99 lines
2.9 KiB
Dart
99 lines
2.9 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:infinite_scroll_pagination/infinite_scroll_pagination.dart';
|
|
import 'package:satu/core/models/but_item/buy_item_response.dart';
|
|
import 'package:satu/views/work/tabs/buy/component/product_buy_tile.dart';
|
|
|
|
|
|
import '../../../../core/models/buy_invoice/buy_invoice_response.dart';
|
|
import '../../../../core/services/buy_service.dart';
|
|
import '../../../../core/services/navigator_service.dart';
|
|
import '../../../../core/utils/locator.dart';
|
|
import '../../../../shared/app_colors.dart';
|
|
import '../../../../widgets/bar/products_app_bar.dart';
|
|
|
|
class BuyEditView extends StatefulWidget {
|
|
const BuyEditView({required this.invoice, Key? key}) : super(key: key);
|
|
|
|
final BuyInvoiceResponse invoice;
|
|
|
|
@override
|
|
State<BuyEditView> createState() => _BuyEditViewState();
|
|
}
|
|
|
|
class _BuyEditViewState extends State<BuyEditView> {
|
|
final BuyService _service = locator<BuyService>();
|
|
|
|
static const _pageSize = 20;
|
|
|
|
final PagingController<int, BuyItemResponse> _pagingController =
|
|
PagingController(firstPageKey: 1);
|
|
|
|
|
|
@override
|
|
void initState() {
|
|
_pagingController.addPageRequestListener((pageKey) {
|
|
_fetchData(pageKey, _pageSize);
|
|
});
|
|
super.initState();
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
|
|
_pagingController.dispose();
|
|
super.dispose();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
appBar: const ProductsAppBar(
|
|
title: 'Покупка',
|
|
),
|
|
body: Column(
|
|
children: [
|
|
Expanded(
|
|
child: PagedListView<int, BuyItemResponse>.separated(
|
|
physics: const BouncingScrollPhysics(),
|
|
separatorBuilder: (BuildContext context, int index) {
|
|
return const Divider(
|
|
height: 1.0,
|
|
color: disableColor,
|
|
);
|
|
},
|
|
pagingController: _pagingController,
|
|
builderDelegate: PagedChildBuilderDelegate<BuyItemResponse>(
|
|
itemBuilder: (BuildContext context, BuyItemResponse item,
|
|
int index) {
|
|
return ProductBuyTile(
|
|
key: ValueKey(item.id),
|
|
ean: '1234567890123',
|
|
name: 'Картофель',
|
|
price: item.price,
|
|
count: item.cnt,
|
|
categoryName: 'Овощи',
|
|
isOdd: true,
|
|
);
|
|
},
|
|
),
|
|
),
|
|
)
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
Future<void> _fetchData(int pageKey, int perPage) async {
|
|
final List<BuyItemResponse> newItems = await _service
|
|
.getItemList(widget.invoice.id, page: pageKey, perpage: perPage);
|
|
final isLastPage = newItems.length < _pageSize;
|
|
if (isLastPage) {
|
|
_pagingController.appendLastPage(newItems);
|
|
} else {
|
|
final nextPageKey = pageKey + 1;
|
|
_pagingController.appendPage(newItems, nextPageKey);
|
|
}
|
|
}
|
|
|
|
}
|