Files
fcs/lib/pages/do/photo_page.dart

166 lines
4.6 KiB
Dart
Raw Normal View History

2020-05-29 07:45:27 +06:30
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<PhotoPage> {
File receiptImageFile;
@override
Widget build(BuildContext context) {
var languageModel = Provider.of<LanguageModel>(context);
final receiptImageBox = Padding(
padding: EdgeInsets.symmetric(vertical: 5.0),
child: Container(
color: Colors.grey[400],
child: Column(
children: <Widget>[
Container(
padding: EdgeInsets.only(top: 15),
child: Text(
AppTranslations.of(context).text('do.receipt'),
style:
languageModel.isEng ? photoLabelStyle : photoLabelStyleMM,
),
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
ButtonTheme.bar(
child: new ButtonBar(
alignment: MainAxisAlignment.start,
children: <Widget>[
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: <Widget>[
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<LanguageModel>(context).isEng
? TextStyle(fontSize: 18)
: TextStyle(fontSize: 18, fontFamily: 'MyanmarUnicode')),
actions: <Widget>[
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: <Widget>[
Expanded(
child: ListView(
shrinkWrap: true,
padding: EdgeInsets.only(left: 24.0, right: 24.0, top: 20),
children: <Widget>[
receiptImageBox,
],
),
),
SizedBox(
height: 20,
)
],
),
);
}
Widget receiptShowImage() {
return Container(
child: receiptImageFile == null ? initialImage() : receiptEnableImage(),
);
}
Widget initialImage() {
var languageModel = Provider.of<LanguageModel>(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;
});
}
}