add payment

This commit is contained in:
Sai Naw Wun
2020-10-28 05:11:06 +06:30
parent 2786acfd08
commit d5c2407545
28 changed files with 740 additions and 601 deletions

View File

@@ -0,0 +1,162 @@
import 'dart:io';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:image_picker/image_picker.dart';
import 'show_img.dart';
typedef OnFile = void Function(File);
class LocalImagePicker extends StatefulWidget {
final Color color;
final String title;
final OnFile onFile;
final bool enabled;
final String initialImgUrl;
final ImageSource imageSource;
const LocalImagePicker(
{Key key,
this.title,
this.onFile,
this.enabled = true,
this.initialImgUrl,
this.imageSource = ImageSource.gallery,
this.color})
: super(key: key);
@override
_LocalImagePickerState createState() => _LocalImagePickerState();
}
class _LocalImagePickerState extends State<LocalImagePicker> {
String url;
File file;
@override
void initState() {
super.initState();
this.url = widget.initialImgUrl == null || widget.initialImgUrl == ""
? null
: widget.initialImgUrl;
}
@override
Widget build(BuildContext context) {
return Container(
height: 30,
child: this.file == null && this.url == null
? IconButton(
padding: const EdgeInsets.all(3.0),
icon: Icon(Icons.attach_file, color: widget.color ?? Colors.blue),
onPressed: () async {
if (!widget.enabled) return;
bool camera = false, gallery = false;
await _dialog(
context, () => camera = true, () => gallery = true);
if (camera || gallery) {
var selectedFile = await ImagePicker.pickImage(
source: camera ? ImageSource.camera : ImageSource.gallery,
imageQuality: 80,
maxWidth: 1000);
if (selectedFile != null) {
setState(() {
this.file = selectedFile;
});
if (widget.onFile != null) {
widget.onFile(selectedFile);
}
}
}
},
)
: InkWell(
onTap: () => {
Navigator.of(context).push(CupertinoPageRoute(
builder: (context) => ShowImage(
imageFile: file,
url: file == null ? widget.initialImgUrl : null,
fileName: widget.title))),
},
child: Padding(
padding: const EdgeInsets.only(left: 3.0),
child: Chip(
avatar: Icon(
Icons.image,
color: widget.color ?? Colors.blue,
),
onDeleted: !widget.enabled
? null
: () {
setState(() {
this.file = null;
this.url = null;
if (widget.onFile != null) {
widget.onFile(null);
}
});
},
deleteIcon: Icon(
Icons.close,
color: widget.color ?? Colors.blue,
),
label: Text(widget.title),
),
),
),
);
}
Future<void> _dialog(BuildContext context, cameraPress(), photoPress()) {
return showDialog<void>(
context: context,
builder: (BuildContext context) {
return AlertDialog(
content: Container(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
IconButton(
icon: Icon(
FontAwesomeIcons.camera,
size: 30,
color: widget.color ?? Colors.blue,
),
onPressed: () {
Navigator.pop(context);
cameraPress();
}),
Text("Camera")
],
),
Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
IconButton(
icon: Icon(
Icons.photo_library,
size: 30,
color: widget.color ?? Colors.blue,
),
onPressed: () {
Navigator.pop(context);
photoPress();
}),
Text("Gallery")
],
),
],
),
),
),
);
},
);
}
}

View File

@@ -0,0 +1,125 @@
import 'dart:async';
import 'dart:io';
import 'package:fcs/helpers/cache_mgr.dart';
import 'package:fcs/helpers/theme.dart';
import 'package:fcs/pages/main/util.dart';
import 'package:fcs/pages/widgets/progress.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_pdfview/flutter_pdfview.dart';
import 'package:share/share.dart';
class PDFScreen extends StatefulWidget {
final String title;
final String url;
PDFScreen({Key key, this.url, this.title}) : super(key: key);
_PDFScreenState createState() => _PDFScreenState();
}
class _PDFScreenState extends State<PDFScreen> with WidgetsBindingObserver {
final Completer<PDFViewController> _controller =
Completer<PDFViewController>();
int pages = 0;
int currentPage = 0;
bool isReady = false;
String errorMessage = '';
bool _isLoading = true;
void initState() {
super.initState();
download();
}
File file;
Future<void> download() async {
try {
File f = await PdfCacheMgr.pdfs.getSingleFile(widget.url);
setState(() {
file = f;
});
} catch (e) {
showMsgDialog(context, "Error", e.toString());
} finally {
setState(() {
_isLoading = false;
});
}
}
@override
Widget build(BuildContext context) {
return LocalProgress(
inAsyncCall: _isLoading,
child: Scaffold(
appBar: AppBar(
centerTitle: true,
backgroundColor: Colors.white,
shadowColor: Colors.transparent,
title:
Text(widget.title ?? "", style: TextStyle(color: primaryColor)),
leading: new IconButton(
icon: new Icon(CupertinoIcons.back, color: primaryColor),
onPressed: () => Navigator.of(context).pop(),
),
actions: <Widget>[
IconButton(
icon: Icon(
Icons.share,
color: primaryColor,
),
onPressed: _share,
),
],
),
body: Stack(
children: <Widget>[
_isLoading
? Container()
: PDFView(
filePath: file?.path ?? "",
enableSwipe: true,
swipeHorizontal: true,
autoSpacing: false,
pageFling: true,
pageSnap: true,
defaultPage: currentPage,
fitPolicy: FitPolicy.BOTH,
preventLinkNavigation:
false, // if set to true the link is handled in flutter
onRender: (_pages) {
print(('pages => $pages'));
setState(() {
pages = _pages;
isReady = true;
});
},
onViewCreated: (PDFViewController pdfViewController) {
_controller.complete(pdfViewController);
},
onLinkHandler: (String uri) {
print('goto uri: $uri');
},
onPageChanged: (int page, int total) {
print('page change: $page/$total');
setState(() {
currentPage = page;
});
},
),
],
),
),
);
}
_share() async {
final RenderBox box = context.findRenderObject();
await Share.shareFiles([file.path],
mimeTypes: ["application/pdf"],
subject: "File",
sharePositionOrigin: box.localToGlobal(Offset.zero) & box.size);
}
}

View File

@@ -1,6 +1,7 @@
import 'dart:io';
import 'package:fcs/helpers/theme.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:photo_view/photo_view.dart';
@@ -21,12 +22,19 @@ class _ShowImageState extends State<ShowImage> {
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
leading: new IconButton(
icon: new Icon(Icons.close),
onPressed: () => Navigator.of(context).pop(),
),
backgroundColor: primaryColor,
title: Text(widget.fileName, style: TextStyle(color: Colors.white)),
shadowColor: Colors.transparent,
iconTheme: new IconThemeData(color: Colors.white),
),
body: Center(
child: PhotoView(
backgroundDecoration: const BoxDecoration(
color: primaryColor,
),
imageProvider: widget.url != null
? NetworkImage(widget.url)
: widget.imageFile != null