diff --git a/lib/Utils/methods.dart b/lib/Utils/methods.dart index 547993e..db0885b 100644 --- a/lib/Utils/methods.dart +++ b/lib/Utils/methods.dart @@ -1,4 +1,5 @@ import 'dart:io'; +import 'package:fluttertoast/fluttertoast.dart'; import 'package:pdf/pdf.dart'; import 'package:get/get.dart'; import 'package:pdf/widgets.dart'; @@ -43,6 +44,10 @@ Future cropImage(String imagepath, Function(String) onCrop) async { } } +void showToast(String msg) { + Fluttertoast.showToast(msg: msg, gravity: ToastGravity.BOTTOM); +} + void exportPdf(List images) { final Document pdf = Document(); final filesToImages = images diff --git a/lib/controllers/images_to_pdf.dart b/lib/controllers/images_to_pdf.dart index c75e15b..0169001 100644 --- a/lib/controllers/images_to_pdf.dart +++ b/lib/controllers/images_to_pdf.dart @@ -1,4 +1,5 @@ import 'dart:io'; +import 'package:fluttertoast/fluttertoast.dart'; import 'package:get/get.dart'; import 'package:EasyScan/Utils/methods.dart'; import 'package:image_picker/image_picker.dart'; @@ -27,4 +28,7 @@ class ImageToPdfController extends GetxController { } void removeImage(int index) => _images.removeAt(index); + void showToast(String msg) { + Fluttertoast.showToast(msg: msg, gravity: ToastGravity.BOTTOM); + } } diff --git a/lib/controllers/pdf.dart b/lib/controllers/pdf.dart index 45876df..efdfb9e 100644 --- a/lib/controllers/pdf.dart +++ b/lib/controllers/pdf.dart @@ -7,6 +7,7 @@ import 'package:EasyScan/Utils/constants.dart'; import 'package:EasyScan/widgets/history_card.dart'; import 'package:EasyScan/Utils/permission_checker.dart'; import 'package:native_pdf_renderer/native_pdf_renderer.dart'; +import 'package:share/share.dart'; class PdfController extends GetxController { final _isFilesChecked = false.obs; @@ -42,6 +43,19 @@ class PdfController extends GetxController { } } + void share({int index}) { + Share.shareFiles([fileSystemEntitys[index].path], text: 'mypdf'); + } + + Future deleteFile(int index) async { + try { + final file = dd.File(fileSystemEntitys[index].path); + file.delete(recursive: false); + } catch (e) { + //error will be here + } + } + Future _makeWidgetList() async { _pdfWidgets = []; for (final dd.FileSystemEntity file in fileSystemEntitys) { diff --git a/lib/screens/history.dart b/lib/screens/history.dart index cba18e9..c90ae60 100644 --- a/lib/screens/history.dart +++ b/lib/screens/history.dart @@ -1,3 +1,7 @@ +import 'package:EasyScan/Utils/constants.dart'; +import 'package:EasyScan/Utils/methods.dart'; +import 'package:EasyScan/screens/home.dart'; +import 'package:EasyScan/widgets/sharedel_dialogue.dart'; import 'package:get/get.dart'; import 'package:flutter/material.dart'; import 'package:open_file/open_file.dart'; @@ -33,6 +37,39 @@ class SavedPdfScreen extends StatelessWidget { crossAxisCount: 2, crossAxisSpacing: 4, mainAxisSpacing: 4), itemBuilder: (_, i) { return GestureDetector( + onLongPress: () { + showDialog( + context: _, + child: SimpleDialog( + title: const Text("What do you want to do ?"), + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(20)), + children: [ + SimpleDialogOption( + onPressed: () { + _savedPdfController.share(index: i); + }, + child: const ShareDelOption( + color: primaryColor, + title: "Share", + iconData: Icons.share, + ), + ), + SimpleDialogOption( + onPressed: () { + _savedPdfController.refreshFiles(); + _savedPdfController.deleteFile(i); + showToast("Pdf has been deleted"); + Get.to(HomeScreen()); + }, + child: const ShareDelOption( + color: Colors.red, + title: "Delete", + iconData: Icons.delete_outline_sharp), + ) + ], + )); + }, onTap: () => OpenFile.open(_fileSystemEntitys[i].path), child: pdfs[i]); }, diff --git a/lib/screens/images_to_pdf.dart b/lib/screens/images_to_pdf.dart index ad196b1..b65ee27 100644 --- a/lib/screens/images_to_pdf.dart +++ b/lib/screens/images_to_pdf.dart @@ -1,3 +1,5 @@ +import 'package:EasyScan/Utils/methods.dart'; +import 'package:EasyScan/screens/home.dart'; import 'package:get/get.dart'; import 'package:flutter/material.dart'; import 'package:EasyScan/Utils/constants.dart'; @@ -17,7 +19,11 @@ class ImageToPdf extends StatelessWidget { padding: const EdgeInsets.symmetric(horizontal: 4), child: FloatingActionButton.extended( heroTag: 'export', - onPressed: _imageToPdfController.exportToPdf, + onPressed: () { + _imageToPdfController.exportToPdf(); + showToast("Pdf has been created"); + Get.to(HomeScreen()); + }, icon: const Icon(Icons.upload_file), label: const Text('Export'), backgroundColor: Colors.green, diff --git a/lib/widgets/sharedel_dialogue.dart b/lib/widgets/sharedel_dialogue.dart new file mode 100644 index 0000000..bdd7993 --- /dev/null +++ b/lib/widgets/sharedel_dialogue.dart @@ -0,0 +1,26 @@ +import 'package:flutter/material.dart'; + +class ShareDelOption extends StatelessWidget { + final IconData iconData; + final String title; + final Color color; + const ShareDelOption({Key key, this.iconData, this.title, this.color}) + : super(key: key); + + @override + Widget build(BuildContext context) { + return Row( + mainAxisSize: MainAxisSize.min, + children: [ + Icon( + iconData, + color: color, + ), + const SizedBox( + width: 20, + ), + Text(title) + ], + ); + } +} diff --git a/pubspec.lock b/pubspec.lock index e830920..fd7e54b 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -102,6 +102,13 @@ packages: description: flutter source: sdk version: "0.0.0" + fluttertoast: + dependency: "direct main" + description: + name: fluttertoast + url: "https://pub.dartlang.org" + source: hosted + version: "7.1.1" get: dependency: "direct main" description: @@ -186,6 +193,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.3.0-nullsafety.3" + mime: + dependency: transitive + description: + name: mime + url: "https://pub.dartlang.org" + source: hosted + version: "0.9.7" native_pdf_renderer: dependency: "direct main" description: @@ -305,6 +319,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.3.0" + share: + dependency: "direct main" + description: + name: share + url: "https://pub.dartlang.org" + source: hosted + version: "0.6.5+3" sky_engine: dependency: transitive description: flutter diff --git a/pubspec.yaml b/pubspec.yaml index 9c703a5..4882451 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -18,7 +18,9 @@ dependencies: image_picker: ^0.6.7+4 native_pdf_renderer: ^2.3.2 permission_handler: ^5.0.1+1 - flutter_image_editor: ^1.2.0 + flutter_image_editor: ^1.2.0 + share: ^0.6.5+2 + fluttertoast: ^7.1.1 dev_dependencies: