Files
fcs/lib/reports/report_list.dart
2020-09-04 15:30:10 +06:30

167 lines
6.3 KiB
Dart

import 'package:provider/provider.dart';
import 'package:fcs/model/main_model.dart';
import 'package:fcs/model/report_model.dart';
import 'package:fcs/pages/report_user_list.dart';
import 'package:fcs/reports/fixed_header.dart';
import 'package:fcs/vo/popup_menu.dart';
import 'package:fcs/vo/report.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/helpers/theme.dart';
import 'reports_data_table.dart';
class ReportList extends StatefulWidget {
@override
_ReportListState createState() => _ReportListState();
}
class _ReportListState extends State<ReportList> {
bool _isLoading = false;
Report _report = new Report();
@override
void initState() {
super.initState();
}
@override
void dispose() {
super.dispose();
}
@override
Widget build(BuildContext context) {
ReportModel reportModel = Provider.of<ReportModel>(context);
MainModel mainModel = Provider.of<MainModel>(context);
bool isOwnerAndAbove =
mainModel.user != null && mainModel.user.isOwnerAndAbove();
bool hasAdmin = mainModel.user != null && mainModel.user.hasAdmin();
bool hasOwner = mainModel.user != null && mainModel.user.isOwner();
return LocalProgress(
inAsyncCall: _isLoading,
child: Scaffold(
appBar: AppBar(
backgroundColor: primaryColor,
title: Text(AppTranslations.of(context).text("report.title")),
// actions: <Widget>[
// IconButton(
// onPressed: () {
// reportModel.addreport();
// },
// iconSize: 30,
// icon: Icon(Icons.filter_list),
// ),
// ],
),
floatingActionButton: mainModel.isSysAdmin()
? FloatingActionButton(
backgroundColor: primaryColor,
onPressed: () async {},
child: Icon(
Icons.add,
color: Colors.white,
),
)
: null,
body: new ListView.builder(
scrollDirection: Axis.vertical,
padding: EdgeInsets.only(top: 15),
shrinkWrap: true,
itemCount: reportModel.reportList.length,
itemBuilder: (BuildContext context, int index) {
return Container(
padding: EdgeInsets.only(left: 10, right: 10),
child: Card(
elevation: 10,
color: Colors.white,
child: Row(children: <Widget>[
new Expanded(
child: InkWell(
onTap: () {
Navigator.of(context).push(MaterialPageRoute(
builder: (_) => ReportsDataTable(
report: reportModel.reportList[index],
)));
},
child: new Padding(
padding: const EdgeInsets.symmetric(vertical: 10.0),
child: new Row(children: <Widget>[
Padding(
padding: const EdgeInsets.all(8.0),
child: Image.asset(
"assets/report.png",
width: 40,
height: 40,
// color: primaryColor,
),
),
Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
reportModel.reportList[index].display == null
? ""
: reportModel.reportList[index].display,
style: new TextStyle(
fontSize: 17.0, color: Colors.black),
),
],
),
])),
)),
isOwnerAndAbove || hasAdmin
? hasOwner || hasAdmin
? PopupMenuButton<PopupMenu>(
elevation: 3.2,
tooltip: 'This is tooltip',
onSelected: _select,
itemBuilder: (BuildContext context) {
this._report = reportModel.reportList[index];
return reportUserPopup
.map((PopupMenu choice) {
return PopupMenuItem<PopupMenu>(
value: choice,
child: Text(choice.status),
);
}).toList();
})
: PopupMenuButton<PopupMenu>(
elevation: 3.2,
tooltip: 'This is tooltip',
onSelected: _select,
itemBuilder: (BuildContext context) {
this._report = reportModel.reportList[index];
return reportpopup.map((PopupMenu choice) {
return PopupMenuItem<PopupMenu>(
value: choice,
child: Text(choice.status),
);
}).toList();
})
: Container()
]),
),
);
}),
),
);
}
void _select(PopupMenu popupMenu) {
if (popupMenu.index == 3) {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => ReportUserList(report: this._report)),
);
}
}
}