Skip to content
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

Open
wants to merge 5 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/Utils/methods.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -43,6 +44,10 @@ Future cropImage(String imagepath, Function(String) onCrop) async {
}
}

void showToast(String msg) {
Fluttertoast.showToast(msg: msg, gravity: ToastGravity.BOTTOM);
Copy link
Collaborator

@cimplesid cimplesid Oct 15, 2020

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

}

void exportPdf(List<File> images) {
final Document pdf = Document();
final filesToImages = images
Expand Down
4 changes: 4 additions & 0 deletions lib/controllers/images_to_pdf.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'dart:io';
import 'package:fluttertoast/fluttertoast.dart';
Copy link
Collaborator

Choose a reason for hiding this comment

The 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';
Expand Down Expand Up @@ -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);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

toast to get

}
}
14 changes: 14 additions & 0 deletions lib/controllers/pdf.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lader import


class PdfController extends GetxController {
final _isFilesChecked = false.obs;
Expand Down Expand Up @@ -42,6 +43,19 @@ class PdfController extends GetxController {
}
}

void share({int index}) {
Copy link
Collaborator

Choose a reason for hiding this comment

The 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
Copy link
Collaborator

Choose a reason for hiding this comment

The 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) {
Expand Down
37 changes: 37 additions & 0 deletions lib/screens/history.dart
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';
Expand Down Expand Up @@ -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());
Copy link
Collaborator

Choose a reason for hiding this comment

The 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]);
},
Expand Down
8 changes: 7 additions & 1 deletion lib/screens/images_to_pdf.dart
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';
Expand All @@ -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());
Copy link
Collaborator

Choose a reason for hiding this comment

The 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,
Expand Down
26 changes: 26 additions & 0 deletions lib/widgets/sharedel_dialogue.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import 'package:flutter/material.dart';

class ShareDelOption extends StatelessWidget {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

better naming like customRow or customDialogOption

final IconData iconData;
final String title;
final Color color;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

iconColor

const ShareDelOption({Key key, this.iconData, this.title, this.color})
Copy link
Collaborator

Choose a reason for hiding this comment

The 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(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

either user Icon as parameter or give default value to color

iconData,
color: color,
),
const SizedBox(
width: 20,
),
Text(title)
],
);
}
}
21 changes: 21 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down