Fix most of the issues && add more additional fixes

pull/1419/head
Ahmed Hnewa 2 years ago
parent 4069185476
commit a0c5186cad
No known key found for this signature in database
GPG Key ID: C488CC70BBCEF0D1
  1. 6
      flutter_quill_extensions/CHANGELOG.md
  2. 4
      flutter_quill_extensions/lib/embeds/builders.dart
  3. 6
      flutter_quill_extensions/lib/embeds/embed_types.dart
  4. 2
      flutter_quill_extensions/lib/embeds/toolbar/image_video_utils.dart
  5. 1
      flutter_quill_extensions/lib/embeds/toolbar/media_button.dart
  6. 2
      flutter_quill_extensions/lib/embeds/utils.dart
  7. 6
      flutter_quill_extensions/lib/embeds/widgets/image.dart
  8. 2
      flutter_quill_extensions/lib/embeds/widgets/video_app.dart
  9. 7
      flutter_quill_extensions/lib/flutter_quill_extensions.dart
  10. 2
      flutter_quill_extensions/lib/shims/dart_ui_real.dart
  11. 29
      flutter_quill_extensions/lib/utils/quill_utils.dart
  12. 4
      flutter_quill_extensions/pubspec.yaml

@ -1,3 +1,9 @@
## 0.5.1
- Fix "The platformViewRegistry getter is deprecated and will be removed in a future release. Please import it from dart:ui_web instead."
- Add QuillImageUtilities class
- Small improvemenets
- Allow to use the mobile context menu on desktop by force using it
## 0.5.0
- Migrated from `gallery_saver` to `gal` for saving images
- Added callbacks for greater control of editing images

@ -25,8 +25,8 @@ class ImageEmbedBuilder extends EmbedBuilder {
this.shouldRemoveImageCallback,
this.forceUseMobileOptionMenu = false,
});
final ImageEmbedBuilderWillRemoveCallback? onImageRemovedCallback;
final ImageEmbedBuilderOnRemovedCallback? shouldRemoveImageCallback;
final ImageEmbedBuilderOnRemovedCallback? onImageRemovedCallback;
final ImageEmbedBuilderWillRemoveCallback? shouldRemoveImageCallback;
final bool forceUseMobileOptionMenu;
@override

