-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Shareand delete #42
base: dev
Are you sure you want to change the base?
Shareand delete #42
Changes from 1 commit
96f33a5
69280cc
e2b7a11
17fa279
c34cd72
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import 'dart:io'; | ||
import 'package:fluttertoast/fluttertoast.dart'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. follow ladder import |
||
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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. toast to get |
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. lader import |
||
|
||
class PdfController extends GetxController { | ||
final _isFilesChecked = false.obs; | ||
|
@@ -42,6 +43,19 @@ class PdfController extends GetxController { | |
} | ||
} | ||
|
||
void share({int index}) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. make index required parameter remove curly |
||
Share.shareFiles([fileSystemEntitys[index].path], text: 'mypdf'); | ||
} | ||
|
||
Future<void> deleteFile(int index) async { | ||
try { | ||
final file = dd.File(fileSystemEntitys[index].path); | ||
file.delete(recursive: false); | ||
} catch (e) { | ||
//error will be here | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. refresh file |
||
} | ||
} | ||
|
||
Future<void> _makeWidgetList() async { | ||
_pdfWidgets = []; | ||
for (final dd.FileSystemEntity file in fileSystemEntitys) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. don't go back |
||
}, | ||
child: const ShareDelOption( | ||
color: Colors.red, | ||
title: "Delete", | ||
iconData: Icons.delete_outline_sharp), | ||
) | ||
], | ||
)); | ||
}, | ||
onTap: () => OpenFile.open(_fileSystemEntitys[i].path), | ||
child: pdfs[i]); | ||
}, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. don't navigate |
||
}, | ||
icon: const Icon(Icons.upload_file), | ||
label: const Text('Export'), | ||
backgroundColor: Colors.green, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import 'package:flutter/material.dart'; | ||
|
||
class ShareDelOption extends StatelessWidget { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. better naming like |
||
final IconData iconData; | ||
final String title; | ||
final Color color; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. iconColor |
||
const ShareDelOption({Key key, this.iconData, this.title, this.color}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. make iconData & title required |
||
: super(key: key); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Row( | ||
mainAxisSize: MainAxisSize.min, | ||
children: [ | ||
Icon( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. either user |
||
iconData, | ||
color: color, | ||
), | ||
const SizedBox( | ||
width: 20, | ||
), | ||
Text(title) | ||
], | ||
); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Get.showSnackbar()
use this remove fluttertoast