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

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

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

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

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

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

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

@ -577,8 +577,11 @@ class QuillToolbar extends StatelessWidget implements PreferredSizeWidget {
),
if (customButtons.isNotEmpty)
if (showDividers)
QuillDivider(axis,
color: sectionDividerColor, space: sectionDividerSpace),
QuillDivider(
axis,
color: sectionDividerColor,
space: sectionDividerSpace,
),
for (final customButton in customButtons)
if (customButton.child != null) ...[
InkWell(
@ -617,6 +620,10 @@ class QuillToolbar extends StatelessWidget implements PreferredSizeWidget {
/// is given.
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
/// More https://github.com/singerdmx/flutter-quill#translation
final Locale? locale;

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

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

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

@ -13,6 +13,7 @@ class SearchButton extends StatelessWidget {
this.iconSize = kDefaultIconSize,
this.fillColor,
this.iconTheme,
this.dialogBarrierColor = Colors.black54,
this.dialogTheme,
this.afterButtonPressed,
this.tooltip,
@ -24,6 +25,7 @@ class SearchButton extends StatelessWidget {
final QuillController controller;
final Color? fillColor;
final Color dialogBarrierColor;
final QuillIconTheme? iconTheme;
final QuillDialogTheme? dialogTheme;
@ -52,12 +54,19 @@ class SearchButton extends StatelessWidget {
}
Future<void> _onPressedHandler(BuildContext context) async {
await showDialog<String>(
final value = await showDialog<String>(
barrierColor: dialogBarrierColor,
context: context,
builder: (_) => SearchDialog(
controller: controller, dialogTheme: dialogTheme, text: ''),
).then(_searchSubmitted);
controller: controller,
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