diff --git a/CHANGELOG.md b/CHANGELOG.md index c14eef17..2d80f938 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ All notable changes to this project will be documented in this file. * Require minimum version `6.0.0` of `flutter_keyboard_visibility` to fix some build issues with Android Gradle Plugin 8.2.0 * Add on image clicked in `flutter_quill_extensions` callback * Deprecate `globalIconSize` and `globalIconButtonFactor`, use `iconSize` and `iconButtonFactor` instead +* Fix the `QuillToolbarSelectAlignmentButtons` ## 9.1.1 * Require `super_clipboard` minimum version `0.8.1` to fix some bug with Linux build failure diff --git a/example/lib/screens/quill/my_quill_toolbar.dart b/example/lib/screens/quill/my_quill_toolbar.dart index 35686478..06d30cf5 100644 --- a/example/lib/screens/quill/my_quill_toolbar.dart +++ b/example/lib/screens/quill/my_quill_toolbar.dart @@ -5,6 +5,7 @@ import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_quill/extensions.dart' show isAndroid, isIOS, isWeb; import 'package:flutter_quill/flutter_quill.dart'; import 'package:flutter_quill_extensions/flutter_quill_extensions.dart'; +import 'package:google_fonts/google_fonts.dart'; import 'package:image_cropper/image_cropper.dart'; import 'package:path/path.dart' as path; import 'package:path_provider/path_provider.dart' @@ -202,6 +203,12 @@ class MyQuillToolbar extends StatelessWidget { controller: controller, showAlignmentButtons: true, multiRowsDisplay: true, + fontFamilyValues: { + 'Amatic': GoogleFonts.amaticSc().fontFamily!, + 'Annie': GoogleFonts.annieUseYourTelescope().fontFamily!, + 'Formal': GoogleFonts.petitFormalScript().fontFamily!, + 'Roboto': GoogleFonts.roboto().fontFamily! + }, buttonOptions: QuillSimpleToolbarButtonOptions( base: QuillToolbarBaseButtonOptions( afterButtonPressed: focusNode.requestFocus, diff --git a/example/macos/Flutter/GeneratedPluginRegistrant.swift b/example/macos/Flutter/GeneratedPluginRegistrant.swift index 0f3c17dd..f0811ff6 100644 --- a/example/macos/Flutter/GeneratedPluginRegistrant.swift +++ b/example/macos/Flutter/GeneratedPluginRegistrant.swift @@ -8,6 +8,7 @@ import Foundation import desktop_drop import device_info_plus import file_selector_macos +import flutter_inappwebview_macos import gal import irondash_engine_context import path_provider_foundation @@ -22,6 +23,7 @@ func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { DesktopDropPlugin.register(with: registry.registrar(forPlugin: "DesktopDropPlugin")) DeviceInfoPlusMacosPlugin.register(with: registry.registrar(forPlugin: "DeviceInfoPlusMacosPlugin")) FileSelectorPlugin.register(with: registry.registrar(forPlugin: "FileSelectorPlugin")) + InAppWebViewFlutterPlugin.register(with: registry.registrar(forPlugin: "InAppWebViewFlutterPlugin")) GalPlugin.register(with: registry.registrar(forPlugin: "GalPlugin")) IrondashEngineContextPlugin.register(with: registry.registrar(forPlugin: "IrondashEngineContextPlugin")) PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin")) diff --git a/example/pubspec.yaml b/example/pubspec.yaml index 301da2ac..e365e550 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -47,6 +47,7 @@ dependencies: # For sharing text share_plus: ^7.2.1 printing: ^5.11.1 + google_fonts: ^6.1.0 dependency_overrides: flutter_quill: diff --git a/lib/src/models/config/toolbar/buttons/select_alignment_configurations.dart b/lib/src/models/config/toolbar/buttons/select_alignment_configurations.dart index 65b33395..e5282855 100644 --- a/lib/src/models/config/toolbar/buttons/select_alignment_configurations.dart +++ b/lib/src/models/config/toolbar/buttons/select_alignment_configurations.dart @@ -1,4 +1,7 @@ +// ignore_for_file: public_member_api_docs, sort_constructors_first import 'package:flutter/widgets.dart' show IconData, immutable; + +import '../../../documents/attribute.dart'; import '../base_button_configurations.dart'; class QuillToolbarSelectAlignmentButtonExtraOptions @@ -24,6 +27,11 @@ class QuillToolbarSelectAlignmentButtonOptions /// This will called on every select alignment button super.childBuilder, super.iconTheme, + this.attributes, + this.showLeftAlignment = true, + this.showCenterAlignment = true, + this.showRightAlignment = true, + this.showJustifyAlignment = true, }); /// Default to @@ -37,6 +45,33 @@ class QuillToolbarSelectAlignmentButtonOptions /// By default will use the localized tooltips final QuillSelectAlignmentValues? tooltips; + + final List? attributes; + + final bool showLeftAlignment; + final bool showCenterAlignment; + final bool showRightAlignment; + final bool showJustifyAlignment; + + QuillToolbarSelectAlignmentButtonOptions copyWith({ + QuillSelectAlignmentValues? iconsData, + QuillSelectAlignmentValues? tooltips, + List? attributes, + bool? showLeftAlignment, + bool? showCenterAlignment, + bool? showRightAlignment, + bool? showJustifyAlignment, + }) { + return QuillToolbarSelectAlignmentButtonOptions( + iconsData: iconsData ?? this.iconsData, + tooltips: tooltips ?? this.tooltips, + attributes: attributes ?? this.attributes, + showLeftAlignment: showLeftAlignment ?? this.showLeftAlignment, + showCenterAlignment: showCenterAlignment ?? this.showCenterAlignment, + showRightAlignment: showRightAlignment ?? this.showRightAlignment, + showJustifyAlignment: showJustifyAlignment ?? this.showJustifyAlignment, + ); + } } /// A helper class which hold all the values for the alignments of the diff --git a/lib/src/widgets/quill/quill_controller.dart b/lib/src/widgets/quill/quill_controller.dart index 31908d7d..b2e076fa 100644 --- a/lib/src/widgets/quill/quill_controller.dart +++ b/lib/src/widgets/quill/quill_controller.dart @@ -71,12 +71,12 @@ class QuillController extends ChangeNotifier { // from the current line /// The current font family, null to use the default one - String? _selectedFontFamily; + MapEntry? _selectedFontFamily; /// The current font family, null to use the default one - String? get selectedFontFamily => _selectedFontFamily; + MapEntry? get selectedFontFamily => _selectedFontFamily; - void selectFontFamily(String? newFontFamily) { + void selectFontFamily(MapEntry? newFontFamily) { _selectedFontFamily = newFontFamily; } diff --git a/lib/src/widgets/raw_editor/raw_editor_state_text_input_client_mixin.dart b/lib/src/widgets/raw_editor/raw_editor_state_text_input_client_mixin.dart index cb46bab7..b6e23333 100644 --- a/lib/src/widgets/raw_editor/raw_editor_state_text_input_client_mixin.dart +++ b/lib/src/widgets/raw_editor/raw_editor_state_text_input_client_mixin.dart @@ -208,27 +208,27 @@ mixin RawEditorStateTextInputClientMixin on EditorState value.selection, ); - if (widget.configurations.controller.selectedFontFamily != null) { - widget.configurations.controller.formatSelection( - Attribute.fromKeyValue( - Attribute.font.key, - widget.configurations.controller.selectedFontFamily, - ), - ); - } + // if (widget.configurations.controller.selectedFontFamily != null) { + // widget.configurations.controller.formatSelection( + // Attribute.fromKeyValue( + // Attribute.font.key, + // widget.configurations.controller.selectedFontFamily?.value, + // ), + // ); + // } - if (widget.configurations.controller.selectedFontSize != null) { - widget.configurations.controller.formatSelection( - Attribute.fromKeyValue( - Attribute.size.key, - widget.configurations.controller.selectedFontSize == '0' - ? null - : getFontSize( - widget.configurations.controller.selectedFontSize, - ), - ), - ); - } + // if (widget.configurations.controller.selectedFontSize != null) { + // widget.configurations.controller.formatSelection( + // Attribute.fromKeyValue( + // Attribute.size.key, + // widget.configurations.controller.selectedFontSize == '0' + // ? null + // : getFontSize( + // widget.configurations.controller.selectedFontSize, + // ), + // ), + // ); + // } // if (widget.configurations.controller.keepStyleOnNewLine) { // widget.configurations.controller.selectedStyles.forEach((key, value) { // if (value ?? false) { diff --git a/lib/src/widgets/toolbar/buttons/alignment/select_alignment_buttons.dart b/lib/src/widgets/toolbar/buttons/alignment/select_alignment_buttons.dart index bab35f3e..ff7fca68 100644 --- a/lib/src/widgets/toolbar/buttons/alignment/select_alignment_buttons.dart +++ b/lib/src/widgets/toolbar/buttons/alignment/select_alignment_buttons.dart @@ -4,46 +4,34 @@ import '../../../../models/documents/attribute.dart'; import '../../../quill/quill_controller.dart'; import '../../base_toolbar.dart'; -enum _AlignmentOptions { - left(attribute: Attribute.leftAlignment), - center(attribute: Attribute.centerAlignment), - right(attribute: Attribute.rightAlignment), - justifyMinWidth(attribute: Attribute.justifyAlignment); - - const _AlignmentOptions({required this.attribute}); - - final Attribute attribute; -} - class QuillToolbarSelectAlignmentButtons extends StatelessWidget { const QuillToolbarSelectAlignmentButtons({ required this.controller, this.options = const QuillToolbarSelectAlignmentButtonOptions(), - this.showLeftAlignment, - this.showCenterAlignment, - this.showRightAlignment, - this.showJustifyAlignment, - this.padding, super.key, }); final QuillController controller; final QuillToolbarSelectAlignmentButtonOptions options; - final bool? showLeftAlignment; - final bool? showCenterAlignment; - final bool? showRightAlignment; - final bool? showJustifyAlignment; - final EdgeInsetsGeometry? padding; + List get _attrbuites { + return options.attributes ?? + [ + if (options.showLeftAlignment) Attribute.leftAlignment, + if (options.showCenterAlignment) Attribute.centerAlignment, + if (options.showRightAlignment) Attribute.rightAlignment, + if (options.showJustifyAlignment) Attribute.justifyAlignment, + ]; + } @override Widget build(BuildContext context) { return Row( mainAxisSize: MainAxisSize.min, - children: _AlignmentOptions.values + children: _attrbuites .map((e) => QuillToolbarToggleStyleButton( controller: controller, - attribute: e.attribute, + attribute: e, options: QuillToolbarToggleStyleButtonOptions( iconData: options.iconData, iconSize: options.iconSize, diff --git a/lib/src/widgets/toolbar/buttons/font_family_button.dart b/lib/src/widgets/toolbar/buttons/font_family_button.dart index 854cf7cb..01a2cb47 100644 --- a/lib/src/widgets/toolbar/buttons/font_family_button.dart +++ b/lib/src/widgets/toolbar/buttons/font_family_button.dart @@ -41,17 +41,13 @@ class QuillToolbarFontFamilyButtonState return widget.options; } - // Style get _selectionStyle => controller.getSelectionStyle(); - @override void initState() { super.initState(); _initState(); } - void _initState() { - // controller.addListener(_didChangeEditingValue); - } + void _initState() {} @override void didChangeDependencies() { @@ -59,12 +55,6 @@ class QuillToolbarFontFamilyButtonState _currentValue = _defaultDisplayText; } - // @override - // void dispose() { - // controller.removeListener(_didChangeEditingValue); - // super.dispose(); - // } - String get _defaultDisplayText { return options.initialValue ?? widget.options.defaultDisplayText ?? @@ -218,7 +208,7 @@ class QuillToolbarFontFamilyButtonState controller.selectFontFamily(null); return; } - controller.selectFontFamily(fontFamily.value); + controller.selectFontFamily(fontFamily); }, child: Text( fontFamily.key.toString(), @@ -272,7 +262,7 @@ class QuillToolbarFontFamilyButtonState enabled: hasFinalWidth, wrapper: (child) => Expanded(child: child), child: Text( - widget.controller.selectedFontFamily ?? _currentValue, + widget.controller.selectedFontFamily?.key ?? _currentValue, maxLines: 1, overflow: options.labelOverflow, style: options.style ?? diff --git a/lib/src/widgets/toolbar/simple_toolbar.dart b/lib/src/widgets/toolbar/simple_toolbar.dart index 60b72a3e..ccf0c4e4 100644 --- a/lib/src/widgets/toolbar/simple_toolbar.dart +++ b/lib/src/widgets/toolbar/simple_toolbar.dart @@ -168,11 +168,13 @@ class QuillSimpleToolbar extends StatelessWidget if (configurations.showAlignmentButtons) QuillToolbarSelectAlignmentButtons( controller: globalController, - options: toolbarConfigurations.buttonOptions.selectAlignmentButtons, - showLeftAlignment: configurations.showLeftAlignment, - showCenterAlignment: configurations.showCenterAlignment, - showRightAlignment: configurations.showRightAlignment, - showJustifyAlignment: configurations.showJustifyAlignment, + options: toolbarConfigurations.buttonOptions.selectAlignmentButtons + .copyWith( + showLeftAlignment: configurations.showLeftAlignment, + showCenterAlignment: configurations.showCenterAlignment, + showRightAlignment: configurations.showRightAlignment, + showJustifyAlignment: configurations.showJustifyAlignment, + ), ), if (configurations.showDirection) QuillToolbarToggleStyleButton(