Skip to content

Commit 7c3f6cc

Browse files
EchoElletEllet
andauthored
Feature/change icon button data (#1634)
* Add a way to change almost properties of IconButton in QuillIconTheme for both selected and unselected state --------- Co-authored-by: Ellet <[email protected]>
1 parent a4dd9b5 commit 7c3f6cc

File tree

20 files changed

+214
-46
lines changed

20 files changed

+214
-46
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
All notable changes to this project will be documented in this file.
44

5+
## 9.1.0
6+
* Fix the simple toolbar by add properties of `IconButton` and fix some buttons
7+
58
## 9.1.0-dev.2
69
* Fix the history buttons
710

example/lib/presentation/quill/my_quill_toolbar.dart

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,24 @@ class MyQuillToolbar extends StatelessWidget {
202202
controller: controller,
203203
showAlignmentButtons: true,
204204
multiRowsDisplay: true,
205+
buttonOptions: QuillSimpleToolbarButtonOptions(
206+
base: QuillToolbarBaseButtonOptions(
207+
afterButtonPressed: focusNode.requestFocus
208+
// globalIconSize: 20,
209+
// iconTheme: QuillIconTheme(
210+
// iconButtonSelectedData: IconButtonData(
211+
// style: IconButton.styleFrom(
212+
// foregroundColor: Colors.amberAccent,
213+
// ),
214+
// ),
215+
// iconButtonUnselectedData: IconButtonData(
216+
// style: IconButton.styleFrom(
217+
// foregroundColor: Colors.amberAccent,
218+
// ),
219+
// ),
220+
// ),
221+
),
222+
),
205223
customButtons: [
206224
QuillToolbarCustomButtonOptions(
207225
icon: const Icon(Icons.add_alarm_rounded),

flutter_quill_extensions/lib/embeds/formula/toolbar/formula_button.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ class QuillToolbarFormulaButton extends StatelessWidget {
9494
tooltip: tooltip,
9595
onPressed: () => _sharedOnPressed(context),
9696
isSelected: false,
97+
iconTheme: iconTheme,
9798
);
9899
}
99100

flutter_quill_extensions/lib/embeds/image/toolbar/image_button.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,7 @@ class QuillToolbarImageButton extends StatelessWidget {
104104
tooltip: tooltip,
105105
isSelected: false,
106106
onPressed: () => _sharedOnPressed(context),
107-
iconSelectedStyle: _iconTheme(context)?.iconButtonSelectedStyle,
108-
iconUnselectedStyle: _iconTheme(context)?.iconButtonUnselectedStyle,
107+
iconTheme: _iconTheme(context),
109108
);
110109
}
111110

flutter_quill_extensions/lib/embeds/others/camera_button/camera_button.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,7 @@ class QuillToolbarCameraButton extends StatelessWidget {
112112
isSelected: false,
113113
// isDesktop(supportWeb: false) ? null :
114114
onPressed: () => _sharedOnPressed(context),
115-
iconSelectedStyle: iconTheme?.iconButtonSelectedStyle,
116-
iconUnselectedStyle: iconTheme?.iconButtonUnselectedStyle,
115+
iconTheme: iconTheme,
117116
);
118117
}
119118

flutter_quill_extensions/lib/embeds/video/toolbar/video_button.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,7 @@ class QuillToolbarVideoButton extends StatelessWidget {
109109
tooltip: tooltip,
110110
isSelected: false,
111111
onPressed: () => _sharedOnPressed(context),
112-
iconSelectedStyle: _iconTheme(context)?.iconButtonSelectedStyle,
113-
iconUnselectedStyle: _iconTheme(context)?.iconButtonUnselectedStyle,
112+
iconTheme: _iconTheme(context),
114113
);
115114
}
116115

Lines changed: 107 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,121 @@
1+
// ignore_for_file: public_member_api_docs, sort_constructors_first
12
import 'package:flutter/material.dart';
23

