forked from lxm_flutter/FlutterUnit
✨ 收藏夹修改完成
This commit is contained in:
Binary file not shown.
@@ -1,8 +1,8 @@
|
||||
import 'package:flutter/material.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/collect/category_show.dart';
|
||||
import 'package:flutter_unit/views/pages/collect/collect_page.dart';
|
||||
import 'package:flutter_unit/views/pages/category/category_show.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';
|
||||
import 'package:flutter_unit/views/pages/setting/font_setting.dart';
|
||||
@@ -10,7 +10,7 @@ import 'package:flutter_unit/views/pages/setting/item_style_setting.dart';
|
||||
import 'package:flutter_unit/views/pages/setting/theme_color_setting.dart';
|
||||
import 'package:flutter_unit/views/pages/unit_todo/attr_unit_page.dart';
|
||||
import 'package:flutter_unit/views/pages/unit_todo/bug_unit_page.dart';
|
||||
import 'package:flutter_unit/views/pages/collect/category_page.dart';
|
||||
import 'package:flutter_unit/views/pages/category/category_page.dart';
|
||||
import 'package:flutter_unit/views/pages/detail/widget_detail_page.dart';
|
||||
import 'package:flutter_unit/views/pages/unit_todo/layout_unit_page.dart';
|
||||
import 'package:flutter_unit/views/pages/unit_todo/paint_unit_page.dart';
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
|
||||
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/repositories/itf/category_repository.dart';
|
||||
import 'package:flutter_unit/storage/po/category_po.dart';
|
||||
|
||||
@@ -9,13 +10,13 @@ import 'category_state.dart';
|
||||
|
||||
/// create by 张风捷特烈 on 2020-04-21
|
||||
/// contact me by email 1981462002@qq.com
|
||||
/// 说明:
|
||||
/// 说明:
|
||||
|
||||
class CategoryBloc extends Bloc<CategoryEvent, CategoryState> {
|
||||
final CategoryRepository repository;
|
||||
|
||||
CategoryBloc({@required this.repository}){
|
||||
print('CategoryBloc') ;
|
||||
CategoryBloc({@required this.repository}) {
|
||||
print('CategoryBloc');
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -23,20 +24,11 @@ class CategoryBloc extends Bloc<CategoryEvent, CategoryState> {
|
||||
|
||||
@override
|
||||
Stream<CategoryState> mapEventToState(CategoryEvent event) async* {
|
||||
print('CategoryBloc');
|
||||
// if (event is ToggleCategoryEvent) {
|
||||
// await repository.toggleCategory(event.id);
|
||||
// var collected= await repository.checkCategoryed(1, event.id);
|
||||
// yield ToggleCategorySuccess(collected);
|
||||
// }
|
||||
// if (event is CheckCategoryEvent) {
|
||||
// var collected = await repository.checkCategoryed(1, event.id);
|
||||
// yield CheckCategorySuccess(collected);
|
||||
// }
|
||||
|
||||
if (event is EventLoadCategory) {
|
||||
final category = await repository.loadCategories();
|
||||
yield category.isEmpty?CategoryEmptyState():CategoryLoadedState(category);
|
||||
yield category.isEmpty
|
||||
? CategoryEmptyState()
|
||||
: CategoryLoadedState(category);
|
||||
}
|
||||
|
||||
if (event is EventDeleteCategory) {
|
||||
@@ -44,14 +36,15 @@ class CategoryBloc extends Bloc<CategoryEvent, CategoryState> {
|
||||
add(EventLoadCategory());
|
||||
}
|
||||
if (event is EventToggleWidget) {
|
||||
await repository.toggleCategory(event.categoryId,event.widgetId);
|
||||
await repository.toggleCategory(event.categoryId, event.widgetId);
|
||||
add(EventLoadCategory());
|
||||
}
|
||||
|
||||
if (event is EventAddCategory) {
|
||||
var categoryPo = CategoryPo(
|
||||
name: event.name,
|
||||
color: event.color ?? '#FF2196F3',
|
||||
color: event.color ??
|
||||
ColorUtils.colorString(UnitColor.collectColorSupport[0]),
|
||||
info: event.info ?? '这里什么都没有...',
|
||||
created: DateTime.now(),
|
||||
updated: DateTime.now());
|
||||
@@ -61,32 +54,29 @@ class CategoryBloc extends Bloc<CategoryEvent, CategoryState> {
|
||||
if (success) {
|
||||
yield AddCategorySuccess();
|
||||
add(EventLoadCategory());
|
||||
}else{
|
||||
} else {
|
||||
yield AddCategoryFailed();
|
||||
}
|
||||
}
|
||||
|
||||
if (event is EventUpdateCategory) {
|
||||
var categoryPo = CategoryPo(
|
||||
id: event.id,
|
||||
name: event.name,
|
||||
priority: event.priority ?? 0,
|
||||
image: event.image ?? '',
|
||||
color: event.color ?? ColorUtils.colorString(UnitColor.collectColorSupport[0]),
|
||||
info: event.info ?? '这里什么都没有...',
|
||||
updated: DateTime.now());
|
||||
|
||||
// if (event is EventAddCategory) {
|
||||
// var collectPo = CategoryPo(
|
||||
// name: event.name,
|
||||
// color: event.color ?? '#FF2196F3',
|
||||
// info: event.info ?? '这里什么都没有...',
|
||||
// created: DateTime.now(),
|
||||
// updated: DateTime.now());
|
||||
//
|
||||
// final success = await repository.addCategory(collectPo);
|
||||
//
|
||||
// if (success) {
|
||||
final success = await repository.updateCategory(categoryPo);
|
||||
|
||||
if (success) {
|
||||
// yield AddCategorySuccess();
|
||||
// final collect = await repository.loadCategorys();
|
||||
// yield LoadCategorySuccess(collects: collect);
|
||||
// }
|
||||
// }
|
||||
// if (event is EventDeleteCategory) {
|
||||
// await repository.deleteCategory(event.id);
|
||||
// final collect = await repository.loadCategorys();
|
||||
// yield LoadCategorySuccess(collects: collect);
|
||||
// }
|
||||
add(EventLoadCategory());
|
||||
} else {
|
||||
// yield AddCategoryFailed();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,3 +44,17 @@ class EventAddCategory extends CategoryEvent{
|
||||
@override
|
||||
List<Object> get props => [name,info,color];
|
||||
}
|
||||
|
||||
class EventUpdateCategory extends CategoryEvent {
|
||||
final int id;
|
||||
final String name;
|
||||
final String info;
|
||||
final String color;
|
||||
final int priority;
|
||||
final String image;
|
||||
|
||||
EventUpdateCategory({@required this.name, this.info, this.color,this.priority,this.image,this.id});
|
||||
|
||||
@override
|
||||
List<Object> get props => [name, info, color,priority,image,id];
|
||||
}
|
||||
|
||||
@@ -10,8 +10,10 @@ class InputButtonConfig {
|
||||
final Widget front; //前面图标
|
||||
final bool submitClear; //是否提交清空
|
||||
|
||||
|
||||
const InputButtonConfig(
|
||||
{this.height = 36,
|
||||
|
||||
this.iconData = Icons.add,
|
||||
this.fontSize = 14,
|
||||
this.submitClear = true,
|
||||
@@ -24,11 +26,13 @@ class InputButton extends StatefulWidget {
|
||||
final ValueChanged<String> onChanged;
|
||||
final VoidCallback onTap;
|
||||
final InputButtonConfig config;
|
||||
final String defaultText;
|
||||
|
||||
InputButton(
|
||||
{Key key,
|
||||
this.onSubmit,
|
||||
this.onChanged,
|
||||
this.defaultText,
|
||||
this.onTap,
|
||||
this.config = const InputButtonConfig()})
|
||||
: super(key: key);
|
||||
@@ -38,24 +42,31 @@ class InputButton extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _InputButtonState extends State<InputButton> {
|
||||
var _text = "";
|
||||
var _height;
|
||||
var _fontSize;
|
||||
var _radius;
|
||||
|
||||
TextEditingController _controller;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_height = widget.config.height;
|
||||
_fontSize = widget.config.fontSize;
|
||||
_radius = Radius.circular(_height / 3.6);
|
||||
_controller = TextEditingController(text: widget.defaultText??'');
|
||||
}
|
||||
|
||||
super.initState();
|
||||
@override
|
||||
void dispose() {
|
||||
_controller.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
var textField = TextField(
|
||||
controller: TextEditingController(text: _text),
|
||||
controller: _controller,
|
||||
maxLines: 1,
|
||||
style: TextStyle(
|
||||
fontSize: _fontSize,
|
||||
@@ -79,8 +90,7 @@ class _InputButtonState extends State<InputButton> {
|
||||
),
|
||||
),
|
||||
onChanged: (str) {
|
||||
_text = str;
|
||||
if (widget.onChanged != null) widget.onChanged(_text);
|
||||
if (widget.onChanged != null) widget.onChanged(str);
|
||||
},
|
||||
onTap: widget.onTap,
|
||||
);
|
||||
@@ -92,10 +102,10 @@ class _InputButtonState extends State<InputButton> {
|
||||
padding: EdgeInsets.zero,
|
||||
onPressed: () {
|
||||
FocusScope.of(context).requestFocus(FocusNode()); //收起键盘
|
||||
if (widget.onSubmit != null) widget.onSubmit(_text);
|
||||
if (widget.onSubmit != null) widget.onSubmit(_controller.text);
|
||||
if (widget.config.submitClear) {
|
||||
setState(() {
|
||||
_text = "";
|
||||
_controller.clear();
|
||||
});
|
||||
}
|
||||
},
|
||||
@@ -13,50 +13,56 @@ import 'package:flutter_unit/storage/po/widget_po.dart';
|
||||
class CategoryDbRepository implements CategoryRepository {
|
||||
final AppStorage storage;
|
||||
|
||||
CategoryDao _collectDao;
|
||||
CategoryDao _categoryDao;
|
||||
|
||||
CategoryDbRepository(this.storage) {
|
||||
_collectDao = CategoryDao(storage);
|
||||
_categoryDao = CategoryDao(storage);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<bool> addCategory(CategoryPo categoryPo) async {
|
||||
var success = await _collectDao.insert(categoryPo);
|
||||
var success = await _categoryDao.insert(categoryPo);
|
||||
return success != -1;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<bool> check(int categoryId, int widgetId) async {
|
||||
return await _collectDao.existWidgetInCollect(categoryId, widgetId);
|
||||
return await _categoryDao.existWidgetInCollect(categoryId, widgetId);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> deleteCategory(int id) async {
|
||||
await _collectDao.deleteCollect(id);
|
||||
await _categoryDao.deleteCollect(id);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<List<CategoryModel>> loadCategories() async {
|
||||
var data = await _collectDao.queryAll();
|
||||
var data = await _categoryDao.queryAll();
|
||||
var collects = data.map((e) => CategoryPo.fromJson(e)).toList();
|
||||
return collects.map(CategoryModel.fromPo).toList();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<List<WidgetModel>> loadCategoryWidgets({int categoryId = 0}) async {
|
||||
var rawData = await _collectDao.loadCollectWidgets(categoryId);
|
||||
var rawData = await _categoryDao.loadCollectWidgets(categoryId);
|
||||
var widgets = rawData.map((e) => WidgetPo.fromJson(e)).toList();
|
||||
return widgets.map(WidgetModel.fromPo).toList();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> toggleCategory(int categoryId, int widgetId) async {
|
||||
return await _collectDao.toggleCollect( categoryId, widgetId);
|
||||
return await _categoryDao.toggleCollect( categoryId, widgetId);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<List<int>> getCategoryByWidget(int widgetId) async {
|
||||
return await _collectDao.categoryWidgetIds(widgetId);
|
||||
return await _categoryDao.categoryWidgetIds(widgetId);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<bool> updateCategory(CategoryPo categoryPo) async{
|
||||
var success = await _categoryDao.update(categoryPo);
|
||||
return success != -1;
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
@@ -18,6 +18,7 @@ abstract class CategoryRepository {
|
||||
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);
|
||||
|
||||
@@ -44,6 +44,27 @@ class CategoryDao {
|
||||
]));
|
||||
}
|
||||
|
||||
Future<int> update(CategoryPo widget) async {
|
||||
//插入方法
|
||||
final db = await _db;
|
||||
String updateSql = //插入数据
|
||||
"UPDATE category SET name=? , color=? ,info=?, priority=?,image=?,updated=? "
|
||||
"WHERE id = ?";
|
||||
|
||||
return await db.transaction((tran) async =>
|
||||
await tran.rawUpdate(updateSql, [
|
||||
widget.name,
|
||||
widget.color,
|
||||
widget.info,
|
||||
widget.priority,
|
||||
widget.image,
|
||||
widget.updated.toIso8601String(),
|
||||
widget.id,
|
||||
]));
|
||||
}
|
||||
|
||||
|
||||
|
||||
Future<int> addWidget(int categoryId,int widgetId,) async {
|
||||
final db = await _db;
|
||||
String addSql = //插入数据
|
||||
|
||||
@@ -66,7 +66,6 @@ class WidgetDao {
|
||||
final db = await storage.db;
|
||||
var data = await db.rawQuery('SELECT collected FROM widget WHERE id = ?', [id]);
|
||||
var collected = data.toList()[0]['collected']==1;
|
||||
print('collected:$collected');
|
||||
return await db.rawQuery(
|
||||
"UPDATE widget SET collected = ? "
|
||||
"WHERE id = ?",
|
||||
|
||||
@@ -11,8 +11,9 @@ import 'package:flutter_unit/model/category_model.dart';
|
||||
class CategoryListItem extends StatelessWidget {
|
||||
final CategoryModel data;
|
||||
final Function(CategoryModel) onDeleteItemClick;
|
||||
final Function(CategoryModel) onEditItemClick;
|
||||
|
||||
CategoryListItem({this.data, this.onDeleteItemClick});
|
||||
CategoryListItem({this.data, this.onDeleteItemClick,this.onEditItemClick});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@@ -57,7 +58,11 @@ class CategoryListItem extends StatelessWidget {
|
||||
right: 5,
|
||||
child:
|
||||
FeedbackWidget(
|
||||
onPressed: () {},
|
||||
onPressed: () {
|
||||
if (onEditItemClick != null) {
|
||||
onEditItemClick(data);
|
||||
}
|
||||
},
|
||||
child: Icon(
|
||||
Icons.edit,
|
||||
size: 20,
|
||||
|
||||
@@ -27,35 +27,42 @@ class CategoryShow extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(title: Text(model.name)),
|
||||
body: BlocBuilder<CategoryWidgetBloc,CategoryWidgetState>(builder: (_, state) {
|
||||
if (state is CategoryWidgetLoadedState) {
|
||||
return _buildWidgetList(state.widgets);
|
||||
}
|
||||
return Container();
|
||||
}),
|
||||
appBar: AppBar(title: Text(model.name)),
|
||||
body: BlocBuilder<CategoryWidgetBloc, CategoryWidgetState>(
|
||||
builder: (_, state) {
|
||||
if (state is CategoryWidgetLoadedState) {
|
||||
return _buildWidgetList(state.widgets);
|
||||
}
|
||||
return Container();
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildWidgetList(List<WidgetModel> widgets) {
|
||||
return ListView.separated(
|
||||
separatorBuilder: (_, index) => Divider(height: 1,),
|
||||
separatorBuilder: (_, index) => Divider(
|
||||
height: 1,
|
||||
),
|
||||
itemBuilder: (context, index) => Dismissible(
|
||||
direction: DismissDirection.endToStart,
|
||||
key: ValueKey(widgets[index].id),
|
||||
background: Container(
|
||||
padding: EdgeInsets.only(right: 20),
|
||||
alignment: Alignment.centerRight,
|
||||
color: Colors.red,
|
||||
child: Icon(CupertinoIcons.delete_solid,color: Colors.white,size: 30,),
|
||||
),
|
||||
onDismissed: (v){
|
||||
BlocProvider.of<CategoryWidgetBloc>(context)
|
||||
.add(EventToggleCategoryWidget(model.id,widgets[index].id));
|
||||
},
|
||||
child: Container(
|
||||
margin: EdgeInsets.symmetric(horizontal: 15, vertical: 8),
|
||||
child: FeedbackWidget(
|
||||
direction: DismissDirection.endToStart,
|
||||
key: ValueKey(widgets[index].id),
|
||||
background: Container(
|
||||
padding: EdgeInsets.only(right: 20),
|
||||
alignment: Alignment.centerRight,
|
||||
color: Colors.red,
|
||||
child: Icon(
|
||||
CupertinoIcons.delete_solid,
|
||||
color: Colors.white,
|
||||
size: 30,
|
||||
),
|
||||
),
|
||||
onDismissed: (v) {
|
||||
BlocProvider.of<CategoryWidgetBloc>(context).add(
|
||||
EventToggleCategoryWidget(model.id, widgets[index].id));
|
||||
},
|
||||
child: Container(
|
||||
margin: EdgeInsets.symmetric(horizontal: 15, vertical: 8),
|
||||
child: FeedbackWidget(
|
||||
duration: Duration(milliseconds: 200),
|
||||
onPressed: () => _toDetailPage(context, widgets[index]),
|
||||
child: SimpleWidgetItem(
|
||||
@@ -79,38 +86,38 @@ class SimpleWidgetItem extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
return Container(
|
||||
color: Colors.transparent,
|
||||
height: 75,
|
||||
child: Row(
|
||||
children: <Widget>[
|
||||
SizedBox(width: 10,),
|
||||
Column(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||
children: <Widget>[
|
||||
_buildLeading(),
|
||||
|
||||
StarScore(
|
||||
star: Star(emptyColor: Colors.white, size: 12, fillColor: data.color),
|
||||
score: data.lever,
|
||||
),
|
||||
],
|
||||
),
|
||||
SizedBox(width: 20,),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||
children: <Widget>[
|
||||
_buildTitle(),
|
||||
_buildSummary()
|
||||
],
|
||||
children: <Widget>[
|
||||
SizedBox(
|
||||
width: 10,
|
||||
),
|
||||
Column(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||
children: <Widget>[
|
||||
_buildLeading(),
|
||||
StarScore(
|
||||
star: Star(
|
||||
emptyColor: Colors.white, size: 12, fillColor: data.color),
|
||||
score: data.lever,
|
||||
),
|
||||
)
|
||||
],
|
||||
],
|
||||
),
|
||||
SizedBox(
|
||||
width: 20,
|
||||
),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||
children: <Widget>[_buildTitle(), _buildSummary()],
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
Widget _buildTitle() {
|
||||
@@ -123,36 +130,36 @@ class SimpleWidgetItem extends StatelessWidget {
|
||||
}
|
||||
|
||||
Widget _buildLeading() => Padding(
|
||||
padding: const EdgeInsets.only(left: 5, right: 5),
|
||||
child: Hero(
|
||||
tag: "hero_widget_image_${data.id}",
|
||||
child: data.image == null
|
||||
? Material(
|
||||
color: Colors.transparent,
|
||||
child: CircleText(
|
||||
text: data.name,
|
||||
size: 50,
|
||||
color: data.color,
|
||||
padding: const EdgeInsets.only(left: 5, right: 5),
|
||||
child: Hero(
|
||||
tag: "hero_widget_image_${data.id}",
|
||||
child: data.image == null
|
||||
? Material(
|
||||
color: Colors.transparent,
|
||||
child: CircleText(
|
||||
text: data.name,
|
||||
size: 50,
|
||||
color: data.color,
|
||||
),
|
||||
)
|
||||
: CircleImage(
|
||||
image: data.image,
|
||||
size: 50,
|
||||
),
|
||||
),
|
||||
)
|
||||
: CircleImage(
|
||||
image: data.image,
|
||||
size: 50,
|
||||
),
|
||||
),
|
||||
);
|
||||
);
|
||||
|
||||
Widget _buildSummary() {
|
||||
return Container(
|
||||
child: Text(
|
||||
data.info,
|
||||
maxLines: 2,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(
|
||||
color: Colors.grey[600],
|
||||
fontSize: 14,
|
||||
shadows: [Shadow(color: Colors.white, offset: Offset(.5, .5))]),
|
||||
),
|
||||
return Container(
|
||||
child: Text(
|
||||
data.info,
|
||||
maxLines: 2,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(
|
||||
color: Colors.grey[600],
|
||||
fontSize: 14,
|
||||
shadows: [Shadow(color: Colors.white, offset: Offset(.5, .5))]),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -29,8 +29,7 @@ class CollectPage extends StatelessWidget {
|
||||
Widget build(BuildContext 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(
|
||||
100
lib/views/pages/category/edit_category_panel.dart
Normal file
100
lib/views/pages/category/edit_category_panel.dart
Normal file
@@ -0,0 +1,100 @@
|
||||
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/edit_panel.dart';
|
||||
import 'package:flutter_unit/components/permanent/input_button.dart';
|
||||
import 'package:flutter_unit/components/project/color_chooser.dart';
|
||||
import 'package:flutter_unit/model/category_model.dart';
|
||||
|
||||
/// create by 张风捷特烈 on 2020-04-23
|
||||
/// contact me by email 1981462002@qq.com
|
||||
/// 说明:
|
||||
|
||||
enum EditType { add, update }
|
||||
|
||||
class EditCategoryPanel extends StatefulWidget {
|
||||
final CategoryModel model;
|
||||
final EditType type;
|
||||
|
||||
EditCategoryPanel({this.model, this.type = EditType.add});
|
||||
|
||||
@override
|
||||
_EditCategoryPanelState createState() => _EditCategoryPanelState();
|
||||
}
|
||||
|
||||
class _EditCategoryPanelState extends State<EditCategoryPanel> {
|
||||
String name;
|
||||
String color;
|
||||
String info;
|
||||
|
||||
int get colorIndex => widget.model == null
|
||||
? 0
|
||||
: UnitColor.collectColorSupport
|
||||
.map((e) => e.value)
|
||||
.toList()
|
||||
.indexOf(widget.model.color.value);
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
info = widget.model?.info;
|
||||
color = widget.model == null
|
||||
? null
|
||||
: ColorUtils.colorString(widget.model.color);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: <Widget>[
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 15, vertical: 8),
|
||||
child: InputButton(
|
||||
defaultText: widget.model?.name,
|
||||
config: InputButtonConfig(hint: '收藏集名称', iconData: Icons.check),
|
||||
onSubmit: (str) {
|
||||
name = str;
|
||||
if (name.isNotEmpty) {
|
||||
if (widget.type == EditType.add) {
|
||||
BlocProvider.of<CategoryBloc>(context).add(
|
||||
EventAddCategory(name: name, info: info, color: color));
|
||||
}
|
||||
if (widget.type == EditType.update) {
|
||||
BlocProvider.of<CategoryBloc>(context).add(
|
||||
EventUpdateCategory(
|
||||
id: widget.model.id,
|
||||
name: name,
|
||||
info: info,
|
||||
color: color));
|
||||
}
|
||||
}
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 15, vertical: 8),
|
||||
child: EditPanel(
|
||||
defaultText: widget.model?.info,
|
||||
submitClear: false,
|
||||
hint: '收藏集简介...',
|
||||
onChange: (v) => info = v,
|
||||
),
|
||||
),
|
||||
Container(
|
||||
alignment: Alignment.center,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 15, vertical: 15),
|
||||
child: ColorChooser(
|
||||
defaultIndex: colorIndex,
|
||||
colors: UnitColor.collectColorSupport,
|
||||
onChecked: (v) => color = ColorUtils.colorString(v),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,18 +1,16 @@
|
||||
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/style/unit_text_style.dart';
|
||||
import 'package:flutter_unit/app/utils/Toast.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/blocs/collect/collect_bloc.dart';
|
||||
import 'package:flutter_unit/blocs/collect/collect_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/views/pages/collect/InputButton.dart';
|
||||
import 'package:flutter_unit/views/pages/collect/edit_panel.dart';
|
||||
import 'package:flutter_unit/components/permanent/input_button.dart';
|
||||
import 'package:flutter_unit/components/permanent/edit_panel.dart';
|
||||
|
||||
import 'edit_category_panel.dart';
|
||||
|
||||
class HomeRightDrawer extends StatefulWidget {
|
||||
final Color color;
|
||||
@@ -41,40 +39,7 @@ class _HomeRightDrawerState extends State<HomeRightDrawer> {
|
||||
child: ListView(padding: EdgeInsets.zero, children: <Widget>[
|
||||
UnitDrawerHeader(color:widget.color),
|
||||
_buildTitle(context),
|
||||
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();
|
||||
// Toast.toast(context, '收藏集功能正在开发中...',
|
||||
// duration: Duration(seconds: 1));
|
||||
},
|
||||
),
|
||||
),
|
||||
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),
|
||||
),
|
||||
),
|
||||
EditCategoryPanel()
|
||||
]),
|
||||
);
|
||||
|
||||
@@ -108,3 +73,54 @@ 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),
|
||||
// ),
|
||||
// ),
|
||||
// ],
|
||||
// );
|
||||
// }
|
||||
//}
|
||||
|
||||
@@ -1,22 +1,16 @@
|
||||
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/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/components/permanent/circle.dart';
|
||||
import 'package:flutter_unit/components/permanent/feedback_widget.dart';
|
||||
import 'package:flutter_unit/components/permanent/panel.dart';
|
||||
import 'package:flutter_unit/components/project/color_chooser.dart';
|
||||
import 'package:flutter_unit/model/category_model.dart';
|
||||
import 'package:flutter_unit/model/widget_model.dart';
|
||||
import 'package:flutter_unit/repositories/itf/category_repository.dart';
|
||||
import 'package:flutter_unit/views/common/unit_drawer_header.dart';
|
||||
import 'package:flutter_unit/views/pages/collect/InputButton.dart';
|
||||
import 'package:flutter_unit/views/pages/collect/edit_panel.dart';
|
||||
|
||||
|
||||
/// create by 张风捷特烈 on 2020-04-22
|
||||
/// contact me by email 1981462002@qq.com
|
||||
|
||||
@@ -6,10 +6,9 @@ import 'package:flutter_unit/blocs/collect/collect_bloc.dart';
|
||||
import 'package:flutter_unit/blocs/collect/collect_event.dart';
|
||||
import 'package:flutter_unit/blocs/widgets/home_bloc.dart';
|
||||
import 'package:flutter_unit/blocs/widgets/home_state.dart';
|
||||
import 'package:flutter_unit/views/pages/collect/collect_page.dart';
|
||||
import 'package:flutter_unit/views/pages/collect/home_right_drawer.dart';
|
||||
import 'package:flutter_unit/views/pages/category/collect_page.dart';
|
||||
import 'package:flutter_unit/views/pages/category/home_right_drawer.dart';
|
||||
import 'package:flutter_unit/views/pages/navigation/unit_bottom_bar.dart';
|
||||
import '../collect/category_page.dart';
|
||||
import '../home/home_page.dart';
|
||||
import '../home/home_drawer.dart';
|
||||
|
||||
|
||||
Reference in New Issue
Block a user