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/indent.dart';
import 'buttons/link_style.dart';
import 'buttons/link_style2.dart';
import 'buttons/search.dart';
import 'buttons/select_alignment.dart';
import 'buttons/select_header_style.dart';
@ -32,6 +33,7 @@ export './buttons/font_size.dart';
export './buttons/history.dart';
export './buttons/indent.dart';
export './buttons/link_style.dart';
export './buttons/link_style2.dart';
export './buttons/search.dart';
export './buttons/select_alignment.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.
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
@immutable
class QuillToolbarConfigurations extends QuillSharedToolbarProperties {
@ -91,6 +104,7 @@ class QuillToolbarConfigurations extends QuillSharedToolbarProperties {
this.showSearchButton = true,
this.showSubscript = true,
this.showSuperscript = true,
this.linkStyleType = LinkStyleType.original,
super.customButtons = const [],
/// The decoration to use for the toolbar.
@ -191,6 +205,9 @@ class QuillToolbarConfigurations extends QuillSharedToolbarProperties {
///shown when embedding an image, for example
final QuillDialogTheme? dialogTheme;
/// Defines which dialog is used for applying link attribute.
final LinkStyleType linkStyleType;
@override
List<Object?> get props => [
buttonOptions,
@ -239,6 +256,7 @@ class QuillToolbarButtonOptions extends Equatable {
this.selectHeaderStyleButtons =
const QuillToolbarSelectHeaderStyleButtonsOptions(),
this.linkStyle = const QuillToolbarLinkStyleButtonOptions(),
this.linkStyle2 = const QuillToolbarLinkStyleButton2Options(),
this.customButtons = const QuillToolbarCustomButtonOptions(),
});
@ -284,6 +302,7 @@ class QuillToolbarButtonOptions extends Equatable {
final QuillToolbarSelectHeaderStyleButtonsOptions selectHeaderStyleButtons;
final QuillToolbarLinkStyleButtonOptions linkStyle;
final QuillToolbarLinkStyleButton2Options linkStyle2;
final QuillToolbarCustomButtonOptions customButtons;

@ -6,12 +6,13 @@ import '../../../../extensions.dart'
show UtilityWidgets, AutoFormatMultipleLinksRule;
import '../../../extensions/quill_provider.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/themes/quill_dialog_theme.dart';
import '../../../models/themes/quill_icon_theme.dart';
import '../../controller.dart';
import '../../link.dart';
import '../../utils/provider.dart';
import '../base_toolbar.dart';
/// Alternative version of [QuillToolbarLinkStyleButton]. This widget has more
@ -172,18 +173,23 @@ class _QuillToolbarLinkStyleButton2State
final textLink = await showDialog<QuillTextLink>(
context: context,
barrierColor: dialogBarrierColor,
builder: (_) => LinkStyleDialog(
dialogTheme: options.dialogTheme,
text: initialTextLink.text,
link: initialTextLink.link,
constraints: options.constraints,
addLinkLabel: options.addLinkLabel,
editLinkLabel: options.editLinkLabel,
linkColor: options.linkColor,
childrenSpacing: options.childrenSpacing,
autovalidateMode: options.autovalidateMode,
validationMessage: options.validationMessage,
buttonSize: options.buttonSize,
builder: (_) => QuillProvider.value(
value: context.requireQuillProvider,
child: FlutterQuillLocalizationsWidget(
child: LinkStyleDialog(
dialogTheme: options.dialogTheme,
text: initialTextLink.text,
link: initialTextLink.link,
constraints: options.constraints,
addLinkLabel: options.addLinkLabel,
editLinkLabel: options.editLinkLabel,
linkColor: options.linkColor,
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,
),
if (configurations.showLink) ...[
QuillToolbarLinkStyleButton(
controller: toolbarConfigurations
.buttonOptions.linkStyle.controller ??
globalController,
options: toolbarConfigurations.buttonOptions.linkStyle,
),
toolbarConfigurations.linkStyleType.isOriginal
? QuillToolbarLinkStyleButton(
controller: toolbarConfigurations
.buttonOptions.linkStyle.controller ??
globalController,
options: toolbarConfigurations.buttonOptions.linkStyle,
)
: QuillToolbarLinkStyleButton2(
controller: toolbarConfigurations
.buttonOptions.linkStyle2.controller ??
globalController,
options: toolbarConfigurations.buttonOptions.linkStyle2,
),
spacerWidget,
],
if (configurations.showSearchButton) ...[

Loading…
Cancel
Save