From c81eb9448c62ac4443b299be085cb18851eb9e19 Mon Sep 17 00:00:00 2001 From: bambinoua <130981115+MacDeveloper1@users.noreply.github.com> Date: Thu, 20 Apr 2023 12:26:57 +0200 Subject: [PATCH] Implement `dialogTheme` for `QuillEditor` --- lib/src/widgets/editor.dart | 5 +++++ lib/src/widgets/raw_editor.dart | 8 ++++++-- lib/src/widgets/toolbar/link_style_button2.dart | 13 ++++++++++--- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/lib/src/widgets/editor.dart b/lib/src/widgets/editor.dart index eac31792..71bbd84a 100644 --- a/lib/src/widgets/editor.dart +++ b/lib/src/widgets/editor.dart @@ -15,6 +15,7 @@ import '../models/documents/nodes/container.dart' as container_node; import '../models/documents/nodes/leaf.dart'; import '../models/documents/style.dart'; import '../models/structs/offset_value.dart'; +import '../models/themes/quill_dialog_theme.dart'; import '../utils/platform.dart'; import 'box.dart'; import 'controller.dart'; @@ -184,6 +185,7 @@ class QuillEditor extends StatefulWidget { this.detectWordBoundary = true, this.enableUnfocusOnTapOutside = true, this.customLinkPrefixes = const [], + this.dialogTheme, Key? key, }) : super(key: key); @@ -420,6 +422,9 @@ class QuillEditor extends StatefulWidget { /// Useful for deeplinks final List customLinkPrefixes; + /// Configures the dialog theme. + final QuillDialogTheme? dialogTheme; + @override QuillEditorState createState() => QuillEditorState(); } diff --git a/lib/src/widgets/raw_editor.dart b/lib/src/widgets/raw_editor.dart index 7eb5af5e..465072af 100644 --- a/lib/src/widgets/raw_editor.dart +++ b/lib/src/widgets/raw_editor.dart @@ -2,8 +2,6 @@ import 'dart:async'; import 'dart:convert'; import 'dart:io'; import 'dart:math' as math; -// ignore: unnecessary_import -import 'dart:typed_data'; import 'dart:ui' as ui hide TextStyle; import 'package:flutter/foundation.dart'; @@ -24,6 +22,7 @@ import '../models/documents/nodes/node.dart'; import '../models/documents/style.dart'; import '../models/structs/offset_value.dart'; import '../models/structs/vertical_spacing.dart'; +import '../models/themes/quill_dialog_theme.dart'; import '../utils/cast.dart'; import '../utils/delta.dart'; import '../utils/embeds.dart'; @@ -82,6 +81,7 @@ class RawEditor extends StatefulWidget { this.floatingCursorDisabled = false, this.onImagePaste, this.customLinkPrefixes = const [], + this.dialogTheme, }) : assert(maxHeight == null || maxHeight > 0, 'maxHeight cannot be null'), assert(minHeight == null || minHeight >= 0, 'minHeight cannot be null'), assert(maxHeight == null || minHeight == null || maxHeight >= minHeight, @@ -264,6 +264,9 @@ class RawEditor extends StatefulWidget { final bool floatingCursorDisabled; final List customLinkPrefixes; + /// Configures the dialog theme. + final QuillDialogTheme? dialogTheme; + @override State createState() => RawEditorState(); } @@ -2591,6 +2594,7 @@ class ApplyLinkAction extends Action { return LinkStyleDialog( text: initialTextLink.text, link: initialTextLink.link, + dialogTheme: state.widget.dialogTheme, ); }, ); diff --git a/lib/src/widgets/toolbar/link_style_button2.dart b/lib/src/widgets/toolbar/link_style_button2.dart index 4a54f3c9..03188427 100644 --- a/lib/src/widgets/toolbar/link_style_button2.dart +++ b/lib/src/widgets/toolbar/link_style_button2.dart @@ -247,9 +247,16 @@ class _LinkStyleDialogState extends State { kIsWeb ? mediaQuery.size.width / 4 : mediaQuery.size.width - 80; return BoxConstraints(maxWidth: maxWidth, maxHeight: 80); }(); - final buttonStyle = Theme.of(context).elevatedButtonTheme.style?.copyWith( - fixedSize: MaterialStatePropertyAll(widget.buttonSize), - ); + + var buttonStyle = widget.dialogTheme?.buttonStyle; + if (buttonStyle == null) { + if (widget.buttonSize != null) { + buttonStyle = Theme.of(context).elevatedButtonTheme.style?.copyWith( + fixedSize: MaterialStatePropertyAll(widget.buttonSize), + ); + } + } + return Dialog( backgroundColor: widget.dialogTheme?.dialogBackgroundColor, shape: widget.dialogTheme?.shape ??