forked from lxm_flutter/FlutterUnit
📝 修改文档
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
### FlutterUnit apk 下载体验:
|
||||
|
||||
|
||||

|
||||

|
||||
|
||||
---
|
||||
|
||||
|
||||
@@ -15,9 +15,7 @@ import 'category_state.dart';
|
||||
class CategoryBloc extends Bloc<CategoryEvent, CategoryState> {
|
||||
final CategoryRepository repository;
|
||||
|
||||
CategoryBloc({@required this.repository}) {
|
||||
print('CategoryBloc');
|
||||
}
|
||||
CategoryBloc({@required this.repository});
|
||||
|
||||
@override
|
||||
CategoryState get initialState => CategoryEmptyState(); //初始状态
|
||||
|
||||
@@ -18,7 +18,6 @@ class EventLoadCategory extends CategoryEvent{
|
||||
class EventToggleWidget extends CategoryEvent{
|
||||
final int widgetId;
|
||||
final int categoryId;
|
||||
|
||||
EventToggleWidget({this.widgetId, this.categoryId});
|
||||
|
||||
@override
|
||||
|
||||
@@ -15,9 +15,7 @@ class CategoryWidgetBloc
|
||||
extends Bloc<CategoryWidgetEvent, CategoryWidgetState> {
|
||||
final CategoryBloc categoryBloc;
|
||||
|
||||
CategoryWidgetBloc({@required this.categoryBloc}) {
|
||||
print('CategoryBloc');
|
||||
}
|
||||
CategoryWidgetBloc({@required this.categoryBloc});
|
||||
|
||||
CategoryRepository get repository => categoryBloc.repository;
|
||||
|
||||
|
||||
@@ -10,11 +10,6 @@ abstract class CategoryWidgetEvent extends Equatable{
|
||||
List<Object> get props => [];
|
||||
}
|
||||
|
||||
//class EventLoadCategory extends CategoryWidgetEvent{
|
||||
// @override
|
||||
// List<Object> get props => [];
|
||||
//}
|
||||
|
||||
class EventLoadCategoryWidget extends CategoryWidgetEvent{
|
||||
final int categoryId;
|
||||
|
||||
@@ -33,23 +28,3 @@ class EventToggleCategoryWidget extends CategoryWidgetEvent{
|
||||
@override
|
||||
List<Object> get props => [categoryId,widgetId];
|
||||
}
|
||||
|
||||
//class EventDeleteCategory extends CategoryWidgetEvent{
|
||||
// final int id;
|
||||
//
|
||||
// EventDeleteCategory({@required this.id});
|
||||
//
|
||||
// @override
|
||||
// List<Object> 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<Object> get props => [name,info,color];
|
||||
//}
|
||||
|
||||
@@ -11,8 +11,6 @@ import 'collect_state.dart';
|
||||
/// contact me by email 1981462002@qq.com
|
||||
/// 说明:
|
||||
|
||||
|
||||
|
||||
class CollectBloc extends Bloc<CollectEvent, CollectState> {
|
||||
final WidgetRepository repository;
|
||||
|
||||
|
||||
109
lib/components/permanent/edit_panel.dart
Normal file
109
lib/components/permanent/edit_panel.dart
Normal file
@@ -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<EditPanel> {
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -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<void> toggleCategory(int categoryId, int widgetId);
|
||||
|
||||
// 检查一个组件是否在收藏夹内
|
||||
Future<bool> check(int categoryId,int widgetId);
|
||||
|
||||
// 获取一个收藏夹中的所有组件
|
||||
Future<List<WidgetModel>> loadCategoryWidgets({int categoryId = 0});
|
||||
|
||||
|
||||
// 获取所有收藏集
|
||||
Future<List<CategoryModel>> loadCategories();
|
||||
|
||||
//添加收藏集
|
||||
Future<bool> addCategory(CategoryPo categoryPo);
|
||||
|
||||
//更新收藏集
|
||||
Future<bool> updateCategory(CategoryPo categoryPo);
|
||||
|
||||
//删除收藏集
|
||||
Future<void> deleteCategory(int id);
|
||||
|
||||
//查看某个组件在哪些收藏集中
|
||||
Future<List<int>> getCategoryByWidget(int widgetId);
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -14,16 +14,12 @@ abstract class WidgetRepository {
|
||||
|
||||
Future<List<WidgetModel>> loadWidget(List<int> ids);
|
||||
|
||||
|
||||
Future<List<WidgetModel>> searchWidgets(SearchArgs args);
|
||||
Future<List<NodeModel>> loadNode(WidgetModel widgetModel);
|
||||
|
||||
Future<void> toggleCollect(int id);
|
||||
|
||||
Future<List<WidgetModel>> loadCollectWidgets();
|
||||
|
||||
Future<bool> collected(int id);
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
116
lib/views/pages/category/category_page.dart
Normal file
116
lib/views/pages/category/category_page.dart
Normal file
@@ -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<CategoryBloc, CategoryState>(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<CategoryBloc>(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: <Widget>[
|
||||
SizedBox(
|
||||
height: 5,
|
||||
),
|
||||
Row(
|
||||
children: <Widget>[
|
||||
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<CategoryWidgetBloc>(context)
|
||||
.add(EventLoadCategoryWidget(model.id));
|
||||
Navigator.pushNamed(context, Router.category_show, arguments: model);
|
||||
}
|
||||
}
|
||||
@@ -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<CategoryBloc, CategoryState>(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<CategoryBloc>(context)
|
||||
.add(EventDeleteCategory(id: model.id));
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
),
|
||||
),
|
||||
));
|
||||
}
|
||||
|
||||
_toDetailPage(BuildContext context, CategoryModel model) {
|
||||
BlocProvider.of<CategoryWidgetBloc>(context).add(EventLoadCategoryWidget(model.id));
|
||||
Navigator.pushNamed(context, Router.category_show, arguments: model);
|
||||
}
|
||||
}
|
||||
@@ -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<EditPanel> {
|
||||
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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user