Skip to content

Commit 230f091

Browse files
authored
enable customize the checkbox widget using DefaultListBlockStyle style. (singerdmx#436)
1 parent 71a8f75 commit 230f091

File tree

4 files changed

+51
-14
lines changed

4 files changed

+51
-14
lines changed

lib/flutter_quill.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ export 'src/models/themes/quill_icon_theme.dart';
1010
export 'src/widgets/controller.dart';
1111
export 'src/widgets/default_styles.dart';
1212
export 'src/widgets/editor.dart';
13+
export 'src/widgets/style_widgets/style_widgets.dart';
1314
export 'src/widgets/toolbar.dart';

lib/src/widgets/default_styles.dart

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import 'package:flutter/material.dart';
22
import 'package:flutter/widgets.dart';
3+
import 'package:flutter_quill/src/widgets/style_widgets/style_widgets.dart';
34
import 'package:tuple/tuple.dart';
45

56
class QuillStyles extends InheritedWidget {
@@ -43,6 +44,18 @@ class DefaultTextBlockStyle {
4344
final BoxDecoration? decoration;
4445
}
4546

47+
class DefaultListBlockStyle extends DefaultTextBlockStyle {
48+
DefaultListBlockStyle(
49+
TextStyle style,
50+
Tuple2<double, double> verticalSpacing,
51+
Tuple2<double, double> lineSpacing,
52+
BoxDecoration? decoration,
53+
this.checkboxUIBuilder,
54+
) : super(style, verticalSpacing, lineSpacing, decoration);
55+
56+
final QuillCheckboxBuilder? checkboxUIBuilder;
57+
}
58+
4659
class DefaultStyles {
4760
DefaultStyles({
4861
this.h1,
@@ -85,7 +98,7 @@ class DefaultStyles {
8598
final TextStyle? link;
8699
final Color? color;
87100
final DefaultTextBlockStyle? placeHolder;
88-
final DefaultTextBlockStyle? lists;
101+
final DefaultListBlockStyle? lists;
89102
final DefaultTextBlockStyle? quote;
90103
final DefaultTextBlockStyle? code;
91104
final DefaultTextBlockStyle? indent;
@@ -172,8 +185,8 @@ class DefaultStyles {
172185
const Tuple2(0, 0),
173186
const Tuple2(0, 0),
174187
null),
175-
lists: DefaultTextBlockStyle(
176-
baseStyle, baseSpacing, const Tuple2(0, 6), null),
188+
lists: DefaultListBlockStyle(
189+
baseStyle, baseSpacing, const Tuple2(0, 6), null, null),
177190
quote: DefaultTextBlockStyle(
178191
TextStyle(color: baseStyle.color!.withOpacity(0.6)),
179192
baseSpacing,

lib/src/widgets/style_widgets/checkbox.dart

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@ class QuillCheckbox extends StatelessWidget {
88
this.isChecked = false,
99
this.offset,
1010
this.onTap,
11+
this.uiBuilder,
1112
}) : super(key: key);
1213
final TextStyle? style;
1314
final double? width;
1415
final bool isChecked;
1516
final int? offset;
1617
final Function(int, bool)? onTap;
18+
final QuillCheckboxBuilder? uiBuilder;
1719

1820
void _onCheckboxClicked(bool? newValue) {
1921
if (onTap != null && newValue != null && offset != null) {
@@ -23,17 +25,36 @@ class QuillCheckbox extends StatelessWidget {
2325

2426
@override
2527
Widget build(BuildContext context) {
26-
return Container(
27-
alignment: AlignmentDirectional.topEnd,
28-
width: width,
29-
padding: const EdgeInsetsDirectional.only(end: 13),
30-
child: GestureDetector(
31-
onLongPress: () => _onCheckboxClicked(!isChecked),
32-
child: Checkbox(
33-
value: isChecked,
34-
onChanged: _onCheckboxClicked,
28+
Widget child;
29+
if (uiBuilder != null) {
30+
child = uiBuilder!.build(
31+
context: context,
32+
isChecked: isChecked,
33+
onChanged: _onCheckboxClicked,
34+
);
35+
} else {
36+
child = Container(
37+
alignment: AlignmentDirectional.topEnd,
38+
width: width,
39+
padding: const EdgeInsetsDirectional.only(end: 13),
40+
child: GestureDetector(
41+
onLongPress: () => _onCheckboxClicked(!isChecked),
42+
child: Checkbox(
43+
value: isChecked,
44+
onChanged: _onCheckboxClicked,
45+
),
3546
),
36-
),
37-
);
47+
);
48+
}
49+
50+
return child;
3851
}
3952
}
53+
54+
abstract class QuillCheckboxBuilder {
55+
Widget build({
56+
required BuildContext context,
57+
required bool isChecked,
58+
required void Function(bool?) onChanged,
59+
});
60+
}

lib/src/widgets/text_block.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ class EditableTextBlock extends StatelessWidget {
176176
isChecked: true,
177177
offset: block.offset + line.offset,
178178
onTap: onCheckboxTap,
179+
uiBuilder: defaultStyles.lists!.checkboxUIBuilder,
179180
);
180181
}
181182

@@ -186,6 +187,7 @@ class EditableTextBlock extends StatelessWidget {
186187
width: 32,
187188
offset: block.offset + line.offset,
188189
onTap: onCheckboxTap,
190+
uiBuilder: defaultStyles.lists!.checkboxUIBuilder,
189191
);
190192
}
191193

0 commit comments

Comments
 (0)