Skip to content

Commit

Permalink
Bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Ellet committed Dec 6, 2023
1 parent ec2d28c commit 5e6115d
Show file tree
Hide file tree
Showing 15 changed files with 52 additions and 41 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ All notable changes to this project will be documented in this file.

## 9.0.0-dev-6
* Move the `child` from `QuillToolbarConfigurations` into `QuillToolbar` directly
* Bug fixes
* Flutter Quill Extensions:
* **Breaking Change**: The `imageProviderBuilder`is now providing the context and image url

## 9.0.0-dev-5
* The `QuillToolbar` is now accepting only `child` with no configurations so you can customize everything you wants, the `QuillToolbar.simple()` or `QuillSimpleToolbar` implements a simple toolbar that is based on `QuillToolbar`, you are free to use it but it just an example and not standard
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,6 @@ class MyQuillEditor extends StatelessWidget {
scrollController: scrollController,
focusNode: focusNode,
configurations: configurations.copyWith(
extraConfigurations: {
QuillEditorExtensionsConfigurations.key:
const QuillEditorExtensionsConfigurations(
assetsPrefix: 'dsadsasda', // Defaults to assets
),
},
customStyles: const DefaultStyles(
h1: DefaultTextBlockStyle(
TextStyle(
Expand Down Expand Up @@ -88,7 +82,7 @@ class MyQuillEditor extends StatelessWidget {
'Error while loading an image: ${error.toString()}',
);
},
imageProviderBuilder: (imageUrl) {
imageProviderBuilder: (context, imageUrl) {
// cached_network_image is supported
// only for Android, iOS and web

Expand All @@ -105,7 +99,8 @@ class MyQuillEditor extends StatelessWidget {
return getImageProviderByImageSource(
imageUrl,
imageProviderBuilder: null,
assetsPrefix: QuillEditorExtensionsConfigurations.get(
context: context,
assetsPrefix: QuillSharedExtensionsConfigurations.get(
context: context)
.assetsPrefix,
);
Expand Down
16 changes: 11 additions & 5 deletions example/lib/presentation/quill/quill_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ import 'dart:convert' show jsonEncode;
import 'package:flutter/material.dart';
import 'package:flutter_quill/flutter_quill.dart';
import 'package:flutter_quill_extensions/flutter_quill_extensions.dart'
show FlutterQuillEmbeds;
show FlutterQuillEmbeds, QuillSharedExtensionsConfigurations;

import 'package:quill_html_converter/quill_html_converter.dart';
import 'package:share_plus/share_plus.dart' show Share;

import '../extensions/scaffold_messenger.dart';
import '../shared/widgets/home_screen_button.dart';
import 'quill_editor.dart';
import 'quill_toolbar.dart';
import 'my_quill_editor.dart';
import 'my_quill_toolbar.dart';

@immutable
class QuillScreenArgs {
Expand Down Expand Up @@ -133,7 +133,13 @@ class _QuillScreenState extends State<QuillScreen> {

QuillSharedConfigurations get _sharedConfigurations {
return const QuillSharedConfigurations(
// locale: Locale('en'),
);
// locale: Locale('en'),
extraConfigurations: {
QuillSharedExtensionsConfigurations.key:
QuillSharedExtensionsConfigurations(
assetsPrefix: 'assets', // Defaults to assets
),
},
);
}
}
16 changes: 9 additions & 7 deletions flutter_quill_extensions/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,17 +170,19 @@ This works for all platforms except Web
If you want to use image assets in the Quill Editor, you need to make sure your assets folder is `assets` otherwise:

```dart
QuillEditor.basic(
configurations: const QuillEditorConfigurations(
// ...
QuillEditor.basic(
configurations: const QuillEditorConfigurations(
// ...
sharedConfigurations: QuillSharedConfigurations(
extraConfigurations: {
QuillEditorExtensionsConfigurations.key:
QuillEditorExtensionsConfigurations(
assetsPrefix: 'your-assets-folder-name', // Defaults to assets
QuillSharedExtensionsConfigurations.key:
QuillSharedExtensionsConfigurations(
assetsPrefix: 'your-assets-folder-name', // Defaults to `assets`
),
},
),
)
),
);
```

This info is needed by the package to check if it asset image to use the `AssetImage` provider
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,19 @@ class QuillEditorImageEmbedBuilder extends EmbedBuilder {
final height = imageSize.height;

final image = getImageWidgetByImageSource(
context: context,
imageSource,
imageProviderBuilder: configurations.imageProviderBuilder,
imageErrorWidgetBuilder: configurations.imageErrorWidgetBuilder,
alignment: alignment,
height: height,
width: width,
assetsPrefix: QuillEditorExtensionsConfigurations.get(context: context)
assetsPrefix: QuillSharedExtensionsConfigurations.get(context: context)
.assetsPrefix,
);

final imageSaverService =
QuillEditorExtensionsConfigurations.get(context: context)
QuillSharedExtensionsConfigurations.get(context: context)
.imageSaverService;
return GestureDetector(
onTap: configurations.onImageClicked ??
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ typedef ImageEmbedBuilderOnRemovedCallback = Future<void> Function(
);

typedef ImageEmbedBuilderProviderBuilder = ImageProvider Function(
BuildContext context,
String imageUrl,
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ class ImageOptionsMenu extends StatelessWidget {
MaterialPageRoute(
builder: (_) => ImageTapWrapper(
assetsPrefix:
QuillEditorExtensionsConfigurations.get(context: context)
QuillSharedExtensionsConfigurations.get(context: context)
.assetsPrefix,
imageUrl: imageSource,
configurations: configurations,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class QuillToolbarImageButton extends StatelessWidget {

Future<void> _onPressedHandler(BuildContext context) async {
final imagePickerService =
QuillEditorExtensionsConfigurations.get(context: context)
QuillSharedExtensionsConfigurations.get(context: context)
.imagePickerService;

final onRequestPickImage =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ class QuillToolbarCameraButton extends StatelessWidget {
QuillController controller,
) async {
final imagePickerService =
QuillEditorExtensionsConfigurations.get(context: context)
QuillSharedExtensionsConfigurations.get(context: context)
.imagePickerService;

final cameraAction = await _getCameraAction(context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ class QuillToolbarVideoButton extends StatelessWidget {

Future<void> _onPressedHandler(BuildContext context) async {
final imagePickerService =
QuillEditorExtensionsConfigurations.get(context: context)
QuillSharedExtensionsConfigurations.get(context: context)
.imagePickerService;

final onRequestPickVideo = options.videoConfigurations.onRequestPickVideo;
Expand Down
6 changes: 5 additions & 1 deletion flutter_quill_extensions/lib/embeds/widgets/image.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@ ImageProvider getImageProviderByImageSource(
String imageSource, {
required ImageEmbedBuilderProviderBuilder? imageProviderBuilder,
required String assetsPrefix,
required BuildContext context,
}) {
if (imageProviderBuilder != null) {
return imageProviderBuilder(imageSource);
return imageProviderBuilder(context, imageSource);
}

if (isImageBase64(imageSource)) {
Expand All @@ -57,6 +58,7 @@ ImageProvider getImageProviderByImageSource(

Image getImageWidgetByImageSource(
String imageSource, {
required BuildContext context,
required ImageEmbedBuilderProviderBuilder? imageProviderBuilder,
required ImageErrorWidgetBuilder? imageErrorWidgetBuilder,
required String assetsPrefix,
Expand All @@ -66,6 +68,7 @@ Image getImageWidgetByImageSource(
}) {
return Image(
image: getImageProviderByImageSource(
context: context,
imageSource,
imageProviderBuilder: imageProviderBuilder,
assetsPrefix: assetsPrefix,
Expand Down Expand Up @@ -126,6 +129,7 @@ class ImageTapWrapper extends StatelessWidget {
children: [
PhotoView(
imageProvider: getImageProviderByImageSource(
context: context,
imageUrl,
imageProviderBuilder: configurations.imageProviderBuilder,
assetsPrefix: assetsPrefix,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ import 'package:meta/meta.dart' show immutable;
import '../../services/image_picker/s_image_picker.dart';
import '../../services/image_saver/s_image_saver.dart';

/// Configurations for Flutter Quill Editor Extensions
/// Configurations for Flutter Editor Extensions
/// shared between toolbar and editor
@immutable
class QuillEditorExtensionsConfigurations {
const QuillEditorExtensionsConfigurations({
class QuillSharedExtensionsConfigurations {
const QuillSharedExtensionsConfigurations({
ImagePickerService? imagePickerService,
ImageSaverService? imageSaverService,
this.assetsPrefix = 'assets',
Expand All @@ -17,28 +18,28 @@ class QuillEditorExtensionsConfigurations {

/// Get the instance from the widget tree in [QuillSharedConfigurations]
/// if it doesn't exists, we will create new one with default options
factory QuillEditorExtensionsConfigurations.get({
factory QuillSharedExtensionsConfigurations.get({
required BuildContext context,
}) {
final value = context.quillEditorConfigurations?.extraConfigurations[key];
final value = context.quillSharedConfigurations?.extraConfigurations[key];
if (value != null) {
if (value is! QuillEditorExtensionsConfigurations) {
if (value is! QuillSharedExtensionsConfigurations) {
throw ArgumentError(
'The value of key `$key` should be of type '
'$key',
);
}
return value;
}
return const QuillEditorExtensionsConfigurations();
return const QuillSharedExtensionsConfigurations();
}

/// 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 [QuillEditorConfigurations]
static const String key = 'QuillEditorExtensionsConfigurations';
static const String key = 'QuillSharedExtensionsConfigurations';

/// Defaults to [ImagePickerService.defaultImpl]
final ImagePickerService? _imagePickerService;
Expand Down
6 changes: 0 additions & 6 deletions lib/src/models/config/editor/editor_configurations.dart
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,10 @@ class QuillEditorConfigurations extends Equatable {
this.builder,
this.magnifierConfiguration,
this.textInputAction = TextInputAction.newline,
this.extraConfigurations = const {},
});

final QuillSharedConfigurations sharedConfigurations;

/// Store custom configurations in here and use it in the widget tree
final Map<String, Object?> extraConfigurations;

final QuillController controller;

/// The text placeholder in the quill editor
Expand Down Expand Up @@ -343,7 +339,6 @@ class QuillEditorConfigurations extends Equatable {

QuillEditorConfigurations copyWith({
QuillSharedConfigurations? sharedConfigurations,
Map<String, Object?>? extraConfigurations,
QuillController? controller,
String? placeholder,
bool? readOnly,
Expand Down Expand Up @@ -391,7 +386,6 @@ class QuillEditorConfigurations extends Equatable {
}) {
return QuillEditorConfigurations(
sharedConfigurations: sharedConfigurations ?? this.sharedConfigurations,
extraConfigurations: extraConfigurations ?? this.extraConfigurations,
controller: controller ?? this.controller,
placeholder: placeholder ?? this.placeholder,
readOnly: readOnly ?? this.readOnly,
Expand Down
4 changes: 4 additions & 0 deletions lib/src/models/config/quill_shared_configurations.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class QuillSharedConfigurations extends Equatable {
this.dialogBarrierColor = Colors.black54,
this.dialogTheme,
this.locale,
this.extraConfigurations = const {},
});

// This is just example or showcase of this major update to make the library
Expand All @@ -33,6 +34,9 @@ class QuillSharedConfigurations extends Equatable {
/// `MaterialApp` or `WidgetsApp`
final Locale? locale;

/// Store custom configurations in here and use it in the widget tree
final Map<String, Object?> extraConfigurations;

@override
List<Object?> get props => [
dialogBarrierColor,
Expand Down

0 comments on commit 5e6115d

Please sign in to comment.