aman-satu-flutter/lib/views/inventarization/view/inventarization_view.dart

165 lines
5.7 KiB
Dart
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

import 'package:flutter/material.dart';
import 'package:infinite_scroll_pagination/infinite_scroll_pagination.dart';
import 'package:intl/intl.dart';
import 'package:satu/core/models/inventarization/response/inventarization_response.dart';
import 'package:satu/core/services/dialog_service.dart';
import 'package:satu/core/services/inventarization_service.dart';
import 'package:satu/core/services/navigator_service.dart';
import 'package:satu/core/utils/locator.dart';
import 'package:satu/shared/app_colors.dart';
import 'package:satu/shared/shared_styles.dart';
import 'package:satu/shared/ui_helpers.dart';
import 'package:satu/views/inventarization/widget/inventarization_list_tile.dart';
import '../../../routes/route_names.dart';
import '../../../widgets/bar/products_app_bar.dart';
import '../../dictionaries/component/dictionary_list_tile.dart';
class InventarizationView extends StatefulWidget {
const InventarizationView({Key? key}) : super(key: key);
@override
State<InventarizationView> createState() => _InventarizationViewState();
}
class _InventarizationViewState extends State<InventarizationView> {
final InventarizationService _service = locator<InventarizationService>();
final NavigatorService _navigatorService = locator<NavigatorService>();
final DialogService _dialogService = locator<DialogService>();
static const _pageSize = 20;
final PagingController<int, InventarizationResponse> _pagingController =
PagingController(firstPageKey: 1);
final DateFormat formatterDay = DateFormat('dd.MM.yyyy');
@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: 'Инвентаризация',
drawerShow: true,
),
body: Column(
children: [
verticalSpaceSmall,
Padding(
padding: const EdgeInsets.only(left: 15.0),
child: SizedBox(
width: double.infinity,
child: Row(
children: [
Expanded(
flex: 2,
child: Text(
'Номер документа',
style: textGray11Style,
),
),
Expanded(
flex: 2,
child: Text(
'Дата создания',
style: textGray11Style,
),
),
Expanded(
flex: 1,
child: Text(
'Акты',
style: textGray11Style,
),
),
],
),
),
),
verticalSpaceSmall,
Expanded(
child: PagedListView<int, InventarizationResponse>.separated(
physics: const BouncingScrollPhysics(),
separatorBuilder: (BuildContext context, int index) {
return const Divider(
height: 1.0,
color: disableColor,
);
},
pagingController: _pagingController,
builderDelegate:
PagedChildBuilderDelegate<InventarizationResponse>(
itemBuilder: (BuildContext context,
InventarizationResponse item, int index) {
return DictionaryTile(
key: Key('category_${item.id}'),
onPress: () async {
if (item.act != null) {
return _dialogService.showDialog(
description:
'В обработанный акт нельзя добавить товары');
}
final dynamic result = await _navigatorService
.push(inventarizationEditRoute, arguments: item);
if (result != null && true == (result as bool)) {
_pagingController.refresh();
}
},
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Expanded(
flex: 2,
child: InventarizationCellTile(
value: item.docNumber.toString()),
),
Expanded(
flex: 2,
child: InventarizationCellTile(
value: formatterDay.format(item.createdAt),
),
),
Expanded(
flex: 1,
child: InventarizationCellButton(
value: item.act,
),
),
],
),
);
},
),
),
)
],
),
);
}
Future<void> _fetchData(int pageKey, int perPage) async {
final List<InventarizationResponse> newItems =
await _service.getList(page: pageKey, perpage: perPage);
final isLastPage = newItems.length < _pageSize;
if (isLastPage) {
_pagingController.appendLastPage(newItems);
} else {
final nextPageKey = pageKey + 1;
_pagingController.appendPage(newItems, nextPageKey);
}
}
}