From b0437c4d3f9abfcfd6b01e37319bde4159692819 Mon Sep 17 00:00:00 2001 From: X Code Date: Sat, 18 Dec 2021 21:20:41 -0800 Subject: [PATCH] Remove class QuillCheckbox --- lib/src/widgets/style_widgets/checkbox.dart | 60 ------------------- .../widgets/style_widgets/checkbox_point.dart | 17 ++++++ .../widgets/style_widgets/style_widgets.dart | 2 +- lib/src/widgets/text_block.dart | 1 - 4 files changed, 18 insertions(+), 62 deletions(-) delete mode 100644 lib/src/widgets/style_widgets/checkbox.dart diff --git a/lib/src/widgets/style_widgets/checkbox.dart b/lib/src/widgets/style_widgets/checkbox.dart deleted file mode 100644 index 64f36120..00000000 --- a/lib/src/widgets/style_widgets/checkbox.dart +++ /dev/null @@ -1,60 +0,0 @@ -import 'package:flutter/material.dart'; - -class QuillCheckbox extends StatelessWidget { - const QuillCheckbox({ - Key? key, - this.style, - this.width, - this.isChecked = false, - this.offset, - this.onTap, - this.uiBuilder, - }) : super(key: key); - final TextStyle? style; - final double? width; - final bool isChecked; - final int? offset; - final Function(int, bool)? onTap; - final QuillCheckboxBuilder? uiBuilder; - - void _onCheckboxClicked(bool? newValue) { - if (onTap != null && newValue != null && offset != null) { - onTap!(offset!, newValue); - } - } - - @override - Widget build(BuildContext context) { - Widget child; - if (uiBuilder != null) { - child = uiBuilder!.build( - context: context, - isChecked: isChecked, - onChanged: _onCheckboxClicked, - ); - } else { - child = Container( - alignment: AlignmentDirectional.topEnd, - width: width, - padding: const EdgeInsetsDirectional.only(end: 13), - child: GestureDetector( - onLongPress: () => _onCheckboxClicked(!isChecked), - child: Checkbox( - value: isChecked, - onChanged: _onCheckboxClicked, - ), - ), - ); - } - - return child; - } -} - -abstract class QuillCheckboxBuilder { - Widget build({ - required BuildContext context, - required bool isChecked, - required void Function(bool?) onChanged, - }); -} diff --git a/lib/src/widgets/style_widgets/checkbox_point.dart b/lib/src/widgets/style_widgets/checkbox_point.dart index 1f97097d..7f4bfe88 100644 --- a/lib/src/widgets/style_widgets/checkbox_point.dart +++ b/lib/src/widgets/style_widgets/checkbox_point.dart @@ -6,6 +6,7 @@ class CheckboxPoint extends StatefulWidget { required this.value, required this.enabled, required this.onChanged, + this.uiBuilder, Key? key, }) : super(key: key); @@ -13,6 +14,7 @@ class CheckboxPoint extends StatefulWidget { final bool value; final bool enabled; final ValueChanged onChanged; + final QuillCheckboxBuilder? uiBuilder; @override _CheckboxPointState createState() => _CheckboxPointState(); @@ -21,6 +23,13 @@ class CheckboxPoint extends StatefulWidget { class _CheckboxPointState extends State { @override Widget build(BuildContext context) { + if (widget.uiBuilder != null) { + return widget.uiBuilder!.build( + context: context, + isChecked: widget.value, + onChanged: widget.onChanged, + ); + } final theme = Theme.of(context); final fillColor = widget.value ? (widget.enabled @@ -59,3 +68,11 @@ class _CheckboxPointState extends State { ); } } + +abstract class QuillCheckboxBuilder { + Widget build({ + required BuildContext context, + required bool isChecked, + required ValueChanged onChanged, + }); +} diff --git a/lib/src/widgets/style_widgets/style_widgets.dart b/lib/src/widgets/style_widgets/style_widgets.dart index 2a252d43..c28606bc 100644 --- a/lib/src/widgets/style_widgets/style_widgets.dart +++ b/lib/src/widgets/style_widgets/style_widgets.dart @@ -1,3 +1,3 @@ export 'bullet_point.dart'; -export 'checkbox.dart'; +export 'checkbox_point.dart'; export 'number_point.dart'; diff --git a/lib/src/widgets/text_block.dart b/lib/src/widgets/text_block.dart index aed6ed77..fcfaa195 100644 --- a/lib/src/widgets/text_block.dart +++ b/lib/src/widgets/text_block.dart @@ -11,7 +11,6 @@ import 'cursor.dart'; import 'default_styles.dart'; import 'delegate.dart'; import 'editor.dart'; -import 'style_widgets/checkbox_point.dart'; import 'text_line.dart'; import 'text_selection.dart';