product list

null-safety-migration
suvaissov 2021-07-01 00:05:56 +06:00
parent 05cf3f4284
commit d500e4daf7
5 changed files with 75 additions and 30 deletions

View File

@ -28,6 +28,35 @@ final Logger log = getLogger('SetSellStateAction');
final DbService _dbService = locator<DbService>();
ThunkAction<AppState> counterSellItem({required int transactionId, required num counter}) {
return (Store<AppState> store) async {
log.i('counterSellItem');
int? appCompanyId = store.state.userState!.auth!.companyId;
String? uuid = store.state.sellState!.transactionState!.uuid;
Transaction? transaction;
if (uuid != null ) {
List<Map<String, dynamic>> set = await _dbService.queryRowsWithWhere(
TransactionTableName,
'$TransactionColumnAppCompanyId = ? and $TransactionColumnStatus = ? and ${TransactionColumnType} = ? and ${TransactionColumnId} = ?',
[appCompanyId, TransactionStatusPrepare, TransactionTypeSell, transactionId],
orderBy: '$TransactionColumnCreatedAt desc');
if (set.isNotEmpty) {
transaction = Transaction.fromMap(set.first);
}
}
if (transaction != null) {
ProductDao item = ProductDao.fromMap(jsonDecode(transaction.data!));
item.count = (item.count ?? 0) + counter;
transaction.data = jsonEncode(item.toMap());
_dbService.update(TransactionTableName, transaction.toMap());
}
// refresh from db ? after save data
await loadSellData(store);
};
}
ThunkAction<AppState> addSellItem({required Good good, String? excise}) {
return (Store<AppState> store) async {
log.i('addSellItem');
@ -108,20 +137,6 @@ ThunkAction<AppState> removeSellItem({required int transactionId}) {
int count = await _dbService.delete(TransactionTableName, transactionId);
log.i('removeSellItem ${count} by transactionId:${transactionId}');
// List<Map<String, dynamic>> set = await _dbService.queryRowsWithWhere(
// TransactionTableName,
// '$TransactionColumnId = ? ',
// [transactionId]);
// if (set.isNotEmpty) {
// for (Map<String, dynamic> map in set) {
// Transaction _transaction = Transaction.fromMap(map);
// ProductDao _product = ProductDao.fromMap(jsonDecode(_transaction.data));
// if (_product.id == good.id && _product.excise == excise) {
// transaction = _transaction;
// break;
// }
// }
// }
// refresh from db ? after save data
await loadSellData(store);

View File

@ -4,9 +4,9 @@ import 'package:satu/core/redux/state/nav_state.dart';
import 'package:satu/core/redux/state/user_state.dart';
navReducer(NavState prevState, SetNavStateAction action) {
final payload = action.navState;
final NavState? payload = action.navState;
return prevState.copyWith(
drawerViewClass: payload.drawerViewClass!,
selectedTabIndex: payload.selectedTabIndex!,
drawerViewClass: payload?.drawerViewClass!,
selectedTabIndex: payload?.selectedTabIndex!,
);
}

View File

@ -49,6 +49,7 @@ class _ProductListItemState extends State<ProductListItem> {
padding: const EdgeInsets.all(8.0),
child: Text(
'Удалить',
style: TextStyle(color: whiteColor, fontWeight: FontWeight.w500),
),
),
),
@ -78,6 +79,7 @@ class _ProductListItemState extends State<ProductListItem> {
key: Key(widget.name ?? ''),
child: ListTile(
//onTap: () => _onItemTapped(context),
onTap: () {},
contentPadding: const EdgeInsets.symmetric(horizontal: 10.0, vertical: 4.0),
title: Row(
crossAxisAlignment: CrossAxisAlignment.start,
@ -126,9 +128,13 @@ class _ProductListItemState extends State<ProductListItem> {
color: Colors.transparent,
borderRadius: BorderRadius.circular(ScreenUtil().radius(5)),
child: InkWell(
onTap: () {},
onTap: () {
Redux.store!
.dispatch(counterSellItem(transactionId: this.widget.transactionId!, counter: 1.0));
},
child: Container(
decoration: BoxDecoration(
color: whiteColor,
borderRadius: BorderRadius.circular(ScreenUtil().radius(5)),
border: Border.all(width: 1.0.sp, color: successColor)),
child: Icon(
@ -151,10 +157,7 @@ class _ProductListItemState extends State<ProductListItem> {
width: 45.w,
child: Text(
'${widget.count} шт',
style: TextStyle(
fontSize: 8.sp,
color: placeholderColor
),
style: TextStyle(fontSize: 8.sp, color: placeholderColor),
textAlign: TextAlign.center,
),
),
@ -163,11 +166,18 @@ class _ProductListItemState extends State<ProductListItem> {
color: Colors.transparent,
borderRadius: BorderRadius.circular(ScreenUtil().radius(5)),
child: InkWell(
onTap: () {},
onTap: () {
if (widget.count! > 1.0) {
Redux.store!
.dispatch(counterSellItem(transactionId: this.widget.transactionId!, counter: -1.0));
}
},
child: Container(
decoration: BoxDecoration(
color: whiteColor,
borderRadius: BorderRadius.circular(ScreenUtil().radius(5)),
border: Border.all(width: 1.0.sp, color: widget.count! <= 1.0 ? disableColor : dangerColor)),
border: Border.all(
width: 1.0.sp, color: widget.count! <= 1.0 ? disableColor : dangerColor)),
child: Icon(
Icons.remove,
color: widget.count! <= 1.0 ? disableColor : dangerColor,

View File

@ -28,7 +28,24 @@ class ProductsTitleBarBar extends StatelessWidget {
)),
if(itemsExist)
TextButton(
onPressed: () {
onPressed: () async {
bool? result = await showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: const Text("Внимание"),
content: Text("Удалить все товары из списка"),
actions: <Widget>[
TextButton(onPressed: () => Navigator.of(context).pop(true), child: const Text("Удалить")),
TextButton(
onPressed: () => Navigator.of(context).pop(false),
child: const Text("Отмена"),
),
],
);
},
);
if(result == true)
Redux.store!.dispatch(removeAllSellData);
},
child: Text(

View File

@ -40,8 +40,8 @@ class SellView extends StatelessWidget {
ContragentSelectBar(
value: 'Частное лицо',
),
ProductsTitleBarBar(itemsExist: state.items!.isNotEmpty),
ListView.builder(
Visibility(child: ProductsTitleBarBar(itemsExist: true), visible: state.items!.isNotEmpty,),
ListView.separated(
shrinkWrap: true,
physics: BouncingScrollPhysics(),
itemCount: state.items!.length,
@ -58,6 +58,9 @@ class SellView extends StatelessWidget {
transactionId: product.transactionId,
);
},
separatorBuilder: (context, index) {
return Divider(height: 1, color: disableColor,);
},
),
],
),