Restore use of alternative `QuillToolbarLinkStyleButton2` widget (#1547)

* Restore support of `QuillToolbarLinkStyleButton2`

* Fix localization
pull/1555/head
MacDeveloper1 1 year ago committed by GitHub
parent df6e07d567
commit 11c83000ae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 19
      lib/src/models/config/toolbar/toolbar_configurations.dart
  2. 32
      lib/src/widgets/toolbar/buttons/link_style2.dart
  3. 19
      lib/src/widgets/toolbar/toolbar.dart

@ -15,6 +15,7 @@ import 'buttons/font_size.dart';
import 'buttons/history.dart'; import 'buttons/history.dart';
import 'buttons/indent.dart'; import 'buttons/indent.dart';
import 'buttons/link_style.dart'; import 'buttons/link_style.dart';
import 'buttons/link_style2.dart';
import 'buttons/search.dart'; import 'buttons/search.dart';
import 'buttons/select_alignment.dart'; import 'buttons/select_alignment.dart';
import 'buttons/select_header_style.dart'; import 'buttons/select_header_style.dart';
@ -32,6 +33,7 @@ export './buttons/font_size.dart';
export './buttons/history.dart'; export './buttons/history.dart';
export './buttons/indent.dart'; export './buttons/indent.dart';
export './buttons/link_style.dart'; export './buttons/link_style.dart';
export './buttons/link_style2.dart';
export './buttons/search.dart'; export './buttons/search.dart';
export './buttons/select_alignment.dart'; export './buttons/select_alignment.dart';
export './buttons/select_header_style.dart'; export './buttons/select_header_style.dart';
@ -50,6 +52,17 @@ const double kIconButtonFactor = 1.77;
/// The horizontal margin between the contents of each toolbar section. /// The horizontal margin between the contents of each toolbar section.
const double kToolbarSectionSpacing = 4; const double kToolbarSectionSpacing = 4;
enum LinkStyleType {
/// Defines the original [QuillToolbarLinkStyleButton].
original,
/// Defines the alternative [QuillToolbarLinkStyleButton2].
alternative;
bool get isOriginal => this == LinkStyleType.original;
bool get isAlternative => this == LinkStyleType.alternative;
}
/// The configurations for the toolbar widget of flutter quill /// The configurations for the toolbar widget of flutter quill
@immutable @immutable
class QuillToolbarConfigurations extends QuillSharedToolbarProperties { class QuillToolbarConfigurations extends QuillSharedToolbarProperties {
@ -91,6 +104,7 @@ class QuillToolbarConfigurations extends QuillSharedToolbarProperties {
this.showSearchButton = true, this.showSearchButton = true,
this.showSubscript = true, this.showSubscript = true,
this.showSuperscript = true, this.showSuperscript = true,
this.linkStyleType = LinkStyleType.original,
super.customButtons = const [], super.customButtons = const [],
/// The decoration to use for the toolbar. /// The decoration to use for the toolbar.
@ -191,6 +205,9 @@ class QuillToolbarConfigurations extends QuillSharedToolbarProperties {
///shown when embedding an image, for example ///shown when embedding an image, for example
final QuillDialogTheme? dialogTheme; final QuillDialogTheme? dialogTheme;
/// Defines which dialog is used for applying link attribute.
final LinkStyleType linkStyleType;
@override @override
List<Object?> get props => [ List<Object?> get props => [
buttonOptions, buttonOptions,
@ -239,6 +256,7 @@ class QuillToolbarButtonOptions extends Equatable {
this.selectHeaderStyleButtons = this.selectHeaderStyleButtons =
const QuillToolbarSelectHeaderStyleButtonsOptions(), const QuillToolbarSelectHeaderStyleButtonsOptions(),
this.linkStyle = const QuillToolbarLinkStyleButtonOptions(), this.linkStyle = const QuillToolbarLinkStyleButtonOptions(),
this.linkStyle2 = const QuillToolbarLinkStyleButton2Options(),
this.customButtons = const QuillToolbarCustomButtonOptions(), this.customButtons = const QuillToolbarCustomButtonOptions(),
}); });
@ -284,6 +302,7 @@ class QuillToolbarButtonOptions extends Equatable {
final QuillToolbarSelectHeaderStyleButtonsOptions selectHeaderStyleButtons; final QuillToolbarSelectHeaderStyleButtonsOptions selectHeaderStyleButtons;
final QuillToolbarLinkStyleButtonOptions linkStyle; final QuillToolbarLinkStyleButtonOptions linkStyle;
final QuillToolbarLinkStyleButton2Options linkStyle2;
final QuillToolbarCustomButtonOptions customButtons; final QuillToolbarCustomButtonOptions customButtons;

@ -6,12 +6,13 @@ import '../../../../extensions.dart'
show UtilityWidgets, AutoFormatMultipleLinksRule; show UtilityWidgets, AutoFormatMultipleLinksRule;
import '../../../extensions/quill_provider.dart'; import '../../../extensions/quill_provider.dart';
import '../../../l10n/extensions/localizations.dart'; import '../../../l10n/extensions/localizations.dart';
import '../../../models/config/toolbar/buttons/link_style2.dart'; import '../../../l10n/widgets/localizations.dart';
import '../../../models/documents/attribute.dart'; import '../../../models/documents/attribute.dart';
import '../../../models/themes/quill_dialog_theme.dart'; import '../../../models/themes/quill_dialog_theme.dart';
import '../../../models/themes/quill_icon_theme.dart'; import '../../../models/themes/quill_icon_theme.dart';
import '../../controller.dart'; import '../../controller.dart';
import '../../link.dart'; import '../../link.dart';
import '../../utils/provider.dart';
import '../base_toolbar.dart'; import '../base_toolbar.dart';
/// Alternative version of [QuillToolbarLinkStyleButton]. This widget has more /// Alternative version of [QuillToolbarLinkStyleButton]. This widget has more
@ -172,18 +173,23 @@ class _QuillToolbarLinkStyleButton2State
final textLink = await showDialog<QuillTextLink>( final textLink = await showDialog<QuillTextLink>(
context: context, context: context,
barrierColor: dialogBarrierColor, barrierColor: dialogBarrierColor,
builder: (_) => LinkStyleDialog( builder: (_) => QuillProvider.value(
dialogTheme: options.dialogTheme, value: context.requireQuillProvider,
text: initialTextLink.text, child: FlutterQuillLocalizationsWidget(
link: initialTextLink.link, child: LinkStyleDialog(
constraints: options.constraints, dialogTheme: options.dialogTheme,
addLinkLabel: options.addLinkLabel, text: initialTextLink.text,
editLinkLabel: options.editLinkLabel, link: initialTextLink.link,
linkColor: options.linkColor, constraints: options.constraints,
childrenSpacing: options.childrenSpacing, addLinkLabel: options.addLinkLabel,
autovalidateMode: options.autovalidateMode, editLinkLabel: options.editLinkLabel,
validationMessage: options.validationMessage, linkColor: options.linkColor,
buttonSize: options.buttonSize, childrenSpacing: options.childrenSpacing,
autovalidateMode: options.autovalidateMode,
validationMessage: options.validationMessage,
buttonSize: options.buttonSize,
),
),
), ),
); );

@ -393,12 +393,19 @@ class QuillToolbar extends StatelessWidget implements PreferredSizeWidget {
space: configurations.sectionDividerSpace, space: configurations.sectionDividerSpace,
), ),
if (configurations.showLink) ...[ if (configurations.showLink) ...[
QuillToolbarLinkStyleButton( toolbarConfigurations.linkStyleType.isOriginal
controller: toolbarConfigurations ? QuillToolbarLinkStyleButton(
.buttonOptions.linkStyle.controller ?? controller: toolbarConfigurations
globalController, .buttonOptions.linkStyle.controller ??
options: toolbarConfigurations.buttonOptions.linkStyle, globalController,
), options: toolbarConfigurations.buttonOptions.linkStyle,
)
: QuillToolbarLinkStyleButton2(
controller: toolbarConfigurations
.buttonOptions.linkStyle2.controller ??
globalController,
options: toolbarConfigurations.buttonOptions.linkStyle2,
),
spacerWidget, spacerWidget,
], ],
if (configurations.showSearchButton) ...[ if (configurations.showSearchButton) ...[

Loading…
Cancel
Save