Organize code

pull/1443/head
Ahmed Hnewa 2 years ago
parent 81d1422755
commit 7e998fc7cf
No known key found for this signature in database
GPG Key ID: C488CC70BBCEF0D1
  1. 11
      flutter_quill_extensions/lib/embeds/toolbar/image_button.dart
  2. 2
      flutter_quill_extensions/lib/embeds/toolbar/media_button.dart
  3. 11
      flutter_quill_extensions/lib/embeds/toolbar/video_button.dart
  4. 6
      flutter_quill_extensions/pubspec.yaml
  5. 12
      lib/src/utils/platform.dart
  6. 16
      lib/src/widgets/editor.dart
  7. 3
      lib/src/widgets/raw_editor.dart
  8. 11
      lib/src/widgets/toolbar.dart
  9. 3
      lib/src/widgets/toolbar/color_button.dart
  10. 3
      lib/src/widgets/toolbar/link_style_button.dart
  11. 4
      lib/src/widgets/toolbar/link_style_button2.dart
  12. 17
      lib/src/widgets/toolbar/search_button.dart

@ -66,7 +66,7 @@ class ImageButton extends StatelessWidget {
Future<void> _onPressedHandler(BuildContext context) async { Future<void> _onPressedHandler(BuildContext context) async {
final onImagePickCallbackRef = onImagePickCallback; final onImagePickCallbackRef = onImagePickCallback;
if (onImagePickCallbackRef == null) { if (onImagePickCallbackRef == null) {
_typeLink(context); await _typeLink(context);
return; return;
} }
final selector = final selector =
@ -80,7 +80,7 @@ class ImageButton extends StatelessWidget {
_pickImage(context); _pickImage(context);
break; break;
case MediaPickSetting.Link: case MediaPickSetting.Link:
_typeLink(context); await _typeLink(context);
break; break;
case MediaPickSetting.Camera: case MediaPickSetting.Camera:
await ImageVideoUtils.handleImageButtonTap( await ImageVideoUtils.handleImageButtonTap(
@ -116,14 +116,15 @@ class ImageButton extends StatelessWidget {
webImagePickImpl: webImagePickImpl, webImagePickImpl: webImagePickImpl,
); );
void _typeLink(BuildContext context) { Future<void> _typeLink(BuildContext context) async {
showDialog<String>( final value = await showDialog<String>(
context: context, context: context,
builder: (_) => LinkDialog( builder: (_) => LinkDialog(
dialogTheme: dialogTheme, dialogTheme: dialogTheme,
linkRegExp: linkRegExp, linkRegExp: linkRegExp,
), ),
).then(_linkSubmitted); );
_linkSubmitted(value);
} }
void _linkSubmitted(String? value) { void _linkSubmitted(String? value) {

@ -39,6 +39,7 @@ class MediaButton extends StatelessWidget {
this.galleryButtonText, this.galleryButtonText,
this.linkButtonText, this.linkButtonText,
this.autovalidateMode = AutovalidateMode.disabled, this.autovalidateMode = AutovalidateMode.disabled,
this.dialogBarrierColor = Colors.black54,
Key? key, Key? key,
this.validationMessage, this.validationMessage,
}) : assert(type == QuillMediaType.image, }) : assert(type == QuillMediaType.image,
@ -55,6 +56,7 @@ class MediaButton extends StatelessWidget {
final String? tooltip; final String? tooltip;
final MediaFilePicker mediaFilePicker; final MediaFilePicker mediaFilePicker;
final MediaPickedCallback? onMediaPickedCallback; final MediaPickedCallback? onMediaPickedCallback;
final Color dialogBarrierColor;
/// The margin between child widgets in the dialog. /// The margin between child widgets in the dialog.
final double childrenSpacing; final double childrenSpacing;

@ -74,11 +74,11 @@ class VideoButton extends StatelessWidget {
if (source == MediaPickSetting.Gallery) { if (source == MediaPickSetting.Gallery) {
_pickVideo(context); _pickVideo(context);
} else { } else {
_typeLink(context); await _typeLink(context);
} }
} }
} else { } else {
_typeLink(context); await _typeLink(context);
} }
} }
@ -91,11 +91,12 @@ class VideoButton extends StatelessWidget {
webVideoPickImpl: webVideoPickImpl, webVideoPickImpl: webVideoPickImpl,
); );
void _typeLink(BuildContext context) { Future<void> _typeLink(BuildContext context) async {
showDialog<String>( final value = await showDialog<String>(
context: context, context: context,
builder: (_) => LinkDialog(dialogTheme: dialogTheme), builder: (_) => LinkDialog(dialogTheme: dialogTheme),
).then(_linkSubmitted); );
_linkSubmitted(value);
} }
void _linkSubmitted(String? value) { void _linkSubmitted(String? value) {

@ -12,10 +12,10 @@ dependencies:
flutter: flutter:
sdk: flutter sdk: flutter
flutter_quill: ^7.4.15 # flutter_quill: ^7.4.15
# In case you are working on changes for both libraries, # In case you are working on changes for both libraries,
# flutter_quill: flutter_quill:
# path: ~/development/playground/framework_based/flutter/flutter-quill path: /Users/ahmedhnewa/development/playground/framework_based/flutter/flutter-quill
http: ^1.1.0 http: ^1.1.0
image_picker: ">=1.0.4" image_picker: ">=1.0.4"

@ -2,14 +2,18 @@ import 'package:device_info_plus/device_info_plus.dart';
import 'package:flutter/foundation.dart' import 'package:flutter/foundation.dart'
show kIsWeb, TargetPlatform, defaultTargetPlatform; show kIsWeb, TargetPlatform, defaultTargetPlatform;
bool isWeb() {
return kIsWeb;
}
bool isMobile([TargetPlatform? targetPlatform]) { bool isMobile([TargetPlatform? targetPlatform]) {
if (kIsWeb) return false; if (isWeb()) return false;
targetPlatform ??= defaultTargetPlatform; targetPlatform ??= defaultTargetPlatform;
return {TargetPlatform.iOS, TargetPlatform.android}.contains(targetPlatform); return {TargetPlatform.iOS, TargetPlatform.android}.contains(targetPlatform);
} }
bool isDesktop([TargetPlatform? targetPlatform]) { bool isDesktop([TargetPlatform? targetPlatform]) {
if (kIsWeb) return false; if (isWeb()) return false;
targetPlatform ??= defaultTargetPlatform; targetPlatform ??= defaultTargetPlatform;
return {TargetPlatform.macOS, TargetPlatform.linux, TargetPlatform.windows} return {TargetPlatform.macOS, TargetPlatform.linux, TargetPlatform.windows}
.contains(targetPlatform); .contains(targetPlatform);
@ -21,7 +25,7 @@ bool isKeyboardOS([TargetPlatform? targetPlatform]) {
} }
bool isAppleOS([TargetPlatform? targetPlatform]) { bool isAppleOS([TargetPlatform? targetPlatform]) {
if (kIsWeb) return false; if (isWeb()) return false;
targetPlatform ??= defaultTargetPlatform; targetPlatform ??= defaultTargetPlatform;
return { return {
TargetPlatform.macOS, TargetPlatform.macOS,
@ -30,7 +34,7 @@ bool isAppleOS([TargetPlatform? targetPlatform]) {
} }
bool isMacOS([TargetPlatform? targetPlatform]) { bool isMacOS([TargetPlatform? targetPlatform]) {
if (kIsWeb) return false; if (isWeb()) return false;
targetPlatform ??= defaultTargetPlatform; targetPlatform ??= defaultTargetPlatform;
return TargetPlatform.macOS == targetPlatform; return TargetPlatform.macOS == targetPlatform;
} }

@ -1068,7 +1068,9 @@ class RenderEditor extends RenderEditableContainerBox
localSelection(baseChild.container, textSelection, true); localSelection(baseChild.container, textSelection, true);
var basePoint = baseChild.getBaseEndpointForSelection(baseSelection); var basePoint = baseChild.getBaseEndpointForSelection(baseSelection);
basePoint = TextSelectionPoint( basePoint = TextSelectionPoint(
basePoint.point + baseParentData.offset, basePoint.direction); basePoint.point + baseParentData.offset,
basePoint.direction,
);
final extentNode = _container.queryChild(textSelection.end, false).node; final extentNode = _container.queryChild(textSelection.end, false).node;
RenderEditableBox? extentChild = baseChild; RenderEditableBox? extentChild = baseChild;
@ -1086,7 +1088,9 @@ class RenderEditor extends RenderEditableContainerBox
var extentPoint = var extentPoint =
extentChild.getExtentEndpointForSelection(extentSelection); extentChild.getExtentEndpointForSelection(extentSelection);
extentPoint = TextSelectionPoint( extentPoint = TextSelectionPoint(
extentPoint.point + extentParentData.offset, extentPoint.direction); extentPoint.point + extentParentData.offset,
extentPoint.direction,
);
return <TextSelectionPoint>[basePoint, extentPoint]; return <TextSelectionPoint>[basePoint, extentPoint];
} }
@ -1757,13 +1761,13 @@ class RenderEditableContainerBox extends RenderBox
EditableContainerParentData>, EditableContainerParentData>,
RenderBoxContainerDefaultsMixin<RenderEditableBox, RenderBoxContainerDefaultsMixin<RenderEditableBox,
EditableContainerParentData> { EditableContainerParentData> {
RenderEditableContainerBox( RenderEditableContainerBox({
{required container_node.Container container, required container_node.Container container,
required this.textDirection, required this.textDirection,
required this.scrollBottomInset, required this.scrollBottomInset,
required EdgeInsetsGeometry padding, required EdgeInsetsGeometry padding,
List<RenderEditableBox>? children}) List<RenderEditableBox>? children,
: assert(padding.isNonNegative), }) : assert(padding.isNonNegative),
_container = container, _container = container,
_padding = padding { _padding = padding {
addAll(children); addAll(children);

@ -1844,7 +1844,8 @@ class _Editor extends MultiChildRenderObjectWidget {
padding: padding, padding: padding,
maxContentWidth: maxContentWidth, maxContentWidth: maxContentWidth,
scrollBottomInset: scrollBottomInset, scrollBottomInset: scrollBottomInset,
floatingCursorDisabled: floatingCursorDisabled); floatingCursorDisabled: floatingCursorDisabled,
);
} }
@override @override

@ -577,8 +577,11 @@ class QuillToolbar extends StatelessWidget implements PreferredSizeWidget {
), ),
if (customButtons.isNotEmpty) if (customButtons.isNotEmpty)
if (showDividers) if (showDividers)
QuillDivider(axis, QuillDivider(
color: sectionDividerColor, space: sectionDividerSpace), axis,
color: sectionDividerColor,
space: sectionDividerSpace,
),
for (final customButton in customButtons) for (final customButton in customButtons)
if (customButton.child != null) ...[ if (customButton.child != null) ...[
InkWell( InkWell(
@ -617,6 +620,10 @@ class QuillToolbar extends StatelessWidget implements PreferredSizeWidget {
/// is given. /// is given.
final Color? color; final Color? color;
// We will add this in the next major release and not now
/// The barrier color of the shown dialogs
// final Color dialogbarrierColor;
/// The locale to use for the editor toolbar, defaults to system locale /// The locale to use for the editor toolbar, defaults to system locale
/// More https://github.com/singerdmx/flutter-quill#translation /// More https://github.com/singerdmx/flutter-quill#translation
final Locale? locale; final Locale? locale;

@ -22,6 +22,7 @@ class ColorButton extends StatefulWidget {
this.iconTheme, this.iconTheme,
this.afterButtonPressed, this.afterButtonPressed,
this.tooltip, this.tooltip,
this.dialogBarrierColor = Colors.black54,
Key? key, Key? key,
}) : super(key: key); }) : super(key: key);
@ -32,6 +33,7 @@ class ColorButton extends StatefulWidget {
final QuillIconTheme? iconTheme; final QuillIconTheme? iconTheme;
final VoidCallback? afterButtonPressed; final VoidCallback? afterButtonPressed;
final String? tooltip; final String? tooltip;
final Color dialogBarrierColor;
@override @override
_ColorButtonState createState() => _ColorButtonState(); _ColorButtonState createState() => _ColorButtonState();
@ -159,6 +161,7 @@ class _ColorButtonState extends State<ColorButton> {
showDialog<String>( showDialog<String>(
context: context, context: context,
barrierColor: widget.dialogBarrierColor,
builder: (context) => StatefulBuilder(builder: (context, dlgSetState) { builder: (context) => StatefulBuilder(builder: (context, dlgSetState) {
return AlertDialog( return AlertDialog(
title: Text('Select Color'.i18n), title: Text('Select Color'.i18n),

@ -21,6 +21,7 @@ class LinkStyleButton extends StatefulWidget {
this.tooltip, this.tooltip,
this.linkRegExp, this.linkRegExp,
this.linkDialogAction, this.linkDialogAction,
this.dialogBarrierColor = Colors.black54,
Key? key, Key? key,
}) : super(key: key); }) : super(key: key);
@ -33,6 +34,7 @@ class LinkStyleButton extends StatefulWidget {
final String? tooltip; final String? tooltip;
final RegExp? linkRegExp; final RegExp? linkRegExp;
final LinkDialogAction? linkDialogAction; final LinkDialogAction? linkDialogAction;
final Color dialogBarrierColor;
@override @override
_LinkStyleButtonState createState() => _LinkStyleButtonState(); _LinkStyleButtonState createState() => _LinkStyleButtonState();
@ -95,6 +97,7 @@ class _LinkStyleButtonState extends State<LinkStyleButton> {
void _openLinkDialog(BuildContext context) { void _openLinkDialog(BuildContext context) {
showDialog<_TextLink>( showDialog<_TextLink>(
context: context, context: context,
barrierColor: widget.dialogBarrierColor,
builder: (ctx) { builder: (ctx) {
final link = _getLinkAttributeValue(); final link = _getLinkAttributeValue();
final index = widget.controller.selection.start; final index = widget.controller.selection.start;

@ -30,6 +30,7 @@ class LinkStyleButton2 extends StatefulWidget {
this.autovalidateMode = AutovalidateMode.disabled, this.autovalidateMode = AutovalidateMode.disabled,
this.validationMessage, this.validationMessage,
this.buttonSize, this.buttonSize,
this.dialogBarrierColor = Colors.black54,
Key? key, Key? key,
}) : assert(addLinkLabel == null || addLinkLabel.length > 0), }) : assert(addLinkLabel == null || addLinkLabel.length > 0),
assert(editLinkLabel == null || editLinkLabel.length > 0), assert(editLinkLabel == null || editLinkLabel.length > 0),
@ -66,6 +67,8 @@ class LinkStyleButton2 extends StatefulWidget {
/// The size of dialog buttons. /// The size of dialog buttons.
final Size? buttonSize; final Size? buttonSize;
final Color dialogBarrierColor;
@override @override
State<LinkStyleButton2> createState() => _LinkStyleButton2State(); State<LinkStyleButton2> createState() => _LinkStyleButton2State();
} }
@ -124,6 +127,7 @@ class _LinkStyleButton2State extends State<LinkStyleButton2> {
final textLink = await showDialog<QuillTextLink>( final textLink = await showDialog<QuillTextLink>(
context: context, context: context,
barrierColor: widget.dialogBarrierColor,
builder: (_) => LinkStyleDialog( builder: (_) => LinkStyleDialog(
dialogTheme: widget.dialogTheme, dialogTheme: widget.dialogTheme,
text: initialTextLink.text, text: initialTextLink.text,

@ -13,6 +13,7 @@ class SearchButton extends StatelessWidget {
this.iconSize = kDefaultIconSize, this.iconSize = kDefaultIconSize,
this.fillColor, this.fillColor,
this.iconTheme, this.iconTheme,
this.dialogBarrierColor = Colors.black54,
this.dialogTheme, this.dialogTheme,
this.afterButtonPressed, this.afterButtonPressed,
this.tooltip, this.tooltip,
@ -24,6 +25,7 @@ class SearchButton extends StatelessWidget {
final QuillController controller; final QuillController controller;
final Color? fillColor; final Color? fillColor;
final Color dialogBarrierColor;
final QuillIconTheme? iconTheme; final QuillIconTheme? iconTheme;
final QuillDialogTheme? dialogTheme; final QuillDialogTheme? dialogTheme;
@ -52,12 +54,19 @@ class SearchButton extends StatelessWidget {
} }
Future<void> _onPressedHandler(BuildContext context) async { Future<void> _onPressedHandler(BuildContext context) async {
await showDialog<String>( final value = await showDialog<String>(
barrierColor: dialogBarrierColor,
context: context, context: context,
builder: (_) => SearchDialog( builder: (_) => SearchDialog(
controller: controller, dialogTheme: dialogTheme, text: ''), controller: controller,
).then(_searchSubmitted); dialogTheme: dialogTheme,
text: '',
),
);
_searchSubmitted(value);
} }
void _searchSubmitted(String? value) {} void _searchSubmitted(String? value) {
// If we are doing nothing here then why we care about the result??
}
} }

Loading…
Cancel
Save