diff --git a/lib/core/models/ProductDao.dart b/lib/core/models/ProductDao.dart index 0cb6bae..21551cd 100644 --- a/lib/core/models/ProductDao.dart +++ b/lib/core/models/ProductDao.dart @@ -1,9 +1,12 @@ +import 'package:aman_kassa_flutter/core/entity/Goods.dart'; + class ProductDao { final String name; final num price; num count; + final Good good; - ProductDao( {this.name, this.price, this.count}); + ProductDao( {this.name, this.price, this.count, this.good}); } \ No newline at end of file diff --git a/lib/redux/actions/main_actions.dart b/lib/redux/actions/main_actions.dart index d677f2f..f2dfbbb 100644 --- a/lib/redux/actions/main_actions.dart +++ b/lib/redux/actions/main_actions.dart @@ -4,6 +4,7 @@ import 'package:aman_kassa_flutter/core/entity/Category.dart'; import 'package:aman_kassa_flutter/core/entity/Goods.dart'; import 'package:aman_kassa_flutter/core/locator.dart'; import 'package:aman_kassa_flutter/core/models/DictDao.dart'; +import 'package:aman_kassa_flutter/core/models/ProductDao.dart'; import 'package:aman_kassa_flutter/core/services/ApiService.dart'; import 'package:aman_kassa_flutter/core/services/DataService.dart'; import 'package:aman_kassa_flutter/core/services/navigator_service.dart'; @@ -33,7 +34,33 @@ Future backBottomElement(Store store) async { store.dispatch(SetMainStateAction(MainState(prevCategories: prevCategories))); store.dispatch(selectBottomElement(last.id)); } +} + +ThunkAction addProductToKassaItems(Good good) { + return (Store store) async { + List items = store.state.mainState.kassaItems; + items.add(new ProductDao(name: good.name, good: good, count: 1, price: good.price)); + store.dispatch(SetMainStateAction(MainState(kassaItems: items))); + }; +} +ThunkAction removeProductFromKassaItems(int index) { + return (Store store) async { + List items = List.from(store.state.mainState.kassaItems); + items.removeAt(index); + store.dispatch(SetMainStateAction(MainState(kassaItems: items))); + }; +} +ThunkAction counterProductFromKassaItems(int index, int counter) { + return (Store store) async { + List items = store.state.mainState.kassaItems; + if(items.elementAt(index).count == 1 && counter < 0) {//if count to zero need delete element + store.dispatch(removeProductFromKassaItems(index)); + } else { + items.elementAt(index).count+=counter; + store.dispatch(SetMainStateAction(MainState(kassaItems: items))); + } + }; } ThunkAction selectBottomElement(int parentId) { diff --git a/lib/redux/reducers/main_reducer.dart b/lib/redux/reducers/main_reducer.dart index b9171f9..f782b51 100644 --- a/lib/redux/reducers/main_reducer.dart +++ b/lib/redux/reducers/main_reducer.dart @@ -7,5 +7,6 @@ mainReducer(MainState prevState, SetMainStateAction action) { bottomSheetElements: payload.bottomSheetElements, bottomSheetLoading: payload.bottomSheetLoading, prevCategories: payload.prevCategories, + kassaItems: payload.kassaItems, ); } diff --git a/lib/redux/state/main_state.dart b/lib/redux/state/main_state.dart index 88bf17c..b1a8e04 100644 --- a/lib/redux/state/main_state.dart +++ b/lib/redux/state/main_state.dart @@ -1,5 +1,5 @@ import 'package:aman_kassa_flutter/core/models/DictDao.dart'; -import 'package:aman_kassa_flutter/core/models/user.dart'; +import 'package:aman_kassa_flutter/core/models/ProductDao.dart'; import 'package:meta/meta.dart'; @immutable @@ -8,23 +8,32 @@ class MainState { final bool bottomSheetLoading; final List prevCategories; - MainState({this.bottomSheetElements, this.bottomSheetLoading, this.prevCategories}); + final List kassaItems; + + MainState( + {this.bottomSheetElements, + this.bottomSheetLoading, + this.prevCategories, + this.kassaItems}); factory MainState.initial() => MainState( - bottomSheetElements: [], - bottomSheetLoading: false, - prevCategories: [], - ); + bottomSheetElements: [], + bottomSheetLoading: false, + prevCategories: [], + kassaItems: [], + ); MainState copyWith({ @required bottomSheetElements, @required bottomSheetLoading, @required prevCategories, + @required kassaItems, }) { return MainState( - bottomSheetElements: bottomSheetElements ?? this.bottomSheetElements, - bottomSheetLoading: bottomSheetLoading ?? this.bottomSheetLoading, + bottomSheetElements: bottomSheetElements ?? this.bottomSheetElements, + bottomSheetLoading: bottomSheetLoading ?? this.bottomSheetLoading, prevCategories: prevCategories ?? this.prevCategories, + kassaItems: kassaItems ?? this.kassaItems, ); } } diff --git a/lib/views/home/tabs/KassaTab.dart b/lib/views/home/tabs/KassaTab.dart index cb2dfa5..2093172 100644 --- a/lib/views/home/tabs/KassaTab.dart +++ b/lib/views/home/tabs/KassaTab.dart @@ -1,6 +1,7 @@ import 'package:aman_kassa_flutter/core/models/ProductDao.dart'; import 'package:aman_kassa_flutter/redux/actions/main_actions.dart'; +import 'package:aman_kassa_flutter/redux/state/main_state.dart'; import 'package:aman_kassa_flutter/redux/store.dart'; import 'package:aman_kassa_flutter/shared/app_colors.dart'; import 'package:aman_kassa_flutter/shared/shared_styles.dart'; @@ -8,23 +9,7 @@ import 'package:aman_kassa_flutter/views/home/tabs/kassaView/CatalogBottomSheet. import 'package:aman_kassa_flutter/views/home/tabs/kassaView/ProductAddBottomSheet.dart'; import 'package:aman_kassa_flutter/widgets/components/ProductListItem.dart'; import 'package:flutter/material.dart'; - - -List litems = [ - "1", - "2", - "3", - "4", - "1", - "2", - "3", - "4", - "1", - "2", - "3", - "4", - "1" -]; +import 'package:flutter_redux/flutter_redux.dart'; class KassaTab extends StatelessWidget { @@ -32,9 +17,10 @@ class KassaTab extends StatelessWidget { KassaTab(this.index); - Widget buildItem(BuildContext ctxt, int index) { + Widget buildItem(BuildContext ctxt, int index, ProductDao productDao) { return ProductListItem( - item: new ProductDao(name: 'Наименование', count: 123, price: 2332.02), + item: new ProductDao(name: productDao.name, count: productDao.count, price: productDao.price), + index: index, ); } @@ -78,10 +64,15 @@ class KassaTab extends StatelessWidget { ), Expanded( child: Container( - child: ListView.builder( - itemCount: litems.length, - itemBuilder: (BuildContext ctxt, int index) => - buildItem(ctxt, index)), + child: StoreConnector( + converter: (store) => store.state.mainState, + builder: (context, vm) { + return ListView.builder( + itemCount: vm.kassaItems.length, + itemBuilder: (BuildContext ctxt, int index) => + buildItem(ctxt, index, vm.kassaItems[index])); + } + ), ), ), Row( @@ -133,7 +124,7 @@ class KassaTab extends StatelessWidget { minChildSize: 0.5, builder: (BuildContext context, ScrollController scrollController) { if( action == 'add') { - return ProductAddBottomSheet(); + return ProductAddBottomSheet(scrollController: scrollController,); } else { return CatalogBottomSheet(scrollController: scrollController,); } diff --git a/lib/views/home/tabs/kassaView/CatalogBottomSheet.dart b/lib/views/home/tabs/kassaView/CatalogBottomSheet.dart index 34f8e90..11432bf 100644 --- a/lib/views/home/tabs/kassaView/CatalogBottomSheet.dart +++ b/lib/views/home/tabs/kassaView/CatalogBottomSheet.dart @@ -36,7 +36,7 @@ class CatalogBottomSheet extends StatelessWidget { style: TextStyle(color: Colors.black45), ), iconTheme: IconThemeData(color: Colors.black), - backgroundColor: whiteColor, + backgroundColor: fillColor, elevation: 3, leading: IconButton( icon: Icon(vm.prevCategories.length > 0 @@ -74,9 +74,12 @@ class CatalogBottomSheet extends StatelessWidget { size: 40, ), title: Text(name), - onTap: () { + onTap: () async { if (el is Category) { Redux.store.dispatch(selectBottomElement(el.id)); + } else if (el is Good) { + await Redux.store.dispatch(addProductToKassaItems(el)); + Navigator.pop(context); } }, trailing: diff --git a/lib/views/home/tabs/kassaView/ProductAddBottomSheet.dart b/lib/views/home/tabs/kassaView/ProductAddBottomSheet.dart index c8e1591..654304c 100644 --- a/lib/views/home/tabs/kassaView/ProductAddBottomSheet.dart +++ b/lib/views/home/tabs/kassaView/ProductAddBottomSheet.dart @@ -1,14 +1,95 @@ import 'package:aman_kassa_flutter/shared/app_colors.dart'; +import 'package:aman_kassa_flutter/shared/ui_helpers.dart'; import 'package:flutter/material.dart'; class ProductAddBottomSheet extends StatelessWidget { + final ScrollController scrollController; + + ProductAddBottomSheet({this.scrollController}); @override Widget build(BuildContext context) { return Container( - decoration: BoxDecoration( - color: whiteColor + decoration: BoxDecoration(color: whiteColor), + child: Scaffold( + appBar: AppBar( + iconTheme: IconThemeData(color: Colors.black), + backgroundColor: fillColor, + elevation: 3, + title: Text('Добавить товар/услугу', style: TextStyle(color: Colors.black87),), + ), + body: Padding( + padding: const EdgeInsets.symmetric(vertical: 15, horizontal: 10), + child: ListView( + controller: scrollController, + children: [ + TextField( + decoration: new InputDecoration( + border: new OutlineInputBorder(borderSide: new BorderSide(color: primaryColor)), + hintText: 'Введите наименовение', + labelText: 'Наименование', + prefixText: ' ', + ), + ), + verticalSpaceSmall, + TextField( + decoration: new InputDecoration( + border: new OutlineInputBorder(borderSide: new BorderSide(color: primaryColor)), + hintText: 'Введите количество', + labelText: 'Количество', + prefixText: ' ', + ), + ), + verticalSpaceSmall, + TextField( + decoration: new InputDecoration( + border: new OutlineInputBorder(borderSide: new BorderSide(color: primaryColor)), + hintText: 'Введите цену за единицу', + labelText: 'Стоимость', + prefixText: ' ', + ), + ), + const Divider( + height: 1.0, + ), + new ListTile( + leading: const Icon(Icons.account_balance_wallet, color: primaryColor,), + title: const Text('0,454'), + subtitle: const Text('Стоимость'), + ), + verticalSpaceMedium, + Row( + mainAxisAlignment: MainAxisAlignment.spaceAround, + children: [ + RawMaterialButton( + onPressed: () {}, + elevation: 2.0, + fillColor: greenColor, + child: Icon( + Icons.done, + size: 35.0, + color: whiteColor, + ), + padding: EdgeInsets.all(15.0), + shape: CircleBorder(), + ), + RawMaterialButton( + onPressed: () {}, + elevation: 2.0, + fillColor: redColor, + child: Icon( + Icons.close, + size: 35.0, + color: whiteColor, + ), + padding: EdgeInsets.all(15.0), + shape: CircleBorder(), + ) + ], + ) + ], + ), + ), ), - child: Text('ProductAddBottomSheet'), ); } } diff --git a/lib/widgets/components/ProductListItem.dart b/lib/widgets/components/ProductListItem.dart index 9b52ca8..8f76713 100644 --- a/lib/widgets/components/ProductListItem.dart +++ b/lib/widgets/components/ProductListItem.dart @@ -1,12 +1,15 @@ +import 'package:aman_kassa_flutter/redux/actions/main_actions.dart'; +import 'package:aman_kassa_flutter/redux/store.dart'; import 'package:aman_kassa_flutter/shared/shared_styles.dart'; import 'package:flutter/material.dart'; import 'package:aman_kassa_flutter/shared/app_colors.dart'; import 'package:aman_kassa_flutter/core/models/ProductDao.dart'; class ProductListItem extends StatelessWidget { - ProductDao item; + final ProductDao item; + final int index; - ProductListItem({this.item}); + ProductListItem({this.item, this.index}); @override Widget build(BuildContext context) { @@ -19,7 +22,7 @@ class ProductListItem extends StatelessWidget { Expanded( child: Container( padding: const EdgeInsets.symmetric(vertical: 8, horizontal: 4), - child: Text(item.name, style: productTextStyle,)), + child: Text(item.name ?? 'name', style: productTextStyle,)), ), Expanded( child: Container( @@ -43,13 +46,19 @@ class ProductListItem extends StatelessWidget { //margin: const EdgeInsets.symmetric(horizontal: 4), child: Row( children: [ - buildClipRect(primaryColor,Icons.remove, () {}), - buildClipRect(primaryColor,Icons.add, () {}), + buildClipRect(primaryColor,Icons.remove, () { + Redux.store.dispatch(counterProductFromKassaItems(index, -1)); + }), + buildClipRect(primaryColor,Icons.add, () { + Redux.store.dispatch(counterProductFromKassaItems(index, 1)); + }), Expanded( child: Container( ), ), - buildClipRect(redColor,Icons.close, () {}), + buildClipRect(redColor,Icons.close, () { + Redux.store.dispatch(removeProductFromKassaItems(index)); + }), ], )), )