dartlangeditorflutterflutter-appsflutter-examplesflutter-packageflutter-widgetquillquill-deltaquilljsreactquillrich-textrich-text-editorwysiwygwysiwyg-editor
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
108 lines
3.9 KiB
108 lines
3.9 KiB
1 year ago
|
import 'package:flutter/widgets.dart' show BuildContext;
|
||
|
import 'package:flutter_quill/flutter_quill.dart';
|
||
|
import 'package:meta/meta.dart' show immutable;
|
||
|
|
||
|
import '../../services/image_picker/s_image_picker.dart';
|
||
|
import '../../services/image_saver/s_image_saver.dart';
|
||
|
|
||
1 year ago
|
/// Configurations for Flutter Quill Extensions
|
||
|
/// that is shared between the toolbar and editor for the extensions package
|
||
|
///
|
||
|
/// Example on how to setup it:
|
||
|
///
|
||
|
/// ```dart
|
||
|
/// QuillProvider(
|
||
|
/// configurations: QuillConfigurations(
|
||
|
/// sharedConfigurations: const QuillSharedConfigurations(
|
||
|
/// extraConfigurations: {
|
||
|
/// QuillSharedExtensionsConfigurations.key:
|
||
|
/// QuillSharedExtensionsConfigurations(
|
||
|
/// // Feel free to explore it
|
||
|
/// ),
|
||
|
/// },
|
||
|
/// ),
|
||
|
/// controller: _controller,
|
||
|
/// ),
|
||
|
/// child: const Column(
|
||
|
/// children: [
|
||
|
/// // QuillToolbar
|
||
|
/// // QuillEditor
|
||
|
/// // ...
|
||
|
/// ],
|
||
|
// ),
|
||
|
/// )
|
||
|
/// ```
|
||
1 year ago
|
///
|
||
1 year ago
|
@immutable
|
||
|
class QuillSharedExtensionsConfigurations {
|
||
|
const QuillSharedExtensionsConfigurations({
|
||
|
ImagePickerService? imagePickerService,
|
||
|
ImageSaverService? imageSaverService,
|
||
1 year ago
|
this.assetsPrefix = 'assets',
|
||
1 year ago
|
}) : _imagePickerService = imagePickerService,
|
||
|
_imageSaverService = imageSaverService;
|
||
|
|
||
|
/// Get the instance from the widget tree in [QuillSharedConfigurations]
|
||
|
/// if it doesn't exists, we will create new one with default options
|
||
|
factory QuillSharedExtensionsConfigurations.get({
|
||
|
required BuildContext context,
|
||
|
}) {
|
||
|
final quillSharedExtensionsConfigurations =
|
||
|
context.requireQuillSharedConfigurations.extraConfigurations[key];
|
||
|
if (quillSharedExtensionsConfigurations != null) {
|
||
|
if (quillSharedExtensionsConfigurations
|
||
|
is! QuillSharedExtensionsConfigurations) {
|
||
|
throw ArgumentError(
|
||
|
'The value of key `$key` should be of type '
|
||
|
'QuillSharedExtensionsConfigurations',
|
||
|
);
|
||
|
}
|
||
|
return quillSharedExtensionsConfigurations;
|
||
|
}
|
||
|
return const QuillSharedExtensionsConfigurations();
|
||
|
}
|
||
|
|
||
1 year ago
|
/// The key to be used in the `extraConfigurations` property
|
||
|
/// which can be found in the [QuillSharedConfigurations]
|
||
|
/// which lives in the [QuillConfigurations]
|
||
|
///
|
||
|
/// which exists in the [QuillProvider]
|
||
1 year ago
|
static const String key = 'quillSharedExtensionsConfigurations';
|
||
|
|
||
1 year ago
|
/// Defaults to [ImagePickerService.defaultImpl]
|
||
1 year ago
|
final ImagePickerService? _imagePickerService;
|
||
|
|
||
1 year ago
|
/// A getter method which returns the [ImagePickerService] that is provided
|
||
|
/// by the developer, if it can't be found then we will use default impl
|
||
1 year ago
|
ImagePickerService get imagePickerService {
|
||
|
return _imagePickerService ?? ImagePickerService.defaultImpl();
|
||
|
}
|
||
|
|
||
|
/// Default to [ImageSaverService.defaultImpl]
|
||
|
final ImageSaverService? _imageSaverService;
|
||
|
|
||
1 year ago
|
/// A getter method which returns the [ImageSaverService] that is provided
|
||
|
/// by the developer, if it can't be found then we will use default impl
|
||
1 year ago
|
ImageSaverService get imageSaverService {
|
||
|
return _imageSaverService ?? ImageSaverService.defaultImpl();
|
||
|
}
|
||
1 year ago
|
|
||
|
/// The property [assetsPrefix] should be the start of your assets folder
|
||
|
/// by default it to `assets` and the reason why we need to know it
|
||
|
///
|
||
|
/// Because in case when you don't define a value for [ImageProviderBuilder]
|
||
|
/// in the [QuillEditorImageEmbedConfigurations] which exists in
|
||
|
/// [FlutterQuillEmbeds.editorBuilders]
|
||
|
///
|
||
|
/// then the only way of how to know if this is asset image that you added
|
||
|
/// in the `pubspec.yaml` is by asking you the assetsPrefix, how should the
|
||
|
/// start of your asset images usualy looks like?? in most projects it's
|
||
|
/// assets so we will go with that as a default
|
||
|
///
|
||
|
/// but if you are using different name and you want to use assets images
|
||
|
/// in the [QuillEditor] then it's important to override this
|
||
|
///
|
||
|
/// if you want a custom solution then please use [imageProviderBuilder]
|
||
|
final String assetsPrefix;
|
||
1 year ago
|
}
|