diff --git a/README.md b/README.md index 7c286f9..1708daa 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ ### FlutterUnit apk 下载体验: -![](https://user-gold-cdn.xitu.io/2020/4/21/17199d41c75cfc9d?w=300&h=390&f=png&s=23245) +![](https://user-gold-cdn.xitu.io/2020/4/24/171a9911d22d34a8?w=300&h=390&f=png&s=22765) --- diff --git a/lib/blocs/category/category_bloc.dart b/lib/blocs/category/category_bloc.dart index d1bcc70..bc20dd1 100644 --- a/lib/blocs/category/category_bloc.dart +++ b/lib/blocs/category/category_bloc.dart @@ -15,9 +15,7 @@ import 'category_state.dart'; class CategoryBloc extends Bloc { final CategoryRepository repository; - CategoryBloc({@required this.repository}) { - print('CategoryBloc'); - } + CategoryBloc({@required this.repository}); @override CategoryState get initialState => CategoryEmptyState(); //初始状态 diff --git a/lib/blocs/category/category_event.dart b/lib/blocs/category/category_event.dart index d869a0c..f931dd7 100644 --- a/lib/blocs/category/category_event.dart +++ b/lib/blocs/category/category_event.dart @@ -18,7 +18,6 @@ class EventLoadCategory extends CategoryEvent{ class EventToggleWidget extends CategoryEvent{ final int widgetId; final int categoryId; - EventToggleWidget({this.widgetId, this.categoryId}); @override diff --git a/lib/blocs/category_widget/category_widget_bloc.dart b/lib/blocs/category_widget/category_widget_bloc.dart index cf0cdfb..0757abc 100644 --- a/lib/blocs/category_widget/category_widget_bloc.dart +++ b/lib/blocs/category_widget/category_widget_bloc.dart @@ -15,9 +15,7 @@ class CategoryWidgetBloc extends Bloc { final CategoryBloc categoryBloc; - CategoryWidgetBloc({@required this.categoryBloc}) { - print('CategoryBloc'); - } + CategoryWidgetBloc({@required this.categoryBloc}); CategoryRepository get repository => categoryBloc.repository; diff --git a/lib/blocs/category_widget/category_widget_event.dart b/lib/blocs/category_widget/category_widget_event.dart index 6313aae..9233ef8 100644 --- a/lib/blocs/category_widget/category_widget_event.dart +++ b/lib/blocs/category_widget/category_widget_event.dart @@ -10,11 +10,6 @@ abstract class CategoryWidgetEvent extends Equatable{ List get props => []; } -//class EventLoadCategory extends CategoryWidgetEvent{ -// @override -// List get props => []; -//} - class EventLoadCategoryWidget extends CategoryWidgetEvent{ final int categoryId; @@ -33,23 +28,3 @@ class EventToggleCategoryWidget extends CategoryWidgetEvent{ @override List get props => [categoryId,widgetId]; } - -//class EventDeleteCategory extends CategoryWidgetEvent{ -// final int id; -// -// EventDeleteCategory({@required this.id}); -// -// @override -// List get props => [id]; -//} -// -//class EventAddCategory extends CategoryWidgetEvent{ -// final String name; -// final String info; -// final String color; -// -// EventAddCategory({@required this.name, this.info, this.color}); -// -// @override -// List get props => [name,info,color]; -//} diff --git a/lib/blocs/collect/collect_bloc.dart b/lib/blocs/collect/collect_bloc.dart index 4ca2394..0a32535 100644 --- a/lib/blocs/collect/collect_bloc.dart +++ b/lib/blocs/collect/collect_bloc.dart @@ -11,8 +11,6 @@ import 'collect_state.dart'; /// contact me by email 1981462002@qq.com /// 说明: - - class CollectBloc extends Bloc { final WidgetRepository repository; diff --git a/lib/components/permanent/edit_panel.dart b/lib/components/permanent/edit_panel.dart new file mode 100644 index 0000000..7a554d8 --- /dev/null +++ b/lib/components/permanent/edit_panel.dart @@ -0,0 +1,109 @@ +import 'package:flutter/material.dart'; + +typedef ChangeCallback = void Function(String str); + +///输入面板 +class EditPanel extends StatefulWidget { + EditPanel( + {Key key, + this.backgroundColor = Colors.white, + this.color = Colors.lightBlue, + this.minLines = 4, + this.maxLines = 15, + this.fontSize = 14, + this.submitClear = true, + this.defaultText = "", + this.onChange, + this.hint = "写点什么..."}) + : super(key: key); + + final Color color; //字颜色 + final Color backgroundColor; //背景色颜色 + final int minLines; //最小行数 + final int maxLines; //最大行数 + final double fontSize; //字号 + final String hint; //提示字 + final bool submitClear; //提交是否清空文字 + final ChangeCallback onChange; //提交监听 + final String defaultText; //提交监听 + + @override + _EditPanelState createState() => _EditPanelState(); +} + +class _EditPanelState extends State { + var _radius; //边角半径 + + TextEditingController _controller; + + @override + void initState() { + _radius = Radius.circular(widget.fontSize * 0.618); + _controller = TextEditingController(text: widget.defaultText??''); + super.initState(); + } + + @override + void dispose() { + _controller.dispose(); + super.dispose(); + } + + @override + Widget build(BuildContext context) { + var panel = TextField( + controller: _controller, + //输入控制器 + keyboardType: TextInputType.text, + //键盘类型 + textAlign: TextAlign.start, + //文字居左 + cursorColor: Colors.black, + //游标颜色 + minLines: widget.minLines, + //最小行数 + maxLines: widget.maxLines, + //最大行数 + style: TextStyle( + //文字样式 + fontSize: widget.fontSize, + color: widget.color, + backgroundColor: Colors.white), + decoration: InputDecoration( + //装饰线 + filled: true, + //是否填充 + fillColor: widget.backgroundColor, + //填充色 + hintText: widget.hint, + //提示文字 + hintStyle: TextStyle(color: Colors.black26, fontSize: widget.fontSize), + //提示文字样式 + focusedBorder: UnderlineInputBorder( + //聚焦时边线 + borderSide: BorderSide(color: widget.backgroundColor), + borderRadius: BorderRadius.all(_radius), + ), + enabledBorder: UnderlineInputBorder( + //非聚焦时边线 + borderSide: BorderSide(color: widget.backgroundColor), + borderRadius: BorderRadius.all(_radius), + ), + ), + onChanged: (str) { + //文字变化监听 + if (widget.onChange != null) widget.onChange(str); + }, + onSubmitted: (str) { + //提交监听 + FocusScope.of(context).requestFocus(FocusNode()); //收起键盘 + if (widget.submitClear) { + setState(() { + _controller.clear(); + }); + } + }, + ); + return panel; + } +} diff --git a/lib/repositories/itf/category_repository.dart b/lib/repositories/itf/category_repository.dart index 72dd8f4..fb30e56 100644 --- a/lib/repositories/itf/category_repository.dart +++ b/lib/repositories/itf/category_repository.dart @@ -4,25 +4,31 @@ import 'package:flutter_unit/storage/po/category_po.dart'; /// create by 张风捷特烈 on 2020-04-21 /// contact me by email 1981462002@qq.com -/// 说明: +/// 说明: 负责数据的存储和操作接口 abstract class CategoryRepository { - + //切换一个组件在收藏夹中的状态 Future toggleCategory(int categoryId, int widgetId); + // 检查一个组件是否在收藏夹内 Future check(int categoryId,int widgetId); + // 获取一个收藏夹中的所有组件 Future> loadCategoryWidgets({int categoryId = 0}); - + // 获取所有收藏集 Future> loadCategories(); + //添加收藏集 Future addCategory(CategoryPo categoryPo); + + //更新收藏集 Future updateCategory(CategoryPo categoryPo); + //删除收藏集 Future deleteCategory(int id); + + //查看某个组件在哪些收藏集中 Future> getCategoryByWidget(int widgetId); - - } \ No newline at end of file diff --git a/lib/repositories/itf/widget_repository.dart b/lib/repositories/itf/widget_repository.dart index a97a82b..f93fb05 100644 --- a/lib/repositories/itf/widget_repository.dart +++ b/lib/repositories/itf/widget_repository.dart @@ -14,16 +14,12 @@ abstract class WidgetRepository { Future> loadWidget(List ids); - Future> searchWidgets(SearchArgs args); Future> loadNode(WidgetModel widgetModel); Future toggleCollect(int id); Future> loadCollectWidgets(); + Future collected(int id); - - - - } \ No newline at end of file diff --git a/lib/views/pages/category/category_page.dart b/lib/views/pages/category/category_page.dart new file mode 100644 index 0000000..03c8b60 --- /dev/null +++ b/lib/views/pages/category/category_page.dart @@ -0,0 +1,116 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:flutter_unit/app/router.dart'; +import 'package:flutter_unit/blocs/category/category_bloc.dart'; +import 'package:flutter_unit/blocs/category/category_event.dart'; +import 'package:flutter_unit/blocs/category/category_state.dart'; +import 'package:flutter_unit/blocs/category_widget/category_widget_bloc.dart'; +import 'package:flutter_unit/blocs/category_widget/category_widget_event.dart'; +import 'package:flutter_unit/blocs/widgets/home_bloc.dart'; +import 'package:flutter_unit/components/permanent/circle.dart'; + +import 'package:flutter_unit/model/category_model.dart'; +import 'package:flutter_unit/views/dialogs/delete_category_dialog.dart'; +import 'package:flutter_unit/views/items/category_list_item.dart'; +import 'package:flutter_unit/views/pages/category/home_right_drawer.dart'; + +import 'edit_category_panel.dart'; + +class CategoryPage extends StatelessWidget { + final gridDelegate = const SliverGridDelegateWithFixedCrossAxisCount( + crossAxisCount: 2, + mainAxisSpacing: 10, + crossAxisSpacing: 10, + childAspectRatio: 0.8, + ); + + @override + Widget build(BuildContext context) { + return BlocBuilder(builder: (_, 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 Container(); + }); + } + + _deleteCollect(BuildContext context, CategoryModel model) { + showDialog( + context: context, + builder: (ctx) => Dialog( + elevation: 5, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.all(Radius.circular(10))), + child: Container( + width: 50, + child: DeleteCategoryDialog( + title: '删除收藏集', + content: ' 删除【${model.name}】收藏集,你将会失去其中的所有收藏组件,是否确定继续执行?', + onSubmit: () { + BlocProvider.of(context) + .add(EventDeleteCategory(id: model.id)); + Navigator.of(context).pop(); + }, + ), + ), + )); + } + + _editCollect(BuildContext context, CategoryModel model) { + showDialog( + context: context, + builder: (ctx) => Dialog( + backgroundColor:Color(0xFFF2F2F2), + elevation: 5, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.all(Radius.circular(10))), + child: Column( + mainAxisSize: MainAxisSize.min, + children: [ + SizedBox( + height: 5, + ), + Row( + children: [ + Padding( + padding: const EdgeInsets.only(left: 20, right: 10), + child: Circle( + color: Theme.of(context).primaryColor, + ), + ), + Text( + '修改收藏集', + style: TextStyle(fontSize: 20), + ), + Spacer(), + CloseButton() + ], + ), + Padding( + padding: const EdgeInsets.all(8.0), + child: EditCategoryPanel(model: model,type: EditType.update,), + ), + ], + ), + )); + } + + _toDetailPage(BuildContext context, CategoryModel model) { + BlocProvider.of(context) + .add(EventLoadCategoryWidget(model.id)); + Navigator.pushNamed(context, Router.category_show, arguments: model); + } +} diff --git a/lib/views/pages/collect/category_page.dart b/lib/views/pages/collect/category_page.dart deleted file mode 100644 index 3429ea6..0000000 --- a/lib/views/pages/collect/category_page.dart +++ /dev/null @@ -1,77 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; -import 'package:flutter_unit/app/router.dart'; -import 'package:flutter_unit/blocs/category/category_bloc.dart'; -import 'package:flutter_unit/blocs/category/category_event.dart'; -import 'package:flutter_unit/blocs/category/category_state.dart'; -import 'package:flutter_unit/blocs/category_widget/category_widget_bloc.dart'; -import 'package:flutter_unit/blocs/category_widget/category_widget_event.dart'; -import 'package:flutter_unit/blocs/collect/collect_bloc.dart'; -import 'package:flutter_unit/blocs/collect/collect_event.dart'; -import 'package:flutter_unit/blocs/detail/detail_bloc.dart'; -import 'package:flutter_unit/blocs/detail/detail_event.dart'; -import 'package:flutter_unit/blocs/widgets/home_bloc.dart'; -import 'package:flutter_unit/model/category_model.dart'; -import 'package:flutter_unit/model/widget_model.dart'; -import 'package:flutter_unit/views/dialogs/delete_category_dialog.dart'; -import 'package:flutter_unit/views/items/category_list_item.dart'; - -class CategoryPage extends StatelessWidget { - final gridDelegate = const SliverGridDelegateWithFixedCrossAxisCount( - crossAxisCount: 2, - mainAxisSpacing: 10, - crossAxisSpacing: 10, - childAspectRatio: 0.8, - ); - - @override - Widget build(BuildContext context) { - return BlocBuilder(builder: (_, 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), - )), - ), - gridDelegate: gridDelegate, - ); - } - return Container(); - }); - } - - _deleteCollect(BuildContext context, CategoryModel model) { - showDialog( - context: context, - builder: (ctx) => Dialog( - backgroundColor: Colors.white, - elevation: 5, - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.all(Radius.circular(10))), - child: Container( - width: 50, - child: DeleteCategoryDialog( - title: '删除收藏集', - content: ' 删除【${model.name}】收藏集,你将会失去其中的所有收藏组件,是否确定继续执行?', - onSubmit: () { - BlocProvider.of(context) - .add(EventDeleteCategory(id: model.id)); - Navigator.of(context).pop(); - }, - ), - ), - )); - } - - _toDetailPage(BuildContext context, CategoryModel model) { - BlocProvider.of(context).add(EventLoadCategoryWidget(model.id)); - Navigator.pushNamed(context, Router.category_show, arguments: model); - } -} diff --git a/lib/views/pages/collect/edit_panel.dart b/lib/views/pages/collect/edit_panel.dart deleted file mode 100644 index ba2f1f5..0000000 --- a/lib/views/pages/collect/edit_panel.dart +++ /dev/null @@ -1,85 +0,0 @@ -import 'package:flutter/material.dart'; - -typedef ChangeCallback = void Function(String str); -///输入面板 -class EditPanel extends StatefulWidget { - EditPanel( - {Key key, - this.backgroundColor = Colors.white, - this.color = Colors.lightBlue, - this.minLines = 4, - this.maxLines = 15, - this.fontSize = 14, - this.submitClear = true, - this.value="", - this.onChange, - this.hint = "写点什么..."}) - : super(key: key); - - final Color color;//字颜色 - final Color backgroundColor;//背景色颜色 - final int minLines;//最小行数 - final int maxLines;//最大行数 - final double fontSize;//字号 - final String hint;//提示字 - final bool submitClear;//提交是否清空文字 - final ChangeCallback onChange;//提交监听 - final String value;//提交监听 - - @override - _EditPanelState createState() => _EditPanelState(); -} - -class _EditPanelState extends State { - var _text; - var _radius;//边角半径 - - - - @override - void initState() { - _radius = Radius.circular(widget.fontSize*0.618); - _text = widget.value; - super.initState(); - } - @override - Widget build(BuildContext context) { - var panel = TextField( - controller: TextEditingController(text: _text),//输入控制器 - keyboardType: TextInputType.text,//键盘类型 - textAlign: TextAlign.start,//文字居左 - cursorColor: Colors.black,//游标颜色 - minLines: widget.minLines,//最小行数 - maxLines: widget.maxLines,//最大行数 - style: TextStyle(//文字样式 - fontSize: widget.fontSize, color: widget.color, backgroundColor: Colors.white), - decoration: InputDecoration(//装饰线 - filled: true,//是否填充 - fillColor: widget.backgroundColor,//填充色 - hintText: widget.hint,//提示文字 - hintStyle: TextStyle(color:Colors.black26,fontSize: widget.fontSize),//提示文字样式 - focusedBorder: UnderlineInputBorder(//聚焦时边线 - borderSide: BorderSide(color: widget.backgroundColor), - borderRadius: BorderRadius.all(_radius), - ), - enabledBorder: UnderlineInputBorder(//非聚焦时边线 - borderSide: BorderSide(color: widget.backgroundColor), - borderRadius: BorderRadius.all(_radius), - ), - ), - onChanged: (str) {//文字变化监听 - if (widget.onChange != null) widget.onChange(str); - _text = str; - }, - onSubmitted: (str) {//提交监听 - FocusScope.of(context).requestFocus(FocusNode()); //收起键盘 - if(widget.submitClear){ - setState(() { - _text = ""; - }); - } - }, - ); - return panel; - } -}