forked from lxm_flutter/FlutterUnit
✨ 优化代码,处理默认视图
This commit is contained in:
@@ -12,6 +12,9 @@ class ColorUnit{
|
||||
static const Color input_hit_text_color = Color(0xff939EA7);
|
||||
static const Color head_text_color = Color(0xff666666);
|
||||
|
||||
// 缺省相关
|
||||
|
||||
static const Color error_color = Colors.red;
|
||||
static const Color warning_color = Colors.orangeAccent;
|
||||
|
||||
}
|
||||
@@ -44,7 +44,7 @@ class WidgetsBloc extends Bloc<WidgetsEvent, WidgetsState> {
|
||||
yield WidgetsLoaded(widgets: widgets, activeFamily: family);
|
||||
} catch (err) {
|
||||
print(err);
|
||||
yield WidgetsLoadFailed();
|
||||
yield WidgetsLoadFailed(err.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,8 +38,11 @@ class WidgetsLoaded extends WidgetsState {
|
||||
}
|
||||
|
||||
class WidgetsLoadFailed extends WidgetsState {
|
||||
const WidgetsLoadFailed();
|
||||
final String error;
|
||||
|
||||
|
||||
const WidgetsLoadFailed(this.error);
|
||||
|
||||
@override
|
||||
List<Object> get props => [];
|
||||
List<Object> get props => [error];
|
||||
}
|
||||
|
||||
39
lib/components/project/default/empty_shower.dart
Normal file
39
lib/components/project/default/empty_shower.dart
Normal file
@@ -0,0 +1,39 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_unit/app/res/color_unit.dart';
|
||||
import 'package:flutter_unit/app/res/style_unit.dart';
|
||||
|
||||
/// create by 张风捷特烈 on 2020/11/17
|
||||
/// contact me by email 1981462002@qq.com
|
||||
/// 说明: 默认 数据为空视图
|
||||
|
||||
class EmptyShower extends StatelessWidget {
|
||||
final String message;
|
||||
|
||||
EmptyShower({Key key, this.message = "数据为空"}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final Color color = Theme.of(context).primaryColor;
|
||||
|
||||
return Center(
|
||||
child: Container(
|
||||
alignment: FractionalOffset.center,
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: <Widget>[
|
||||
Icon(Icons.style, color: color, size: 120.0),
|
||||
Container(
|
||||
padding: EdgeInsets.only(top: 10.0),
|
||||
child: Text(
|
||||
message,
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyleUnit.headTextStyle.copyWith(color: color),
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
40
lib/components/project/default/error_shower.dart
Normal file
40
lib/components/project/default/error_shower.dart
Normal file
@@ -0,0 +1,40 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_unit/app/res/color_unit.dart';
|
||||
import 'package:flutter_unit/app/res/style_unit.dart';
|
||||
|
||||
/// create by 张风捷特烈 on 2020/11/17
|
||||
/// contact me by email 1981462002@qq.com
|
||||
/// 说明: 默认 错误视图
|
||||
|
||||
class ErrorShower extends StatelessWidget {
|
||||
final String error;
|
||||
|
||||
ErrorShower({Key key, this.error = "出现异常"}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Center(
|
||||
child: Wrap(
|
||||
spacing: 10,
|
||||
direction: Axis.vertical,
|
||||
alignment: WrapAlignment.center,
|
||||
crossAxisAlignment: WrapCrossAlignment.center,
|
||||
children: [
|
||||
Container(
|
||||
width: 80,
|
||||
height: 80,
|
||||
child: Icon(
|
||||
Icons.error,
|
||||
size: 80,
|
||||
color: ColorUnit.error_color,
|
||||
)),
|
||||
Text(
|
||||
error,
|
||||
style: TextStyleUnit.headTextStyle.copyWith(color: ColorUnit.error_color),
|
||||
textAlign: TextAlign.center,
|
||||
)
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,7 @@ import 'package:flutter_unit/components/permanent/loading/planet_loading.dart';
|
||||
|
||||
/// create by 张风捷特烈 on 2020/10/24
|
||||
/// contact me by email 1981462002@qq.com
|
||||
/// 说明:
|
||||
/// 说明: 默认 加载视图
|
||||
|
||||
class LoadingShower extends StatelessWidget {
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
|
||||
|
||||
import 'package:flutter_unit/app/enums.dart';
|
||||
import 'package:flutter_unit/storage/dao/widget_dao.dart';
|
||||
import 'package:flutter_unit/model/node_model.dart';
|
||||
@@ -9,12 +7,12 @@ import 'package:flutter_unit/model/widget_model.dart';
|
||||
/// contact me by email 1981462002@qq.com
|
||||
|
||||
abstract class WidgetRepository {
|
||||
|
||||
Future<List<WidgetModel>> loadWidgets(WidgetFamily family);
|
||||
|
||||
Future<List<WidgetModel>> loadWidget(List<int> ids);
|
||||
|
||||
Future<List<WidgetModel>> searchWidgets(SearchArgs args);
|
||||
|
||||
Future<List<NodeModel>> loadNode(WidgetModel widgetModel);
|
||||
|
||||
Future<void> toggleCollect(int id);
|
||||
@@ -22,4 +20,4 @@ abstract class WidgetRepository {
|
||||
Future<List<WidgetModel>> loadCollectWidgets();
|
||||
|
||||
Future<bool> collected(int id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,9 @@ import 'package:flutter_unit/app/router.dart';
|
||||
import 'package:flutter_unit/blocs/bloc_exp.dart';
|
||||
import 'package:flutter_unit/components/permanent/feedback_widget.dart';
|
||||
import 'package:flutter_unit/components/permanent/overlay_tool_wrapper.dart';
|
||||
import 'package:flutter_unit/components/project/loading_shower.dart';
|
||||
import 'package:flutter_unit/components/project/default/empty_shower.dart';
|
||||
import 'package:flutter_unit/components/project/default/error_shower.dart';
|
||||
import 'package:flutter_unit/components/project/default/loading_shower.dart';
|
||||
|
||||
import 'package:flutter_unit/model/widget_model.dart';
|
||||
import 'package:flutter_unit/views/common/empty_page.dart';
|
||||
@@ -84,7 +86,12 @@ class _HomePageState extends State<HomePage>
|
||||
|
||||
if (state is WidgetsLoaded) {
|
||||
List<WidgetModel> items = state.widgets;
|
||||
if (items.isEmpty) return EmptyPage();
|
||||
if (items.isEmpty)
|
||||
return SliverFillRemaining(
|
||||
child: EmptyShower(
|
||||
message: "没数据,哥也没办法\n(≡ _ ≡)/~┴┴",
|
||||
),
|
||||
);
|
||||
return SliverList(
|
||||
delegate: SliverChildBuilderDelegate(
|
||||
(_, int index) => _buildHomeItem(items[index]),
|
||||
@@ -93,11 +100,10 @@ class _HomePageState extends State<HomePage>
|
||||
}
|
||||
|
||||
if (state is WidgetsLoadFailed) {
|
||||
return SliverToBoxAdapter(
|
||||
child: Container(
|
||||
child: Text('加载数据异常'),
|
||||
),
|
||||
);
|
||||
return SliverFillRemaining(
|
||||
child: ErrorShower(
|
||||
error: "数据加载异常:\n${state.error}",
|
||||
));
|
||||
}
|
||||
return Container();
|
||||
}
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class EmptyPage extends StatelessWidget {
|
||||
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Center(child: Container(
|
||||
alignment: FractionalOffset.center,
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: <Widget>[
|
||||
Icon(Icons.event_busy, color: Colors.orangeAccent, size: 120.0),
|
||||
Container(
|
||||
padding: EdgeInsets.only(top: 16.0),
|
||||
child: Text(
|
||||
"没数据,哥也没办法,(≡ _ ≡)/~┴┴",
|
||||
style: TextStyle(
|
||||
fontSize: 20,
|
||||
color: Colors.orangeAccent,
|
||||
),
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
),);
|
||||
}
|
||||
}
|
||||
@@ -13,7 +13,7 @@ import 'package:flutter_unit/views/common/loading_page.dart';
|
||||
import 'package:flutter_unit/views/pages/search/not_search_page.dart';
|
||||
import 'package:flutter_unit/components/permanent/multi_chip_filter.dart';
|
||||
|
||||
import 'empty_page.dart';
|
||||
import '../../../components/project/default/empty_shower.dart';
|
||||
|
||||
|
||||
class SearchPage extends StatefulWidget {
|
||||
@@ -98,7 +98,7 @@ class _SearchPageState extends State<SearchPage> {
|
||||
if (state is SearchStateLoading) return SliverToBoxAdapter(child: LoadingPage());
|
||||
if (state is SearchStateError) return SliverToBoxAdapter(child: ErrorPage());
|
||||
if (state is SearchStateSuccess) return _buildSliverList(state.result);
|
||||
if (state is SearchStateEmpty) return SliverToBoxAdapter(child: EmptyPage());
|
||||
if (state is SearchStateEmpty) return SliverToBoxAdapter(child: EmptyShower(message: "没数据,哥也没办法\n(≡ _ ≡)/~┴┴",));
|
||||
return NotSearchPage();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user