Fix my issues and changes (#1417)

* Add a event that triggers after removing the image from the editor && delete unused dependencies and upgrade all packages and plugins and remove gallery_saver which has not been updated for more than 23 months, it was a great plugin but it old now, and I also add some simple documentation and other minor improvements

* I have add a documentation comments to flutter_quill_extensions, add new event to allow the user to confirm removing the image before actually remove it, translated some text in Arabic languague since it was incorrect or missing

* Fix analyzer error

* Switch back to gal and more changes

* Remove required parameters
pull/1421/head
Ahmed Hnewa 2 years ago committed by GitHub
parent ff381e6e07
commit 9fcd0a7e7a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 27
      flutter_quill_extensions/lib/embeds/builders.dart
  2. 17
      flutter_quill_extensions/lib/embeds/utils.dart
  3. 17
      flutter_quill_extensions/lib/flutter_quill_extensions.dart
  4. 2
      flutter_quill_extensions/pubspec.yaml

@ -11,8 +11,7 @@ import 'package:math_keyboard/math_keyboard.dart';
import 'package:universal_html/html.dart' as html;
import '../shims/dart_ui_fake.dart'
if (dart.library.html) 'package:flutter_quill_extensions/shims/dart_ui_real.dart'
as ui;
if (dart.library.html) '../shims/dart_ui_real.dart' as ui;
import 'embed_types.dart';
import 'utils.dart';
import 'widgets/image.dart';
@ -22,11 +21,11 @@ import 'widgets/youtube_video_app.dart';
class ImageEmbedBuilder extends EmbedBuilder {
ImageEmbedBuilder({
required this.afterRemoveImageFromEditor,
required this.shouldRemoveImageFromEditor,
this.afterRemoveImageFromEditor,
this.shouldRemoveImageFromEditor,
});
final ImageEmbedBuilderAfterRemoveImageFromEditor afterRemoveImageFromEditor;
final ImageEmbedBuilderShouldRemoveImageFromEditor
final ImageEmbedBuilderAfterRemoveImageFromEditor? afterRemoveImageFromEditor;
final ImageEmbedBuilderShouldRemoveImageFromEditor?
shouldRemoveImageFromEditor;
@override
@ -136,8 +135,15 @@ class ImageEmbedBuilder extends EmbedBuilder {
Navigator.of(context).pop();
final imageFile = File(imageUrl);
final shouldRemoveImage =
await shouldRemoveImageFromEditor(imageFile);
final shouldRemoveImageEvent = shouldRemoveImageFromEditor;
var shouldRemoveImage = true;
if (shouldRemoveImageEvent != null) {
shouldRemoveImage = await shouldRemoveImageEvent(
imageFile,
);
}
if (!shouldRemoveImage) {
return;
@ -152,7 +158,10 @@ class ImageEmbedBuilder extends EmbedBuilder {
'',
TextSelection.collapsed(offset: offset),
);
await afterRemoveImageFromEditor(imageFile);
final afterRemoveImageEvent = afterRemoveImageFromEditor;
if (afterRemoveImageEvent != null) {
await afterRemoveImageEvent(imageFile);
}
},
);
return Padding(

@ -1,8 +1,8 @@
import 'dart:io';
import 'package:flutter/foundation.dart' show Uint8List;
import 'package:gal/gal.dart';
import 'package:http/http.dart' as http;
import 'package:image_gallery_saver/image_gallery_saver.dart';
// I would like to orgnize the project structure and the code more
// but here I don't want to change too much since that is a community project
@ -30,7 +30,11 @@ class _SaveImageResult {
Future<_SaveImageResult> saveImage(String imageUrl) async {
final imageFile = File(imageUrl);
final hasPermission = await Gal.hasAccess();
final imageExistsLocally = await imageFile.exists();
if (!hasPermission) {
await Gal.requestAccess();
}
if (!imageExistsLocally) {
final success = await _saveNetworkImageToLocal(imageUrl);
return _SaveImageResult(
@ -54,10 +58,8 @@ Future<bool> _saveNetworkImageToLocal(String imageUrl) async {
return false;
}
final imageBytes = response.bodyBytes;
final result = await ImageGallerySaver.saveImage(
Uint8List.fromList(imageBytes),
);
return result['isSuccess'];
await Gal.putImageBytes(imageBytes);
return true;
} catch (e) {
return false;
}
@ -75,9 +77,8 @@ Future<Uint8List> _convertFileToUint8List(File file) async {
Future<bool> _saveImageLocally(File imageFile) async {
try {
final imageBytes = await _convertFileToUint8List(imageFile);
final result = await ImageGallerySaver.saveImage(imageBytes);
return result['isSuccess'];
await Gal.putImageBytes(imageBytes);
return true;
} catch (e) {
return false;
}

@ -72,21 +72,8 @@ class FlutterQuillEmbeds {
}) =>
[
ImageEmbedBuilder(
afterRemoveImageFromEditor: afterRemoveImageFromEditor ??
(imageFile) async {
// TODO: Change the default event if you want to
final fileExists = await imageFile.exists();
if (fileExists) {
await imageFile.delete();
}
},
shouldRemoveImageFromEditor: shouldRemoveImageFromEditor ??
(imageFile) {
// TODO: Before pubish the changes
// please consider change the name
// of the events if you want to
return Future.value(true);
},
afterRemoveImageFromEditor: afterRemoveImageFromEditor,
shouldRemoveImageFromEditor: shouldRemoveImageFromEditor,
),
VideoEmbedBuilder(onVideoInit: onVideoInit),
FormulaEmbedBuilder(),

@ -26,7 +26,7 @@ dependencies:
# url_launcher: ^6.1.14
# dio: ^5.3.3
image_gallery_saver: ^2.0.3
gal: ^2.1.1
dev_dependencies:
flutter_test:

Loading…
Cancel
Save