import 'package:flutter/material.dart'; import 'package:intl/intl.dart'; import 'package:provider/provider.dart'; import 'package:fcs/model/language_model.dart'; import 'package:fcs/model/pd_model.dart'; import 'package:fcs/pages/pd/pd_form.dart'; import 'package:fcs/fcs/common/helpers/theme.dart'; import 'package:fcs/widget/localization/app_translations.dart'; import 'package:fcs/widget/progress.dart'; class PDList extends StatefulWidget { @override _PDListState createState() => _PDListState(); } class _PDListState extends State { final double dotSize = 15.0; DateTime _selectedDate = DateTime.now(); int _dateIndex = 0; bool _isLoading = false; @override void initState() { super.initState(); var pdModel = Provider.of(context, listen: false); // pdModel.loadPDs(); _selectedDate = pdModel.selectedDate; _dateIndex = pdModel.dateIndex; } Future _selectDate(BuildContext context) async { var pdModel = Provider.of(context); final DateTime picked = await showDatePicker( context: context, initialDate: _selectedDate, firstDate: DateTime(2015, 8), lastDate: DateTime(2101), builder: (BuildContext context, Widget child) { return Theme( data: ThemeData.light().copyWith( primaryColor: primaryColor, //Head background accentColor: secondaryColor, //selection color dialogBackgroundColor: Colors.white, //Background color ), child: child, ); }, ); if (picked != null) { var pickedDate = new DateTime(picked.year, picked.month, picked.day); var currentDate = new DateTime( DateTime.now().year, DateTime.now().month, DateTime.now().day); this._dateIndex = pickedDate == currentDate ? 0 : 1; setState(() { _selectedDate = picked; pdModel.filterDate(_selectedDate, _dateIndex); }); } } @override Widget build(BuildContext context) { var pdModel = Provider.of(context); return LocalProgress( inAsyncCall: _isLoading, child: Scaffold( appBar: AppBar( backgroundColor: primaryColor, title: Text( AppTranslations.of(context).text('pd.title'), style: Provider.of(context).isEng ? TextStyle() : TextStyle(fontFamily: 'MyanmarUnicode'), ), actions: [ InkWell( child: Container( padding: EdgeInsets.only(right: 15, top: 15), child: Stack( children: [ Image.asset( "assets/date_filter.png", color: Colors.white, width: 25, ), _dateIndex == 0 ? Container() : Positioned( bottom: 15, right: 10, child: Container( width: 10, height: 10, decoration: new BoxDecoration( shape: BoxShape.circle, color: secondaryColor, ), ), ) ], ), ), onTap: () => _selectDate(context), ), ], ), floatingActionButton: FloatingActionButton( backgroundColor: primaryColor, child: Icon(Icons.add), onPressed: () { Navigator.push( context, MaterialPageRoute(builder: (context) => PDForm()), ); }, ), body: new ListView.builder( padding: EdgeInsets.only(left: 10, right: 10, top: 15), shrinkWrap: true, itemCount: pdModel.pds.length, itemBuilder: (BuildContext context, int index) { return InkWell( onTap: () { Navigator.push( context, MaterialPageRoute( builder: (context) => PDForm( pd: pdModel.pds[index], )), ); }, child: Card( elevation: 10, color: Colors.white, child: Row( children: [ new Padding( padding: EdgeInsets.all(10), child: Padding( padding: EdgeInsets.all(10.0), child: Image.asset( "assets/pdo.png", width: 30, color: primaryColor, )), ), Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Padding( padding: const EdgeInsets.all(8.0), child: new Text( pdModel.pds[index].date == null ? "" : DateFormat('dd MMM yyyy') .format(pdModel.pds[index].date), style: textStyle), ), Padding( padding: const EdgeInsets.only(left: 8.0), child: new Text( pdModel.pds[index].pdNumber == null ? '' : pdModel.pds[index].pdNumber, style: new TextStyle( fontSize: 12.0, color: Colors.grey), ), ), ], ), SizedBox( height: 15, ) ], ), ), ); }), ), ); } }