KassaTab.dart add ProductDao.dart

4.4
Serik.Uvaissov 2020-06-08 17:16:50 +06:00
parent 1d18e70208
commit 0f1f45223a
8 changed files with 168 additions and 44 deletions

View File

@ -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});
}

View File

@ -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<void> backBottomElement(Store<AppState> store) async {
store.dispatch(SetMainStateAction(MainState(prevCategories: prevCategories)));
store.dispatch(selectBottomElement(last.id));
}
}
ThunkAction<AppState> addProductToKassaItems(Good good) {
return (Store<AppState> store) async {
List<ProductDao> 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<AppState> removeProductFromKassaItems(int index) {
return (Store<AppState> store) async {
List<ProductDao> items = List.from(store.state.mainState.kassaItems);
items.removeAt(index);
store.dispatch(SetMainStateAction(MainState(kassaItems: items)));
};
}
ThunkAction<AppState> counterProductFromKassaItems(int index, int counter) {
return (Store<AppState> store) async {
List<ProductDao> 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<AppState> selectBottomElement(int parentId) {

View File

@ -7,5 +7,6 @@ mainReducer(MainState prevState, SetMainStateAction action) {
bottomSheetElements: payload.bottomSheetElements,
bottomSheetLoading: payload.bottomSheetLoading,
prevCategories: payload.prevCategories,
kassaItems: payload.kassaItems,
);
}

View File

@ -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<DictDao> prevCategories;
MainState({this.bottomSheetElements, this.bottomSheetLoading, this.prevCategories});
final List<ProductDao> kassaItems;
MainState(
{this.bottomSheetElements,
this.bottomSheetLoading,
this.prevCategories,
this.kassaItems});
factory MainState.initial() => MainState(
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,
prevCategories: prevCategories ?? this.prevCategories,
kassaItems: kassaItems ?? this.kassaItems,
);
}
}

View File

@ -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<String> 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,
child: StoreConnector<AppState, MainState>(
converter: (store) => store.state.mainState,
builder: (context, vm) {
return ListView.builder(
itemCount: vm.kassaItems.length,
itemBuilder: (BuildContext ctxt, int index) =>
buildItem(ctxt, 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,);
}

View File

@ -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:

View File

@ -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: <Widget>[
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: <Widget>[
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'),
);
}
}

View File

@ -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: <Widget>[
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));
}),
],
)),
)