34
@immutable
45
class QuillIconTheme {
56
const QuillIconTheme({
6-
this.padding,
77
this.iconButtonSelectedStyle,
88
this.iconButtonUnselectedStyle,
9-
// this.iconSelectedFillColor,
10-
// this.iconUnselectedFillColor,
9+
this.iconButtonSelectedData,
10+
this.iconButtonUnselectedData,
1111
});
1212

13+
@Deprecated('Please use iconButtonUnselectedData instead')
1314
final ButtonStyle? iconButtonUnselectedStyle;
15+
@Deprecated('Please use iconButtonSelectedData instead')
1416
final ButtonStyle? iconButtonSelectedStyle;
1517

16-
// final Color? iconSelectedFillColor;
17-
// final Color? iconUnselectedFillColor;
18+
final IconButtonData? iconButtonUnselectedData;
19+
final IconButtonData? iconButtonSelectedData;
20+
21+
QuillIconTheme copyWith({
22+
IconButtonData? iconButtonUnselectedData,
23+
IconButtonData? iconButtonSelectedData,
24+
}) {
25+
return QuillIconTheme(
26+
iconButtonUnselectedData:
27+
iconButtonUnselectedData ?? this.iconButtonUnselectedData,
28+
iconButtonSelectedData:
29+
iconButtonSelectedData ?? this.iconButtonSelectedData,
30+
);
31+
}
32+
}
33+
34+
@immutable
35+
class IconButtonData {
36+
const IconButtonData({
37+
this.iconSize,
38+
this.visualDensity,
39+
this.padding,
40+
this.alignment,
41+
this.splashRadius,
42+
this.color,
43+
this.focusColor,
44+
this.hoverColor,
45+
this.highlightColor,
46+
this.splashColor,
47+
this.disabledColor,
48+
this.mouseCursor,
49+
this.autofocus = false,
50+
this.tooltip,
51+
this.enableFeedback,
52+
this.constraints,
53+
this.style,
54+
this.isSelected,
55+
this.selectedIcon,
56+
});
57+
58+
final double? iconSize;
59+
final VisualDensity? visualDensity;
60+
final EdgeInsetsGeometry? padding;
61+
final AlignmentGeometry? alignment;
62+
final double? splashRadius;
63+
final Color? color;
64+
final Color? focusColor;
65+
final Color? hoverColor;
66+
final Color? highlightColor;
67+
final Color? splashColor;
68+
final Color? disabledColor;
69+
final MouseCursor? mouseCursor;
70+
final bool autofocus;
71+
final String? tooltip;
72+
final bool? enableFeedback;
73+
final BoxConstraints? constraints;
74+
final ButtonStyle? style;
75+
final bool? isSelected;
76+
final Widget? selectedIcon;
1877

19-
///The padding for icons
20-
final EdgeInsets? padding;
78+
IconButtonData copyWith({
79+
double? iconSize,
80+
VisualDensity? visualDensity,
81+
EdgeInsetsGeometry? padding,
82+
AlignmentGeometry? alignment,
83+
double? splashRadius,
84+
Color? color,
85+
Color? focusColor,
86+
Color? hoverColor,
87+
Color? highlightColor,
88+
Color? splashColor,
89+
Color? disabledColor,
90+
MouseCursor? mouseCursor,
91+
bool? autofocus,
92+
String? tooltip,
93+
bool? enableFeedback,
94+
BoxConstraints? constraints,
95+
ButtonStyle? style,
96+
bool? isSelected,
97+
Widget? selectedIcon,
98+
}) {
99+
return IconButtonData(
100+
iconSize: iconSize ?? this.iconSize,
101+
visualDensity: visualDensity ?? this.visualDensity,
102+
padding: padding ?? this.padding,
103+
alignment: alignment ?? this.alignment,
104+
splashRadius: splashRadius ?? this.splashRadius,
105+
color: color ?? this.color,
106+
focusColor: focusColor ?? this.focusColor,
107+
hoverColor: hoverColor ?? this.hoverColor,
108+
highlightColor: highlightColor ?? this.highlightColor,
109+
splashColor: splashColor ?? this.splashColor,
110+
disabledColor: disabledColor ?? this.disabledColor,
111+
mouseCursor: mouseCursor ?? this.mouseCursor,
112+
autofocus: autofocus ?? this.autofocus,
113+
tooltip: tooltip ?? this.tooltip,
114+
enableFeedback: enableFeedback ?? this.enableFeedback,
115+
constraints: constraints ?? this.constraints,
116+
style: style ?? this.style,
117+
isSelected: isSelected ?? this.isSelected,
118+
selectedIcon: selectedIcon ?? this.selectedIcon,
119+
);
120+
}
21121
}

lib/src/widgets/toolbar/buttons/clear_format_button.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ class QuillToolbarClearFormatButton extends StatelessWidget {
114114
isSelected: false,
115115
onPressed: _sharedOnPressed,
116116
afterPressed: afterButtonPressed,
117-
iconUnselectedStyle: iconTheme?.iconButtonUnselectedStyle,
117+
iconTheme: iconTheme,
118118
);
119119
}
120120
}

lib/src/widgets/toolbar/buttons/color/color_button.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,12 +193,14 @@ class QuillToolbarColorButtonState extends State<QuillToolbarColorButton> {
193193
);
194194
}
195195

196-
return IconButton(
196+
return QuillToolbarIconButton(
197197
tooltip: tooltip,
198-
iconSize: iconSize * iconButtonFactor,
198+
isSelected: false,
199+
iconTheme: iconTheme,
199200
icon: Icon(
200201
iconData,
201202
color: widget.isBackground ? iconColorBackground : iconColor,
203+
size: iconSize * iconButtonFactor,
202204
),
203205
onPressed: _showColorPicker,
204206
);

lib/src/widgets/toolbar/buttons/custom_button_button.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ class QuillToolbarCustomButton extends StatelessWidget {
8585
tooltip: tooltip,
8686
onPressed: () => _onPressed(context),
8787
afterPressed: afterButtonPressed,
88+
iconTheme: iconTheme,
8889
);
8990
}
9091
}

0 commit comments

Comments
 (0)