2019-08-05 09:33:39 +01:00
import ' package:flutter/material.dart ' ;
import ' package:local_spend/common/platform/platform_scaffold.dart ' ;
2019-08-05 11:44:03 +01:00
import ' package:intl/intl.dart ' ;
import ' package:flutter/cupertino.dart ' ;
2019-08-07 13:15:15 +01:00
import ' package:local_spend/common/apifunctions/find_organisations.dart ' ;
import ' package:local_spend/common/widgets/organisations_dialog.dart ' ;
2019-08-05 09:33:39 +01:00
2019-08-05 12:24:40 +01:00
class Transaction {
DateTime date ;
2019-08-07 13:15:15 +01:00
TextEditingController amount ;
Organisation organisation ;
2019-08-05 12:24:40 +01:00
Transaction (
this . date ,
this . amount ,
2019-08-07 13:15:15 +01:00
this . organisation ,
2019-08-05 12:24:40 +01:00
) ;
}
2019-08-05 09:33:39 +01:00
class ReceiptPage2 extends StatefulWidget {
@ override
State < StatefulWidget > createState ( ) {
return new ReceiptPage2State ( ) ;
}
}
class ReceiptPage2State extends State < ReceiptPage2 > {
2019-08-07 13:15:15 +01:00
Transaction transaction = new Transaction (
DateTime . now ( ) ,
new TextEditingController ( ) ,
new Organisation ( null , null , null , null , null ) ,
) ;
2019-08-05 12:24:40 +01:00
2019-08-05 09:33:39 +01:00
@ override
Widget build ( BuildContext context ) {
2019-08-05 11:44:03 +01:00
2019-08-05 09:33:39 +01:00
return PlatformScaffold (
appBar: AppBar (
2019-08-08 15:25:43 +01:00
backgroundColor: Colors . blue [ 400 ] ,
title: Text (
" Submit Receipt " ,
style: TextStyle (
fontSize: 20 ,
color: Colors . white ,
) ,
2019-08-05 09:33:39 +01:00
) ,
2019-08-08 15:25:43 +01:00
centerTitle: true ,
iconTheme: IconThemeData ( color: Colors . black ) ,
2019-08-05 09:33:39 +01:00
) ,
2019-08-05 11:44:03 +01:00
body: ListView (
children: < Widget > [
// each CHILD has its own horizontal padding because if the listView has padding, Android's end-of-scroll animation
// doesn't fit the screen properly and looks weird
2019-08-05 12:11:40 +01:00
2019-08-05 11:44:03 +01:00
Container (
padding: const EdgeInsets . fromLTRB ( 15 , 17 , 0 , 0 ) ,
child : Text (
" Receipt Details " ,
style: TextStyle (
fontSize: 24 ,
color: Colors . grey [ 700 ] ,
fontWeight: FontWeight . bold ,
) ,
) ,
2019-08-05 12:11:40 +01:00
) , // "Receipt Details" title
2019-08-05 11:44:03 +01:00
Container (
padding: EdgeInsets . fromLTRB ( 25 , 15 , 15.0 , 0.0 ) ,
child: Row (
children: < Widget > [
2019-08-05 12:24:40 +01:00
Container (
child : Text (
" Date/Time " ,
style: TextStyle (
fontSize: 18 ,
color: Colors . black ,
fontWeight: FontWeight . bold ,
) ,
2019-08-05 11:44:03 +01:00
) ,
2019-08-05 12:24:40 +01:00
width: 110 ,
2019-08-05 11:44:03 +01:00
) ,
Container (
2019-08-05 12:24:40 +01:00
padding: const EdgeInsets . fromLTRB ( 0 , 0 , 0 , 0 ) ,
2019-08-05 11:44:03 +01:00
height: 32.0 ,
child: RaisedButton (
onPressed: ( ) {
showModalBottomSheet (
context: context ,
builder: ( BuildContext builder ) {
return Container (
height: MediaQuery . of ( context ) . copyWith ( ) . size . height / 3 ,
child: CupertinoDatePicker (
2019-08-05 12:24:40 +01:00
initialDateTime: transaction . date . isAfter ( DateTime . now ( ) )
2019-08-05 11:44:03 +01:00
? DateTime . now ( )
2019-08-05 12:24:40 +01:00
: transaction . date ,
2019-08-05 11:44:03 +01:00
onDateTimeChanged: ( DateTime newDate ) {
setState ( ( ) = > {
newDate . isAfter ( DateTime . now ( ) )
2019-08-05 12:24:40 +01:00
? transaction . date = DateTime . now ( )
: transaction . date = newDate ,
2019-08-05 11:44:03 +01:00
} ) ;
} ,
use24hFormat: true ,
maximumDate: DateTime . now ( ) ,
) ,
) ;
} ) ;
2019-08-08 15:25:43 +01:00
} ,
2019-08-05 11:44:03 +01:00
child: Text (
2019-08-05 12:24:40 +01:00
transaction . date = = null
2019-08-05 11:44:03 +01:00
? ' None set. '
2019-08-05 12:24:40 +01:00
: transaction . date . year = = DateTime . now ( ) . year
? ' ${ new DateFormat . MMMd ( ) . format ( transaction . date ) } ' + " , " + ' ${ new DateFormat . Hm ( ) . format ( transaction . date ) } '
: ' ${ new DateFormat . MMMd ( ) . format ( transaction . date ) } ' + " " + transaction . date . year . toString ( ) + " , " + ' ${ new DateFormat . Hm ( ) . format ( transaction . date ) } ' ,
2019-08-05 11:44:03 +01:00
style:
TextStyle ( color: Colors . white , fontSize: 18.0 ) ,
) ,
color: Colors . blue ,
) ,
) ,
] ,
) ,
2019-08-05 12:11:40 +01:00
) , // Date/Time picker
Container (
padding: EdgeInsets . fromLTRB ( 25 , 15 , 15.0 , 0.0 ) ,
child: Row (
children: < Widget > [
2019-08-05 12:24:40 +01:00
Container (
child : Text (
2019-08-07 13:15:15 +01:00
" Payee " ,
2019-08-05 12:24:40 +01:00
style: TextStyle (
fontSize: 18 ,
color: Colors . black ,
fontWeight: FontWeight . bold ,
) ,
2019-08-05 12:11:40 +01:00
) ,
2019-08-05 12:24:40 +01:00
width: 110 ,
2019-08-05 12:11:40 +01:00
) ,
Container (
2019-08-05 12:24:40 +01:00
padding: const EdgeInsets . fromLTRB ( 0 , 0 , 0 , 0 ) ,
2019-08-05 12:11:40 +01:00
height: 32.0 ,
child: RaisedButton (
onPressed: ( ) {
2019-08-07 13:15:15 +01:00
// var popupListView = new PopupListView();
// var dialog = popupListView.dialog(context, optionsList, "Choose Organization");
var organisations = new FindOrganisations ( ) ;
var orgDialog = organisations . dialog ( context ) ;
orgDialog . then ( ( organisation ) {
2019-08-09 14:32:47 +01:00
setState ( ( ) = > { } ) ;
2019-08-07 13:15:15 +01:00
debugPrint ( organisation . name ) ;
} ) ;
} ,
2019-08-05 12:11:40 +01:00
child: Text (
2019-08-07 13:15:15 +01:00
transaction . organisation . name = = null
? ' Find '
: transaction . organisation . name ,
style:
TextStyle ( color: Colors . white , fontSize: 18.0 ) ,
2019-08-05 12:11:40 +01:00
) ,
color: Colors . blue ,
) ,
) ,
] ,
) ,
2019-08-07 13:15:15 +01:00
) , // Organisation picker
Container (
padding: EdgeInsets . fromLTRB ( 25 , 15 , 15.0 , 0.0 ) ,
child: Row (
children: < Widget > [
Container (
child : Text (
" Amount " ,
style: TextStyle (
fontSize: 18 ,
color: Colors . black ,
fontWeight: FontWeight . bold ,
) ,
) ,
width: 110 ,
) ,
Container (
padding: const EdgeInsets . fromLTRB ( 0 , 0 , 0 , 0 ) ,
height: 32.0 ,
width: 100 ,
child: TextField (
controller: transaction . amount ,
decoration: InputDecoration (
hintText: " £0.00 "
) ,
2019-08-09 16:45:58 +01:00
keyboardType: TextInputType . numberWithOptions ( decimal: true , signed: true ) ,
2019-08-07 13:15:15 +01:00
) ,
) ,
] ,
) ,
2019-08-05 12:24:40 +01:00
) , // Amount picker
2019-08-05 11:44:03 +01:00
] ,
) ,
2019-08-05 09:33:39 +01:00
) ;
}
}