Files
fcs/lib/pages/buyer_list.dart
2020-08-30 21:26:37 +06:30

209 lines
7.4 KiB
Dart

import 'package:provider/provider.dart';
import 'package:fcs/model/buyer_model.dart';
import 'package:fcs/pages/search_page.dart';
import 'package:fcs/vo/buyer.dart';
import 'package:fcs/vo/popup_menu.dart';
import 'package:fcs/widget/localization/app_translations.dart';
import 'package:fcs/widget/popupmenu.dart';
import 'package:flutter/material.dart';
import 'package:fcs/widget/progress.dart';
import '../fcs/common/theme.dart';
import 'buyer_list_row.dart';
class BuyerList extends StatefulWidget {
@override
_BuyerListState createState() => _BuyerListState();
}
class _BuyerListState extends State<BuyerList> {
Buyer buyer;
int _selectedIndex = 0;
bool _isLoading = false;
int _selectedSortIndex;
@override
void initState() {
super.initState();
var buyerModel = Provider.of<BuyerModel>(context, listen: false);
var index = buyerModel.popupMenu.index;
_selectedIndex = index;
var sortIndexndex = buyerModel.sortMenu.index;
_selectedSortIndex = sortIndexndex;
}
@override
void dispose() {
super.dispose();
}
@override
Widget build(BuildContext context) {
BuyerModel buyerModel = Provider.of<BuyerModel>(context);
return LocalProgress(
inAsyncCall: _isLoading,
child: Scaffold(
appBar: AppBar(
backgroundColor: primaryColor,
title: Text(AppTranslations.of(context).text("buyer.title")),
actions: <Widget>[
IconButton(
icon: Icon(
Icons.search,
color: Colors.white,
),
iconSize: 30,
onPressed: () => showPlacesSearch(context),
),
PopupMenuButton<PopupMenu>(
elevation: 3.2,
onSelected: (selected) {
setState(() {
this._selectedSortIndex = selected.index;
this._selectedIndex = 0;
buyerModel.filterSorting(
_selectedSortIndex, this._selectedIndex);
});
},
icon: Container(
width: 30,
height: 30,
decoration: new BoxDecoration(
shape: BoxShape.circle,
color: Colors.white,
),
child: Stack(
fit: StackFit.expand,
children: <Widget>[
Icon(
Icons.sort,
color: primaryColor,
),
_selectedSortIndex != null
? Positioned(
bottom: 0,
right: 0,
child: Container(
width: 10,
height: 10,
decoration: new BoxDecoration(
shape: BoxShape.circle,
color: secondaryColor,
),
),
)
: Container()
],
)),
itemBuilder: (BuildContext context) {
return userMenu.map((PopupMenu choice) {
return PopupMenuItem<PopupMenu>(
value: choice,
child: Container(
padding: EdgeInsets.only(left: 8),
child: Row(
children: <Widget>[
Text(choice.status),
SizedBox(
width: 10,
),
_selectedSortIndex != null &&
_selectedSortIndex == choice.index
? Icon(
Icons.check,
color: Colors.grey,
)
: Container(),
],
),
),
);
}).toList();
}),
PopupMenuButton<PopupMenu>(
elevation: 3.2,
onSelected: (selected) {
String status;
setState(() {
this._selectedIndex = selected.index;
this._selectedSortIndex = null;
if (selected.status == 'All') {
status = null;
} else {
status = selected.status;
}
buyerModel.filterStatus(
status, _selectedIndex, this._selectedSortIndex);
});
},
icon: Container(
width: 30,
height: 30,
decoration: new BoxDecoration(
shape: BoxShape.circle,
color: Colors.white,
),
child: Stack(
fit: StackFit.expand,
children: <Widget>[
Icon(
Icons.filter_list,
color: primaryColor,
),
_selectedIndex != 0
? Positioned(
bottom: 0,
right: 0,
child: Container(
width: 10,
height: 10,
decoration: new BoxDecoration(
shape: BoxShape.circle,
color: secondaryColor,
),
),
)
: Container()
],
)),
itemBuilder: (BuildContext context) {
return buyerStatusMenu.map((PopupMenu choice) {
return PopupMenuItem<PopupMenu>(
value: choice,
child: Row(
children: <Widget>[
Text(choice.status),
SizedBox(
width: 10,
),
_selectedIndex != null &&
_selectedIndex == choice.index
? Icon(
Icons.check,
color: Colors.grey,
)
: Container(),
],
),
);
}).toList();
}),
],
),
body: new ListView.builder(
scrollDirection: Axis.vertical,
padding: EdgeInsets.only(top: 15),
shrinkWrap: true,
itemCount: buyerModel.buyers.length,
itemBuilder: (BuildContext context, int index) {
return BuyerListRow(
buyer: buyerModel.buyers[index],
);
}),
),
);
}
}