import 'dart:io'; import 'package:flutter/material.dart'; import 'package:image_picker/image_picker.dart'; import 'package:provider/provider.dart'; import 'package:fcs/model/language_model.dart'; import 'package:fcs/theme/theme.dart'; import 'package:fcs/widget/localization/app_translations.dart'; import '../util.dart'; class PhotoPage extends StatefulWidget { PhotoPage({Key key}) : super(key: key); @override _PhotoPageState createState() => _PhotoPageState(); } class _PhotoPageState extends State { File receiptImageFile; @override Widget build(BuildContext context) { var languageModel = Provider.of(context); final receiptImageBox = Padding( padding: EdgeInsets.symmetric(vertical: 5.0), child: Container( color: Colors.grey[400], child: Column( children: [ Container( padding: EdgeInsets.only(top: 15), child: Text( AppTranslations.of(context).text('do.receipt'), style: languageModel.isEng ? photoLabelStyle : photoLabelStyleMM, ), ), Row( mainAxisAlignment: MainAxisAlignment.center, children: [ ButtonTheme.bar( child: new ButtonBar( alignment: MainAxisAlignment.start, children: [ new FlatButton( child: Icon( Icons.add_photo_alternate, size: 60.0, color: Colors.black, ), onPressed: () { pickImageFromGallery(ImageSource.gallery); }, ), ], )), ButtonTheme.bar( child: new ButtonBar( alignment: MainAxisAlignment.start, children: [ new FlatButton( child: Icon( Icons.add_a_photo, size: 50.0, color: Colors.black, ), onPressed: () { pickImageFromCamera(ImageSource.camera); }, ), ], )), ], ), receiptShowImage(), SizedBox( height: 10, ) ], ), ), ); return Scaffold( appBar: AppBar( backgroundColor: primaryColor, title: Text(AppTranslations.of(context).text("do.receipt.title"), style: Provider.of(context).isEng ? TextStyle(fontSize: 18) : TextStyle(fontSize: 18, fontFamily: 'MyanmarUnicode')), actions: [ IconButton( icon: Icon(Icons.send), onPressed: () { if (receiptImageFile == null) { showMsgDialog( context, "Error", "Please insert delivery receipt file"); return; } Navigator.pop(context, receiptImageFile); }, ) ], ), body: Column( children: [ Expanded( child: ListView( shrinkWrap: true, padding: EdgeInsets.only(left: 24.0, right: 24.0, top: 20), children: [ receiptImageBox, ], ), ), SizedBox( height: 20, ) ], ), ); } Widget receiptShowImage() { return Container( child: receiptImageFile == null ? initialImage() : receiptEnableImage(), ); } Widget initialImage() { var languageModel = Provider.of(context); return Center( child: Text( AppTranslations.of(context).text('do.no.photo'), style: languageModel.isEng ? photoLabelStyle : photoLabelStyleMM, ), ); } Widget receiptEnableImage() { return Center( child: Image.file( receiptImageFile, ), ); } pickImageFromGallery(ImageSource source) async { var tempImage = await ImagePicker.pickImage( source: source, imageQuality: 80, maxWidth: 300); setState(() { receiptImageFile = tempImage; }); } pickImageFromCamera(ImageSource source) async { var tempImage = await ImagePicker.pickImage( source: source, imageQuality: 80, maxWidth: 300); setState(() { receiptImageFile = tempImage; }); } }