243 lines
8.2 KiB
Dart
243 lines
8.2 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:infinite_scroll_pagination/infinite_scroll_pagination.dart';
|
|
import 'package:satu/core/models/inventarization/response/inventarization_response.dart';
|
|
import 'package:satu/core/services/dialog_service.dart';
|
|
import 'package:satu/views/inventarization/widget/good_inventarization_list_item.dart';
|
|
|
|
import '../../../core/entity/goods_entity.dart';
|
|
import '../../../core/models/inventarization/good_item/good_item.dart';
|
|
import '../../../core/services/dictionary_service.dart';
|
|
import '../../../core/services/inventarization_service.dart';
|
|
import '../../../core/services/navigator_service.dart';
|
|
import '../../../core/utils/locator.dart';
|
|
import '../../../routes/route_names.dart';
|
|
import '../../../shared/app_colors.dart';
|
|
import '../../../shared/shared_styles.dart';
|
|
import '../../../shared/ui_helpers.dart';
|
|
import '../../../widgets/bar/products_app_bar.dart';
|
|
|
|
class InventarizationEditView extends StatefulWidget {
|
|
const InventarizationEditView({
|
|
required this.item,
|
|
Key? key,
|
|
}) : super(key: key);
|
|
final InventarizationResponse item;
|
|
|
|
@override
|
|
State<InventarizationEditView> createState() =>
|
|
_InventarizationEditViewState();
|
|
}
|
|
|
|
class _InventarizationEditViewState extends State<InventarizationEditView> {
|
|
final InventarizationService _service = locator<InventarizationService>();
|
|
final NavigatorService _navigatorService = locator<NavigatorService>();
|
|
final DialogService _dialogService = locator<DialogService>();
|
|
|
|
static const _pageSize = 20;
|
|
int _pageCurrent = 1;
|
|
bool _isLastPage = false;
|
|
|
|
final PagingController<int, GoodInventarization> _pagingController =
|
|
PagingController(firstPageKey: 1);
|
|
|
|
@override
|
|
void initState() {
|
|
_pagingController.addPageRequestListener((pageKey) {
|
|
_pageCurrent = pageKey;
|
|
_fetchData(pageKey, _pageSize);
|
|
});
|
|
super.initState();
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
_pagingController.dispose();
|
|
super.dispose();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
appBar: const ProductsAppBar(
|
|
title: 'Создание инвентаризации',
|
|
drawerShow: false,
|
|
),
|
|
body: Column(
|
|
children: [
|
|
verticalSpaceSmall,
|
|
Padding(
|
|
padding: const EdgeInsets.symmetric(horizontal: 15.0),
|
|
child: SizedBox(
|
|
width: double.infinity,
|
|
child: Row(
|
|
children: [
|
|
Expanded(
|
|
flex: 4,
|
|
child: Text(
|
|
'Список товара',
|
|
style: textGray11Style,
|
|
),
|
|
),
|
|
Expanded(
|
|
flex: 2,
|
|
child: Text(
|
|
'Количество',
|
|
style: textGray11Style,
|
|
),
|
|
),
|
|
Expanded(
|
|
flex: 1,
|
|
child: Text(
|
|
'Сумма',
|
|
style: textGray11Style,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
verticalSpaceSmall,
|
|
Expanded(
|
|
child: PagedListView<int, GoodInventarization>.separated(
|
|
//physics: const BouncingScrollPhysics(),
|
|
separatorBuilder: (BuildContext context, int index) {
|
|
return const Divider(
|
|
height: 1.0,
|
|
color: disableColor,
|
|
);
|
|
},
|
|
pagingController: _pagingController,
|
|
builderDelegate: PagedChildBuilderDelegate<GoodInventarization>(
|
|
itemBuilder: (BuildContext context, GoodInventarization item,
|
|
int index) {
|
|
return GoodInventarizationListItem(
|
|
key: Key(
|
|
'good_inv_${item.id}',
|
|
),
|
|
inventoryId: widget.item.id,
|
|
inventoryItemId: item.id,
|
|
name: item.name,
|
|
categoryName: item.category,
|
|
count: item.cntBuh,
|
|
price: item.priceBuh,
|
|
ean: item.ean13,
|
|
isOdd: index % 2 == 0,
|
|
refresh: () {
|
|
_pagingController.refresh();
|
|
},
|
|
);
|
|
},
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
|
|
floatingActionButton: floatingActionButtonRender(),
|
|
);
|
|
}
|
|
|
|
/// render floating buttons
|
|
Widget floatingActionButtonRender() {
|
|
return Padding(
|
|
padding: EdgeInsets.all(15),
|
|
child: Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
crossAxisAlignment: CrossAxisAlignment.end,
|
|
children: <Widget>[
|
|
Visibility(
|
|
visible: false,
|
|
child: Padding(
|
|
padding: const EdgeInsets.all(8.0),
|
|
child: FloatingActionButton(
|
|
mini: true,
|
|
elevation: 2,
|
|
backgroundColor: successColor,
|
|
onPressed: () {},
|
|
child: Icon(
|
|
Icons.check,
|
|
color: whiteColor,
|
|
size: 35,
|
|
),
|
|
),
|
|
)),
|
|
Column(
|
|
mainAxisAlignment: MainAxisAlignment.end,
|
|
children: [
|
|
FloatingActionButton(
|
|
elevation: 2,
|
|
mini: true,
|
|
onPressed: () async {
|
|
final Good? good = await locator<NavigatorService>()
|
|
.push(addProductViewRoute) as Good?;
|
|
if (good != null) {
|
|
bool result =
|
|
await _service.addGoodToList(widget.item.id, good.id);
|
|
if (result) {
|
|
_pagingController.refresh();
|
|
} else {
|
|
_dialogService.showDialog(
|
|
description:
|
|
'Товара отсутсвует в остатке или ранее не'
|
|
' использователся в системе',
|
|
);
|
|
}
|
|
}
|
|
},
|
|
child: Icon(
|
|
Icons.add_rounded,
|
|
size: 40,
|
|
color: whiteColor,
|
|
),
|
|
),
|
|
verticalSpaceSmall,
|
|
FloatingActionButton(
|
|
elevation: 2,
|
|
mini: true,
|
|
onPressed: () async {
|
|
final NavigatorService _nav = locator<NavigatorService>();
|
|
final dynamic result = await _nav.push(addByBarcodeViewRoute);
|
|
if (result != null) {
|
|
final List<Good> goods = await locator<DictionaryService>()
|
|
.getGoodsByNameOrEan(result as String);
|
|
if (goods.isNotEmpty) {}
|
|
}
|
|
},
|
|
child: Icon(Icons.qr_code_rounded, size: 30, color: whiteColor),
|
|
),
|
|
],
|
|
)
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
Future<void> _fetchData(int pageKey, int perPage) async {
|
|
final List<GoodInventarization> newItems =
|
|
await _service.getGoodByInventarizationId(
|
|
page: pageKey, perpage: perPage, id: widget.item.id);
|
|
_isLastPage = newItems.length < _pageSize;
|
|
_pageCurrent = pageKey;
|
|
if (_isLastPage) {
|
|
_pagingController.appendLastPage(newItems);
|
|
} else {
|
|
final nextPageKey = pageKey + 1;
|
|
_pageCurrent = nextPageKey;
|
|
_pagingController.appendPage(newItems, nextPageKey);
|
|
}
|
|
}
|
|
|
|
Future<void> _refreshData(int pageKey, int perPage) async {
|
|
print('${pageKey} - ${perPage}');
|
|
final List<GoodInventarization> newItems =
|
|
await _service.getGoodByInventarizationId(
|
|
page: pageKey, perpage: perPage, id: widget.item.id);
|
|
final List<GoodInventarization> oldList =
|
|
_pagingController.value.itemList ?? [];
|
|
oldList.setAll((pageKey - 1) * perPage, newItems);
|
|
setState(() {
|
|
_pagingController.itemList = oldList;
|
|
});
|
|
}
|
|
}
|