forked from lxm_flutter/FlutterUnit
🎨 优化代码
This commit is contained in:
@@ -13,16 +13,15 @@
|
||||
|
||||
- Android下载链接: http://photo.toly1994.com/release/FlutterUnit.apk
|
||||
- Mac下载链接: http://photo.toly1994.com/release$flutter_unit_mac.zip
|
||||
|
||||
- ✨ [Flutter Unit mac版支持 ](https://github.com/toly1994328/FlutterUnit/tree/flutter_unit_mac)
|
||||
|
||||
---
|
||||
|
||||
#### Flutter Unit 周边
|
||||
|
||||
- 🔥 [Flutter Unit 更新记录 ](http://king.toly1994.com/FlutterUnit_update.html)
|
||||
- 🔥 [Flutter实用插件集录 ](https://github.com/toly1994328/FlutterUnit/issues/41)
|
||||
- 🔥 [Flutter要点集录 ](https://github.com/toly1994328/FlutterUnit/labels/point)
|
||||
- 🔥 [Flutter Unit 更新记录 ](http://king.toly1994.com/FlutterUnit_update.html)
|
||||
|
||||
---
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter_unit/views/app/navigation/unit_navigation.dart';
|
||||
import 'package:flutter_unit/views/pages/about/about_me_page.dart';
|
||||
import 'package:flutter_unit/views/pages/about/about_app_page.dart';
|
||||
import 'package:flutter_unit/views/pages/category/category_show.dart';
|
||||
import 'package:flutter_unit/views/pages/category/category_detail.dart';
|
||||
import 'package:flutter_unit/views/pages/category/collect_page.dart';
|
||||
import 'package:flutter_unit/views/pages/search/serach_page.dart';
|
||||
import 'package:flutter_unit/views/pages/setting/code_style_setting.dart';
|
||||
|
||||
@@ -10,9 +10,9 @@ import 'package:flutter_unit/model/widget_model.dart';
|
||||
|
||||
class CollectWidgetListItem extends StatelessWidget {
|
||||
final WidgetModel data;
|
||||
final Function(WidgetModel) onDelectItemClick;
|
||||
final Function(WidgetModel) onDeleteItemClick;
|
||||
|
||||
CollectWidgetListItem({this.data, this.onDelectItemClick});
|
||||
CollectWidgetListItem({this.data, this.onDeleteItemClick});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@@ -21,11 +21,7 @@ class CollectWidgetListItem extends StatelessWidget {
|
||||
Material(
|
||||
color: itemColor.withAlpha(66),
|
||||
shape: TechnoShapeBorder(color: itemColor),
|
||||
child: Container(
|
||||
height: 95,
|
||||
padding:
|
||||
const EdgeInsets.only(top: 10, left: 5, right: 10, bottom: 5),
|
||||
child: Row(
|
||||
child: Row(
|
||||
children: <Widget>[
|
||||
_buildLeading(),
|
||||
Expanded(
|
||||
@@ -46,7 +42,6 @@ class CollectWidgetListItem extends StatelessWidget {
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
Positioned(
|
||||
@@ -54,8 +49,8 @@ class CollectWidgetListItem extends StatelessWidget {
|
||||
right: 5,
|
||||
child: FeedbackWidget(
|
||||
onPressed: () {
|
||||
if (onDelectItemClick != null) {
|
||||
onDelectItemClick(data);
|
||||
if (onDeleteItemClick != null) {
|
||||
onDeleteItemClick(data);
|
||||
}
|
||||
},
|
||||
child: const Icon(
|
||||
@@ -86,10 +81,8 @@ class CollectWidgetListItem extends StatelessWidget {
|
||||
|
||||
Color get itemColor => Color(Cons.tabColors[data.family.index]);
|
||||
|
||||
Widget _buildTitle() {
|
||||
return Row(
|
||||
Widget _buildTitle() => Row(
|
||||
children: <Widget>[
|
||||
// SizedBox(width: 10),
|
||||
Expanded(
|
||||
child: Text(data.name,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
@@ -103,11 +96,9 @@ class CollectWidgetListItem extends StatelessWidget {
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildSummary() {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(left: 5, bottom: 10, top: 5),
|
||||
Widget _buildSummary() => Padding(
|
||||
padding: const EdgeInsets.only(left: 5, bottom: 5, top: 5),
|
||||
child: Container(
|
||||
child: Text(
|
||||
data.nameCN,
|
||||
@@ -120,5 +111,4 @@ class CollectWidgetListItem extends StatelessWidget {
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ import 'package:flutter_unit/views/items/category_list_item.dart';
|
||||
import 'edit_category_panel.dart';
|
||||
|
||||
class CategoryPage extends StatelessWidget {
|
||||
|
||||
final gridDelegate = const SliverGridDelegateWithFixedCrossAxisCount(
|
||||
crossAxisCount: 2,
|
||||
mainAxisSpacing: 10,
|
||||
@@ -24,27 +25,39 @@ class CategoryPage extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocBuilder<CategoryBloc, CategoryState>(builder: (_, state) {
|
||||
return BlocBuilder<CategoryBloc, CategoryState>(builder: (ctx, state) {
|
||||
if (state is CategoryLoadedState) {
|
||||
return GridView.builder(
|
||||
padding: EdgeInsets.all(10),
|
||||
itemCount: state.categories.length,
|
||||
itemBuilder: (_, index) => Container(
|
||||
child: GestureDetector(
|
||||
onTap: () => _toDetailPage(context, state.categories[index]),
|
||||
child: CategoryListItem(
|
||||
data: state.categories[index],
|
||||
onDeleteItemClick: (model) => _deleteCollect(context, model),
|
||||
onEditItemClick: (model) => _editCollect(context, model),
|
||||
)),
|
||||
),
|
||||
gridDelegate: gridDelegate,
|
||||
return CustomScrollView(
|
||||
slivers: <Widget>[
|
||||
SliverOverlapInjector(
|
||||
handle: NestedScrollView.sliverOverlapAbsorberHandleFor(ctx),
|
||||
),
|
||||
_buildContent(context, state)],
|
||||
);
|
||||
}
|
||||
return Container();
|
||||
});
|
||||
}
|
||||
|
||||
_buildContent(BuildContext context, CategoryLoadedState state) {
|
||||
return SliverPadding(
|
||||
padding: EdgeInsets.only(top:10, left: 10, right: 10, bottom: 40),
|
||||
sliver: SliverGrid(
|
||||
delegate: SliverChildBuilderDelegate(
|
||||
(_, index) => Container(
|
||||
child: GestureDetector(
|
||||
onTap: () => _toDetailPage(context, state.categories[index]),
|
||||
child: CategoryListItem(
|
||||
data: state.categories[index],
|
||||
onDeleteItemClick: (model) => _deleteCollect(context, model),
|
||||
onEditItemClick: (model) => _editCollect(context, model),
|
||||
)),
|
||||
),
|
||||
childCount: state.categories.length),
|
||||
gridDelegate: gridDelegate),
|
||||
);
|
||||
}
|
||||
|
||||
_deleteCollect(BuildContext context, CategoryModel model) {
|
||||
showDialog(
|
||||
context: context,
|
||||
@@ -111,4 +124,6 @@ class CategoryPage extends StatelessWidget {
|
||||
.add(EventLoadCategoryWidget(model.id));
|
||||
Navigator.pushNamed(context, Router.category_show, arguments: model);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,34 +1,32 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:flutter_unit/app/router.dart';
|
||||
import 'package:flutter_unit/blocs/bloc_exp.dart';
|
||||
import 'package:flutter_unit/components/permanent/circle_image.dart';
|
||||
import 'package:flutter_unit/model/widget_model.dart';
|
||||
import 'package:flutter_unit/views/items/collect_widget_list_item.dart';
|
||||
|
||||
import 'category_page.dart';
|
||||
import 'default_collect_page.dart';
|
||||
|
||||
class CollectPage extends StatefulWidget {
|
||||
@override
|
||||
_CollectPageState createState() => _CollectPageState();
|
||||
}
|
||||
|
||||
class _CollectPageState extends State<CollectPage> with AutomaticKeepAliveClientMixin{
|
||||
final gridDelegate = const SliverGridDelegateWithFixedCrossAxisCount(
|
||||
crossAxisCount: 2,
|
||||
mainAxisSpacing: 10,
|
||||
crossAxisSpacing: 10,
|
||||
childAspectRatio: 1 / 0.5,
|
||||
);
|
||||
class _CollectPageState extends State<CollectPage>
|
||||
with AutomaticKeepAliveClientMixin {
|
||||
|
||||
final _tabs = ['收藏集录','默认收藏', ];
|
||||
final _tabs = [
|
||||
'收藏集录',
|
||||
'默认收藏',
|
||||
];
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
var _topContext = context;
|
||||
super.build(context);
|
||||
var _topContext = context;
|
||||
return Scaffold(
|
||||
backgroundColor: BlocProvider.of<HomeBloc>(context).state.homeColor.withAlpha(11),
|
||||
backgroundColor:
|
||||
BlocProvider.of<HomeBloc>(context).state.homeColor.withAlpha(11),
|
||||
body: DefaultTabController(
|
||||
length: _tabs.length, // This is the number of tabs.
|
||||
child: NestedScrollView(
|
||||
@@ -38,22 +36,14 @@ class _CollectPageState extends State<CollectPage> with AutomaticKeepAliveClient
|
||||
SliverOverlapAbsorber(
|
||||
handle: NestedScrollView.sliverOverlapAbsorberHandleFor(
|
||||
context),
|
||||
child: _buildAppBar(_topContext, innerBoxIsScrolled)),
|
||||
sliver: _buildAppBar(_topContext, innerBoxIsScrolled)),
|
||||
];
|
||||
},
|
||||
body: Container(
|
||||
padding: EdgeInsets.only(top: 150-30.0-10),
|
||||
child: TabBarView(
|
||||
children: <Widget>[
|
||||
CategoryPage(),
|
||||
BlocBuilder<CollectBloc, CollectState>(
|
||||
builder: (_, state) {
|
||||
return CustomScrollView(
|
||||
slivers: <Widget>[_buildContent(context, state)],
|
||||
);
|
||||
}),
|
||||
],
|
||||
),
|
||||
body: TabBarView(
|
||||
children: <Widget>[
|
||||
CategoryPage(),
|
||||
DefaultCollectPage(),
|
||||
],
|
||||
),
|
||||
),
|
||||
));
|
||||
@@ -71,7 +61,8 @@ class _CollectPageState extends State<CollectPage> with AutomaticKeepAliveClient
|
||||
actions: <Widget>[_buildAddActionBuilder(context)],
|
||||
title: Text(
|
||||
'收藏集 CollectUnit',
|
||||
style: TextStyle(color: Colors.white, //标题
|
||||
style: TextStyle(
|
||||
color: Colors.white, //标题
|
||||
fontSize: 18,
|
||||
shadows: [
|
||||
Shadow(color: Colors.blue, offset: Offset(1, 1), blurRadius: 2)
|
||||
@@ -91,7 +82,7 @@ class _CollectPageState extends State<CollectPage> with AutomaticKeepAliveClient
|
||||
preferredSize: Size.fromHeight(30),
|
||||
child: TabBar(
|
||||
indicatorColor: Colors.transparent,
|
||||
unselectedLabelColor : Colors.white,
|
||||
unselectedLabelColor: Colors.white,
|
||||
labelColor: Colors.black,
|
||||
labelStyle: TextStyle(fontSize: 16, shadows: [
|
||||
Shadow(
|
||||
@@ -99,34 +90,17 @@ class _CollectPageState extends State<CollectPage> with AutomaticKeepAliveClient
|
||||
offset: Offset(1, 1),
|
||||
blurRadius: 10)
|
||||
]),
|
||||
tabs: _tabs.map((String name) => Container(
|
||||
margin: EdgeInsets.only(bottom: 5),
|
||||
alignment:Alignment.center,child: Text(name))).toList(),
|
||||
tabs: _tabs
|
||||
.map((String name) => Container(
|
||||
margin: EdgeInsets.only(bottom: 5),
|
||||
alignment: Alignment.center,
|
||||
child: Text(name)))
|
||||
.toList(),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildContent(BuildContext context, CollectState state) {
|
||||
return SliverPadding(
|
||||
padding: EdgeInsets.only(top:10, left: 10, right: 10, bottom: 40),
|
||||
sliver: SliverGrid(
|
||||
delegate: SliverChildBuilderDelegate(
|
||||
(_, index) => Container(
|
||||
child: GestureDetector(
|
||||
onTap: () =>
|
||||
_toDetailPage(context, state.widgets[index]),
|
||||
child: CollectWidgetListItem(
|
||||
data: state.widgets[index],
|
||||
onDelectItemClick: (model) =>
|
||||
_deleteCollect(context, model),
|
||||
)),
|
||||
),
|
||||
childCount: state.widgets.length),
|
||||
gridDelegate: gridDelegate),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildAddActionBuilder(BuildContext context) => IconButton(
|
||||
icon: Icon(
|
||||
Icons.add,
|
||||
@@ -134,15 +108,6 @@ class _CollectPageState extends State<CollectPage> with AutomaticKeepAliveClient
|
||||
),
|
||||
onPressed: () => Scaffold.of(context).openEndDrawer());
|
||||
|
||||
_deleteCollect(BuildContext context, WidgetModel model) =>
|
||||
BlocProvider.of<CollectBloc>(context)
|
||||
.add(ToggleCollectEvent(id: model.id));
|
||||
|
||||
_toDetailPage(BuildContext context, WidgetModel model) {
|
||||
BlocProvider.of<DetailBloc>(context).add(FetchWidgetDetail(model));
|
||||
Navigator.pushNamed(context, Router.widget_detail, arguments: model);
|
||||
}
|
||||
|
||||
@override
|
||||
// TODO: implement wantKeepAlive
|
||||
bool get wantKeepAlive => true;
|
||||
|
||||
64
lib/views/pages/category/default_collect_page.dart
Normal file
64
lib/views/pages/category/default_collect_page.dart
Normal file
@@ -0,0 +1,64 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:flutter_unit/app/router.dart';
|
||||
import 'package:flutter_unit/blocs/bloc_exp.dart';
|
||||
import 'package:flutter_unit/model/widget_model.dart';
|
||||
import 'package:flutter_unit/views/items/collect_widget_list_item.dart';
|
||||
|
||||
/// create by 张风捷特烈 on 2020/6/16
|
||||
/// contact me by email 1981462002@qq.com
|
||||
/// 说明:
|
||||
|
||||
class DefaultCollectPage extends StatelessWidget {
|
||||
|
||||
final gridDelegate = const SliverGridDelegateWithFixedCrossAxisCount(
|
||||
crossAxisCount: 2,
|
||||
mainAxisSpacing: 10,
|
||||
crossAxisSpacing: 10,
|
||||
childAspectRatio: 1 / 0.5,
|
||||
);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocBuilder<CollectBloc, CollectState>(
|
||||
builder: (ctx, state) {
|
||||
return CustomScrollView(
|
||||
slivers: <Widget>[
|
||||
SliverOverlapInjector(
|
||||
handle: NestedScrollView.sliverOverlapAbsorberHandleFor(ctx),
|
||||
),
|
||||
_buildContent(context, state)],
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
Widget _buildContent(BuildContext context, CollectState state) {
|
||||
return SliverPadding(
|
||||
padding: EdgeInsets.only(top:10, left: 10, right: 10, bottom: 40),
|
||||
sliver: SliverGrid(
|
||||
delegate: SliverChildBuilderDelegate(
|
||||
(_, index) => Container(
|
||||
child: GestureDetector(
|
||||
onTap: () =>
|
||||
_toDetailPage(context, state.widgets[index]),
|
||||
child: CollectWidgetListItem(
|
||||
data: state.widgets[index],
|
||||
onDeleteItemClick: (model) =>
|
||||
_deleteCollect(context, model),
|
||||
)),
|
||||
),
|
||||
childCount: state.widgets.length),
|
||||
gridDelegate: gridDelegate),
|
||||
);
|
||||
}
|
||||
|
||||
_deleteCollect(BuildContext context, WidgetModel model) =>
|
||||
BlocProvider.of<CollectBloc>(context)
|
||||
.add(ToggleCollectEvent(id: model.id));
|
||||
|
||||
_toDetailPage(BuildContext context, WidgetModel model) {
|
||||
BlocProvider.of<DetailBloc>(context).add(FetchWidgetDetail(model));
|
||||
Navigator.pushNamed(context, Router.widget_detail, arguments: model);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,14 +1,6 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:flutter_unit/app/style/unit_color.dart';
|
||||
import 'package:flutter_unit/app/utils/color_utils.dart';
|
||||
import 'package:flutter_unit/blocs/category/category_bloc.dart';
|
||||
import 'package:flutter_unit/blocs/category/category_event.dart';
|
||||
import 'package:flutter_unit/components/permanent/circle.dart';
|
||||
import 'package:flutter_unit/components/project/color_chooser.dart';
|
||||
import 'package:flutter_unit/views/common/unit_drawer_header.dart';
|
||||
import 'package:flutter_unit/components/permanent/input_button.dart';
|
||||
import 'package:flutter_unit/components/permanent/edit_panel.dart';
|
||||
|
||||
import 'edit_category_panel.dart';
|
||||
|
||||
@@ -73,54 +65,3 @@ class _HomeRightDrawerState extends State<HomeRightDrawer> {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
//class EditCategoryPanel extends StatefulWidget {
|
||||
// @override
|
||||
// _EditCategoryPanelState createState() => _EditCategoryPanelState();
|
||||
//}
|
||||
//
|
||||
//class _EditCategoryPanelState extends State<EditCategoryPanel> {
|
||||
// String name;
|
||||
// String color;
|
||||
// String info;
|
||||
//
|
||||
// @override
|
||||
// Widget build(BuildContext context) {
|
||||
// return Column(
|
||||
// children: <Widget>[
|
||||
// Padding(
|
||||
// padding: const EdgeInsets.symmetric(horizontal: 15, vertical: 8),
|
||||
// child: InputButton(
|
||||
// config: InputButtonConfig(hint: '收藏集名称', iconData: Icons.check),
|
||||
// onSubmit: (str) {
|
||||
// name = str;
|
||||
// if(name.isNotEmpty){
|
||||
// BlocProvider.of<CategoryBloc>(context)
|
||||
// .add(EventAddCategory(name: name, info: info, color: color));
|
||||
// }
|
||||
// Navigator.of(context).pop();
|
||||
// },
|
||||
// ),
|
||||
// ),
|
||||
// Padding(
|
||||
// padding: const EdgeInsets.symmetric(horizontal: 15, vertical: 8),
|
||||
// child: EditPanel(
|
||||
// submitClear: false,
|
||||
// hint: '收藏集简介...',
|
||||
// onChange: (v) => info = v,
|
||||
// ),
|
||||
// ),
|
||||
// Container(
|
||||
// alignment: Alignment.center,
|
||||
// padding: const EdgeInsets.symmetric(horizontal: 15, vertical: 15),
|
||||
// child: ColorChooser(
|
||||
// defaultIndex: 0,
|
||||
// colors: UnitColor.collectColorSupport,
|
||||
// onChecked: (v) => color = ColorUtils.colorString(v),
|
||||
// ),
|
||||
// ),
|
||||
// ],
|
||||
// );
|
||||
// }
|
||||
//}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user