@ -1,4 +1,4 @@
import 'dart:io';
import 'dart:io' show File;
import 'dart:typed_data';
import 'package:flutter/material.dart';
@ -45,10 +45,10 @@ class QuillFile {
final Uint8List bytes;
}
typedef ImageEmbedBuilderWillRemoveCallback = Future<void> Function(
typedef ImageEmbedBuilderWillRemoveCallback = Future<bool> Function(
File imageFile,
);
typedef ImageEmbedBuilderOnRemovedCallback = Future<bool> Function(
typedef ImageEmbedBuilderOnRemovedCallback = Future<void> Function(
File imageFile,
);

@ -1,4 +1,4 @@
import 'dart:io';
import 'dart:io' show File;
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';

@ -1,4 +1,3 @@
//import 'dart:io';
import 'dart:math' as math;
import 'dart:ui';

@ -1,4 +1,4 @@
import 'dart:io';
import 'dart:io' show File;
import 'package:flutter/foundation.dart' show Uint8List;
import 'package:gal/gal.dart';

@ -1,5 +1,5 @@
import 'dart:convert';
import 'dart:io' as io;
import 'dart:io' show File;
import 'package:flutter/material.dart';
import 'package:flutter_quill/flutter_quill.dart';
@ -40,7 +40,7 @@ Image imageByUrl(String imageUrl,
return Image.network(imageUrl,
width: width, height: height, alignment: alignment);
}
return Image.file(io.File(imageUrl),
return Image.file(File(imageUrl),
width: width, height: height, alignment: alignment);
}
@ -82,7 +82,7 @@ class ImageTapWrapper extends StatelessWidget {
return NetworkImage(imageUrl);
}
return FileImage(io.File(imageUrl));
return FileImage(File(imageUrl));
}
@override

@ -1,4 +1,4 @@
import 'dart:io';
import 'dart:io' show File;
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';

@ -80,7 +80,8 @@ class FlutterQuillEmbeds {
/// [forceUseMobileOptionMenuForImageClick] is a boolean
/// flag that, when set to `true`,
/// enforces the use of the mobile-specific option menu for image clicks in
/// other platforms like web and desktop, this option doesn't affect mobile.
/// other platforms like desktop, this option doesn't affect mobile. it will
/// not affect web
/// This option
/// can be used to override the default behavior based on the platform.
///
@ -104,8 +105,8 @@ class FlutterQuillEmbeds {
/// ```
static List<EmbedBuilder> builders({
void Function(GlobalKey videoContainerKey)? onVideoInit,
ImageEmbedBuilderWillRemoveCallback? onImageRemovedCallback,
ImageEmbedBuilderOnRemovedCallback? shouldRemoveImageCallback,
ImageEmbedBuilderOnRemovedCallback? onImageRemovedCallback,
ImageEmbedBuilderWillRemoveCallback? shouldRemoveImageCallback,
bool forceUseMobileOptionMenuForImageClick = false,
}) =>
[

@ -1 +1 @@
export 'dart:ui';
export 'dart:ui' if (dart.library.html) 'dart:ui_web';

@ -9,10 +9,20 @@ import '../flutter_quill_extensions.dart';
class QuillImageUtilities {
const QuillImageUtilities._();
static void _webIsNotSupported(String functionName) {
if (kIsWeb) {
throw UnsupportedError(
'The static function $functionName()'
' on QuillImageUtilities is not supported in Web',
);
}
}
/// Saves a list of images to a specified directory.
///
/// This function is designed to work efficiently on
/// mobile platforms, but it can also be used on other platforms.
/// But it's not supported on web for now
///
/// When you have a list of cached image paths
/// from a Quill document and you want to save them,
@ -29,6 +39,9 @@ class QuillImageUtilities {
/// [deleteThePreviousImages]: Indicates whether to delete the
/// original cached images after copying.
/// [saveDirectory]: The directory where the images will be saved.
/// [startOfEachFile]: Each file will have a name and it need to be unique
/// but to make the file name is clear we will need a string represent
/// the start of each file
///
/// Returns a list of paths to the newly saved images.
/// For images that do not exist, their paths are returned as empty strings.
@ -40,13 +53,16 @@ class QuillImageUtilities {
/// images: cachedImagePaths,
/// deleteThePreviousImages: true,
/// saveDirectory: documentsDir,
/// startOfEachFile: 'quill-image-', // default
/// );
/// ```
static Future<List<String>> saveImagesToDirectory({
required Iterable<String> images,
required deleteThePreviousImages,
required Directory saveDirectory,
String startOfEachFile = 'quill-image-',
}) async {
_webIsNotSupported('saveImagesToDirectory');
final newImagesFutures = images.map((cachedImagePath) async {
final previousImageFile = File(cachedImagePath);
final isPreviousImageFileExists = await previousImageFile.exists();
@ -61,7 +77,7 @@ class QuillImageUtilities {
// TODO: You might want to make it easier for the developer to change
// the newImageFileName, but he can rename it anyway
final newImageFileName =
'quill-image-$dateTimeAsString$newImageFileExtensionWithDot';
'$startOfEachFile$dateTimeAsString$newImageFileExtensionWithDot';
final newImagePath = path.join(saveDirectory.path, newImageFileName);
final newImageFile = await previousImageFile.copy(newImagePath);
if (deleteThePreviousImages) {
@ -75,6 +91,7 @@ class QuillImageUtilities {
}
/// Deletes all local images referenced in a Quill document.
/// it's not supported on web for now
///
/// This function removes local images from the
/// file system that are referenced in the provided [document].
@ -94,6 +111,7 @@ class QuillImageUtilities {
static Future<void> deleteAllLocalImagesOfDocument(
quill.Document document,
) async {
_webIsNotSupported('deleteAllLocalImagesOfDocument');
final imagesPaths = getImagesPathsFromDocument(
document,
onlyLocalImages: true,
@ -116,11 +134,12 @@ class QuillImageUtilities {
/// Retrieves paths to images embedded in a Quill document.
///
/// it's not supported on web for now.
/// This function parses the [document] and returns a list of image paths.
///
/// [document]: The Quill document from which image paths will be retrieved.
/// [onlyLocalImages]: If `true`,
/// only local (non-web) image paths will be included.
/// only local (non-web-url) image paths will be included.
///
/// Returns an iterable of image paths.
///
@ -138,6 +157,7 @@ class QuillImageUtilities {
quill.Document document, {
required bool onlyLocalImages,
}) {
_webIsNotSupported('getImagesPathsFromDocument');
final images = document.root.children
.whereType<quill.Line>()
.where((node) {
@ -167,6 +187,7 @@ class QuillImageUtilities {
}
/// Determines if an image file is cached based on the platform.
/// it's not supported on web for now
///
/// On mobile platforms (Android and iOS), images are typically
/// cached in temporary directories.
@ -178,6 +199,7 @@ class QuillImageUtilities {
/// Returns `true` if the image is cached, `false` otherwise.
/// On other platforms it will always return false
static bool isImageCached(String imagePath) {
_webIsNotSupported('isImageCached');
// Determine if the image path is a cached path based on platform
if (kIsWeb) {
// For now this will not work for web
@ -199,6 +221,8 @@ class QuillImageUtilities {
/// Retrieves cached image paths from a Quill document,
/// primarily for mobile platforms.
///
/// it's not supported on web for now
///
/// This function scans a Quill document to identify
/// and return paths to locally cached images.
/// It is specifically designed for mobile
@ -217,6 +241,7 @@ class QuillImageUtilities {
quill.Document document, {
String? replaceUnexistentImagesWith,
}) async {
_webIsNotSupported('getCachedImagePathsFromDocument');
final imagePaths = getImagesPathsFromDocument(
document,
onlyLocalImages: true,

@ -1,6 +1,6 @@
name: flutter_quill_extensions
description: Embed extensions for flutter_quill including image, video, formula and etc.
version: 0.4.1
version: 0.5.0
homepage: https://bulletjournal.us/home/index.html
repository: https://github.com/singerdmx/flutter-quill/tree/master/flutter_quill_extensions
@ -22,7 +22,7 @@ dependencies:
math_keyboard: ">=0.2.1"
universal_html: ^2.2.4
gal: ^2.1.1
gal: ^2.1.2
dev_dependencies:
flutter_test:

Loading…
Cancel
Save