feat: Added builder for custom button in _LinkDialog (#1342)

pull/1347/head
Joep Heijnen 2 years ago committed by GitHub
parent df57af93dd
commit 3263e7f259
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      lib/flutter_quill.dart
  2. 7
      lib/src/models/structs/link_dialog_action.dart
  3. 8
      lib/src/models/themes/quill_dialog_theme.dart
  4. 9
      lib/src/widgets/toolbar.dart
  5. 30
      lib/src/widgets/toolbar/link_style_button.dart

@ -11,6 +11,7 @@ export 'src/models/documents/style.dart';
export 'src/models/quill_delta.dart'; export 'src/models/quill_delta.dart';
export 'src/models/structs/doc_change.dart'; export 'src/models/structs/doc_change.dart';
export 'src/models/structs/image_url.dart'; export 'src/models/structs/image_url.dart';
export 'src/models/structs/link_dialog_action.dart';
export 'src/models/structs/offset_value.dart'; export 'src/models/structs/offset_value.dart';
export 'src/models/structs/optional_size.dart'; export 'src/models/structs/optional_size.dart';
export 'src/models/structs/vertical_spacing.dart'; export 'src/models/structs/vertical_spacing.dart';

@ -0,0 +1,7 @@
import 'package:flutter/material.dart';
class LinkDialogAction {
LinkDialogAction({required this.builder});
Widget Function(bool canPress, void Function() applyLink) builder;
}

@ -4,6 +4,7 @@ import 'package:flutter/material.dart';
/// Used to configure the dialog's look and feel. /// Used to configure the dialog's look and feel.
class QuillDialogTheme with Diagnosticable { class QuillDialogTheme with Diagnosticable {
const QuillDialogTheme({ const QuillDialogTheme({
this.buttonTextStyle,
this.labelTextStyle, this.labelTextStyle,
this.inputTextStyle, this.inputTextStyle,
this.dialogBackgroundColor, this.dialogBackgroundColor,
@ -17,6 +18,9 @@ class QuillDialogTheme with Diagnosticable {
this.runSpacing = 8.0, this.runSpacing = 8.0,
}) : assert(runSpacing >= 0); }) : assert(runSpacing >= 0);
///The text style to use for the button shown in the dialog
final TextStyle? buttonTextStyle;
///The text style to use for the label shown in the link-input dialog ///The text style to use for the label shown in the link-input dialog
final TextStyle? labelTextStyle; final TextStyle? labelTextStyle;
@ -59,6 +63,7 @@ class QuillDialogTheme with Diagnosticable {
final double runSpacing; final double runSpacing;
QuillDialogTheme copyWith({ QuillDialogTheme copyWith({
TextStyle? buttonTextStyle,
TextStyle? labelTextStyle, TextStyle? labelTextStyle,
TextStyle? inputTextStyle, TextStyle? inputTextStyle,
Color? dialogBackgroundColor, Color? dialogBackgroundColor,
@ -72,6 +77,7 @@ class QuillDialogTheme with Diagnosticable {
double? runSpacing, double? runSpacing,
}) { }) {
return QuillDialogTheme( return QuillDialogTheme(
buttonTextStyle: buttonTextStyle ?? this.buttonTextStyle,
labelTextStyle: labelTextStyle ?? this.labelTextStyle, labelTextStyle: labelTextStyle ?? this.labelTextStyle,
inputTextStyle: inputTextStyle ?? this.inputTextStyle, inputTextStyle: inputTextStyle ?? this.inputTextStyle,
dialogBackgroundColor: dialogBackgroundColor:
@ -96,6 +102,7 @@ class QuillDialogTheme with Diagnosticable {
return false; return false;
} }
return other is QuillDialogTheme && return other is QuillDialogTheme &&
other.buttonTextStyle == buttonTextStyle &&
other.labelTextStyle == labelTextStyle && other.labelTextStyle == labelTextStyle &&
other.inputTextStyle == inputTextStyle && other.inputTextStyle == inputTextStyle &&
other.dialogBackgroundColor == dialogBackgroundColor && other.dialogBackgroundColor == dialogBackgroundColor &&
@ -112,6 +119,7 @@ class QuillDialogTheme with Diagnosticable {
@override @override
int get hashCode => Object.hash( int get hashCode => Object.hash(
buttonTextStyle,
labelTextStyle, labelTextStyle,
inputTextStyle, inputTextStyle,
dialogBackgroundColor, dialogBackgroundColor,

@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
import 'package:i18n_extension/i18n_widget.dart'; import 'package:i18n_extension/i18n_widget.dart';
import '../models/documents/attribute.dart'; import '../models/documents/attribute.dart';
import '../models/structs/link_dialog_action.dart';
import '../models/themes/quill_custom_button.dart'; import '../models/themes/quill_custom_button.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';
@ -64,6 +65,7 @@ class QuillToolbar extends StatelessWidget implements PreferredSizeWidget {
VoidCallback? afterButtonPressed, VoidCallback? afterButtonPressed,
this.sectionDividerColor, this.sectionDividerColor,
this.sectionDividerSpace, this.sectionDividerSpace,
this.linkDialogAction,
Key? key, Key? key,
}) : super(key: key); }) : super(key: key);
@ -157,6 +159,9 @@ class QuillToolbar extends StatelessWidget implements PreferredSizeWidget {
/// Validate the legitimacy of hyperlinks /// Validate the legitimacy of hyperlinks
RegExp? linkRegExp, RegExp? linkRegExp,
LinkDialogAction? linkDialogAction,
Key? key, Key? key,
}) { }) {
final isButtonGroupShown = [ final isButtonGroupShown = [
@ -555,6 +560,7 @@ class QuillToolbar extends StatelessWidget implements PreferredSizeWidget {
dialogTheme: dialogTheme, dialogTheme: dialogTheme,
afterButtonPressed: afterButtonPressed, afterButtonPressed: afterButtonPressed,
linkRegExp: linkRegExp, linkRegExp: linkRegExp,
linkDialogAction: linkDialogAction,
), ),
if (showSearchButton) if (showSearchButton)
SearchButton( SearchButton(
@ -599,6 +605,9 @@ class QuillToolbar extends StatelessWidget implements PreferredSizeWidget {
final WrapCrossAlignment toolbarIconCrossAlignment; final WrapCrossAlignment toolbarIconCrossAlignment;
final bool multiRowsDisplay; final bool multiRowsDisplay;
// Overrides the action in the _LinkDialog widget
final LinkDialogAction? linkDialogAction;
/// The color of the toolbar. /// The color of the toolbar.
/// ///
/// Defaults to [ThemeData.canvasColor] of the current [Theme] if no color /// Defaults to [ThemeData.canvasColor] of the current [Theme] if no color

@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
import '../../models/documents/attribute.dart'; import '../../models/documents/attribute.dart';
import '../../models/rules/insert.dart'; import '../../models/rules/insert.dart';
import '../../models/structs/link_dialog_action.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 '../../translations/toolbar.i18n.dart'; import '../../translations/toolbar.i18n.dart';
@ -19,6 +20,7 @@ class LinkStyleButton extends StatefulWidget {
this.afterButtonPressed, this.afterButtonPressed,
this.tooltip, this.tooltip,
this.linkRegExp, this.linkRegExp,
this.linkDialogAction,
Key? key, Key? key,
}) : super(key: key); }) : super(key: key);
@ -30,6 +32,7 @@ class LinkStyleButton extends StatefulWidget {
final VoidCallback? afterButtonPressed; final VoidCallback? afterButtonPressed;
final String? tooltip; final String? tooltip;
final RegExp? linkRegExp; final RegExp? linkRegExp;
final LinkDialogAction? linkDialogAction;
@override @override
_LinkStyleButtonState createState() => _LinkStyleButtonState(); _LinkStyleButtonState createState() => _LinkStyleButtonState();
@ -114,6 +117,7 @@ class _LinkStyleButtonState extends State<LinkStyleButton> {
link: link, link: link,
text: text, text: text,
linkRegExp: widget.linkRegExp, linkRegExp: widget.linkRegExp,
action: widget.linkDialogAction,
); );
}, },
).then( ).then(
@ -154,6 +158,7 @@ class _LinkDialog extends StatefulWidget {
this.link, this.link,
this.text, this.text,
this.linkRegExp, this.linkRegExp,
this.action,
Key? key, Key? key,
}) : super(key: key); }) : super(key: key);
@ -161,6 +166,7 @@ class _LinkDialog extends StatefulWidget {
final String? link; final String? link;
final String? text; final String? text;
final RegExp? linkRegExp; final RegExp? linkRegExp;
final LinkDialogAction? action;
@override @override
_LinkDialogState createState() => _LinkDialogState(); _LinkDialogState createState() => _LinkDialogState();
@ -216,15 +222,21 @@ class _LinkDialogState extends State<_LinkDialog> {
), ),
], ],
), ),
actions: [ actions: [_okButton()],
TextButton( );
onPressed: _canPress() ? _applyLink : null, }
child: Text(
'Ok'.i18n, Widget _okButton() {
style: widget.dialogTheme?.labelTextStyle, if (widget.action != null) {
), return widget.action!.builder(_canPress(), _applyLink);
), }
],
return TextButton(
onPressed: _canPress() ? _applyLink : null,
child: Text(
'Ok'.i18n,
style: widget.dialogTheme?.buttonTextStyle,
),
); );
} }

Loading…
Cancel
Save