Skip to content

Commit

Permalink
3
Browse files Browse the repository at this point in the history
  • Loading branch information
Ellet committed Dec 5, 2023
1 parent b513bf2 commit b074484
Show file tree
Hide file tree
Showing 15 changed files with 30 additions and 115 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,11 @@ class QuillToolbarFormulaButton extends StatelessWidget {
options.childBuilder ?? baseButtonExtraOptions(context).childBuilder;

final iconColor = iconTheme?.iconUnselectedColor ?? theme.iconTheme.color;
final iconFillColor = iconTheme?.iconUnselectedFillColor ??
(options.fillColor ?? theme.canvasColor);

if (childBuilder != null) {
return childBuilder(
QuillToolbarFormulaButtonOptions(
afterButtonPressed: _afterButtonPressed(context),
fillColor: iconFillColor,
iconData: iconData,
iconSize: iconSize,
iconButtonFactor: iconButtonFactor,
Expand All @@ -96,12 +93,9 @@ class QuillToolbarFormulaButton extends StatelessWidget {
return QuillToolbarIconButton(
icon: Icon(iconData, size: iconSize, color: iconColor),
tooltip: tooltip,
highlightElevation: 0,
hoverElevation: 0,
size: iconSize * 1.77,
fillColor: iconFillColor,
borderRadius: iconTheme?.borderRadius ?? 2,
onPressed: () => _sharedOnPressed(context),
isFilled: false,
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,6 @@ class QuillToolbarImageButton extends StatelessWidget {
final iconTheme = _iconTheme(context);

final iconColor = iconTheme?.iconUnselectedColor ?? theme.iconTheme.color;
final iconFillColor = iconTheme?.iconUnselectedFillColor ??
(options.fillColor ?? theme.canvasColor);

return QuillToolbarIconButton(
icon: Icon(
Expand All @@ -111,11 +109,8 @@ class QuillToolbarImageButton extends StatelessWidget {
color: iconColor,
),
tooltip: tooltip,
highlightElevation: 0,
hoverElevation: 0,
size: iconSize * 1.77,
fillColor: iconFillColor,
borderRadius: iconTheme?.borderRadius ?? 2,
isFilled: false,
onPressed: () => _sharedOnPressed(context),
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,17 +96,12 @@ class QuillToolbarCameraButton extends StatelessWidget {
final theme = Theme.of(context);

final iconColor = iconTheme?.iconUnselectedColor ?? theme.iconTheme.color;
final iconFillColor = iconTheme?.iconUnselectedFillColor ??
(options.fillColor ?? theme.canvasColor);

return QuillToolbarIconButton(
icon: Icon(iconData, size: iconSize, color: iconColor),
tooltip: tooltip,
highlightElevation: 0,
hoverElevation: 0,
size: iconSize * 1.77,
fillColor: iconFillColor,
borderRadius: iconTheme?.borderRadius ?? 2,
isFilled: false,
// isDesktop(supportWeb: false) ? null :
onPressed: () => _sharedOnPressed(context),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,8 @@ class QuillToolbarVideoButton extends StatelessWidget {
return QuillToolbarIconButton(
icon: Icon(iconData, size: iconSize, color: iconColor),
tooltip: tooltip,
highlightElevation: 0,
hoverElevation: 0,
size: iconSize * 1.77,
fillColor: iconFillColor,
borderRadius: iconTheme?.borderRadius ?? 2,
isFilled: false,
onPressed: () => _sharedOnPressed(context),
);
}
Expand Down
6 changes: 1 addition & 5 deletions lib/src/widgets/toolbar/buttons/clear_format.dart
Original file line number Diff line number Diff line change
Expand Up @@ -108,16 +108,12 @@ class QuillToolbarClearFormatButton extends StatelessWidget {
final theme = Theme.of(context);

final iconColor = iconTheme?.iconUnselectedColor ?? theme.iconTheme.color;
final fillColor = iconTheme?.iconUnselectedFillColor ?? theme.canvasColor;

return QuillToolbarIconButton(
tooltip: tooltip,
highlightElevation: 0,
hoverElevation: 0,
size: iconSize * iconButtonFactor,
icon: Icon(iconData, size: iconSize, color: iconColor),
fillColor: fillColor,
borderRadius: iconTheme?.borderRadius ?? 2,
isFilled: false,
onPressed: _sharedOnPressed,
afterPressed: afterButtonPressed,
);
Expand Down
6 changes: 2 additions & 4 deletions lib/src/widgets/toolbar/buttons/color/color.dart
Original file line number Diff line number Diff line change
Expand Up @@ -195,14 +195,12 @@ class QuillToolbarColorButtonState extends State<QuillToolbarColorButton> {

return QuillToolbarIconButton(
tooltip: tooltip,
highlightElevation: 0,
hoverElevation: 0,
size: iconSize * iconButtonFactor,
icon: Icon(iconData,
size: iconSize,
color: widget.isBackground ? iconColorBackground : iconColor),
fillColor: widget.isBackground ? fillColorBackground : fillColor,
borderRadius: iconTheme?.borderRadius ?? 2,
// fillColor: widget.isBackground ? fillColorBackground : fillColor,
isFilled: false,
onPressed: _showColorPicker,
afterPressed: afterButtonPressed,
);
Expand Down
6 changes: 2 additions & 4 deletions lib/src/widgets/toolbar/buttons/custom_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,13 @@ class QuillToolbarCustomButton extends StatelessWidget {
);
}

final theme = Theme.of(context);
return QuillToolbarIconButton(
size: iconSize * iconButtonFactor,
icon: options.icon,
icon: options.icon ?? const SizedBox.shrink(),
isFilled: false,
tooltip: tooltip,
borderRadius: iconTheme?.borderRadius ?? 2,
onPressed: () => _onPressed(context),
afterPressed: afterButtonPressed,
fillColor: iconTheme?.iconUnselectedFillColor ?? theme.canvasColor,
);
}
}
7 changes: 1 addition & 6 deletions lib/src/widgets/toolbar/buttons/history.dart
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,8 @@ class QuillToolbarHistoryButtonState extends State<QuillToolbarHistoryButton> {
}

theme = Theme.of(context);

final fillColor = iconTheme?.iconUnselectedFillColor ?? theme.canvasColor;
return QuillToolbarIconButton(
tooltip: tooltip,
highlightElevation: 0,
hoverElevation: 0,
size: iconSize * iconButtonFactor,
icon: Icon(
iconData,
Expand All @@ -107,8 +103,7 @@ class QuillToolbarHistoryButtonState extends State<QuillToolbarHistoryButton> {
? iconTheme?.iconUnselectedColor ?? theme.iconTheme.color
: iconTheme?.disabledIconColor ?? theme.disabledColor,
),
fillColor: fillColor,
borderRadius: iconTheme?.borderRadius ?? 2,
isFilled: false,
onPressed: _updateHistory,
afterPressed: afterButtonPressed,
);
Expand Down
7 changes: 1 addition & 6 deletions lib/src/widgets/toolbar/buttons/indent.dart
Original file line number Diff line number Diff line change
Expand Up @@ -107,16 +107,11 @@ class QuillToolbarIndentButtonState extends State<QuillToolbarIndentButton> {
final theme = Theme.of(context);

final iconColor = iconTheme?.iconUnselectedColor ?? theme.iconTheme.color;
final iconFillColor =
iconTheme?.iconUnselectedFillColor ?? theme.canvasColor;
return QuillToolbarIconButton(
tooltip: tooltip,
highlightElevation: 0,
hoverElevation: 0,
size: iconSize * iconButtonFactor,
icon: Icon(iconData, size: iconSize, color: iconColor),
fillColor: iconFillColor,
borderRadius: iconTheme?.borderRadius ?? 2,
isFilled: false,
onPressed: _sharedOnPressed,
afterPressed: afterButtonPressed,
);
Expand Down
7 changes: 1 addition & 6 deletions lib/src/widgets/toolbar/buttons/link_style.dart
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,6 @@ class QuillToolbarLinkStyleButtonState
final theme = Theme.of(context);
return QuillToolbarIconButton(
tooltip: tooltip,
highlightElevation: 0,
hoverElevation: 0,
size: iconSize * iconButtonFactor,
icon: Icon(
iconData,
Expand All @@ -151,10 +149,7 @@ class QuillToolbarLinkStyleButtonState
? (iconTheme?.iconSelectedColor ?? theme.primaryIconTheme.color)
: (iconTheme?.iconUnselectedColor ?? theme.iconTheme.color),
),
fillColor: isToggled
? (iconTheme?.iconSelectedFillColor ?? theme.primaryColor)
: (iconTheme?.iconUnselectedFillColor ?? theme.canvasColor),
borderRadius: iconTheme?.borderRadius ?? 2,
isFilled: isToggled,
onPressed: () => _openLinkDialog(context),
afterPressed: afterButtonPressed,
);
Expand Down
7 changes: 1 addition & 6 deletions lib/src/widgets/toolbar/buttons/link_style2.dart
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,6 @@ class _QuillToolbarLinkStyleButton2State
final isToggled = _getLinkAttributeValue() != null;
return QuillToolbarIconButton(
tooltip: tooltip,
highlightElevation: 0,
hoverElevation: 0,
size: iconSize * iconButtonFactor,
icon: Icon(
iconData,
Expand All @@ -158,10 +156,7 @@ class _QuillToolbarLinkStyleButton2State
? (iconTheme?.iconSelectedColor ?? theme.primaryIconTheme.color)
: (iconTheme?.iconUnselectedColor ?? theme.iconTheme.color),
),
fillColor: isToggled
? (iconTheme?.iconSelectedFillColor ?? theme.primaryColor)
: (iconTheme?.iconUnselectedFillColor ?? theme.canvasColor),
borderRadius: iconTheme?.borderRadius ?? 2,
isFilled: isToggled,
onPressed: _openLinkDialog,
afterPressed: afterButtonPressed,
);
Expand Down
42 changes: 10 additions & 32 deletions lib/src/widgets/toolbar/buttons/quill_icon.dart
Original file line number Diff line number Diff line change
@@ -1,54 +1,32 @@
import 'package:flutter/material.dart';

import '../../../utils/widgets.dart';

class QuillToolbarIconButton extends StatelessWidget {
const QuillToolbarIconButton({
required this.onPressed,
required this.icon,
required this.isFilled,
this.afterPressed,
this.icon,
this.size = 40,
this.fillColor,
this.hoverElevation = 1,
this.highlightElevation = 1,
this.borderRadius = 2,
this.tooltip,
super.key,
});

final VoidCallback? onPressed;
final VoidCallback? afterPressed;
final Widget? icon;
final Widget icon;

final double size;
final Color? fillColor;
final double hoverElevation;
final double highlightElevation;
final double borderRadius;
final String? tooltip;
final bool isFilled;

@override
Widget build(BuildContext context) {
return ConstrainedBox(
constraints: BoxConstraints.tightFor(width: size, height: size),
child: UtilityWidgets.maybeTooltip(
message: tooltip,
child: RawMaterialButton(
visualDensity: VisualDensity.compact,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(borderRadius),
),
fillColor: fillColor,
elevation: 0,
hoverElevation: hoverElevation,
highlightElevation: hoverElevation,
onPressed: () {
onPressed?.call();
afterPressed?.call();
},
child: icon,
),
),
if (isFilled) {
return IconButton.filled(onPressed: onPressed, icon: icon);
}
return IconButton(
onPressed: onPressed,
icon: icon,
);
}
}
7 changes: 1 addition & 6 deletions lib/src/widgets/toolbar/buttons/search/search.dart
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,6 @@ class QuillToolbarSearchButton extends StatelessWidget {
final theme = Theme.of(context);

final iconColor = iconTheme?.iconUnselectedColor ?? theme.iconTheme.color;
final iconFillColor = iconTheme?.iconUnselectedFillColor ??
(options.fillColor ?? theme.canvasColor);

return QuillToolbarIconButton(
tooltip: tooltip,
Expand All @@ -121,11 +119,8 @@ class QuillToolbarSearchButton extends StatelessWidget {
size: iconSize,
color: iconColor,
),
highlightElevation: 0,
hoverElevation: 0,
size: iconSize * iconButtonFactor,
fillColor: iconFillColor,
borderRadius: iconTheme?.borderRadius ?? 2,
isFilled: false,
onPressed: () => _sharedOnPressed(context),
afterPressed: afterButtonPressed,
);
Expand Down
13 changes: 1 addition & 12 deletions lib/src/widgets/toolbar/buttons/toggle_style.dart
Original file line number Diff line number Diff line change
Expand Up @@ -241,22 +241,11 @@ Widget defaultToggleStyleButtonBuilder(
.primaryIconTheme.color) //You can specify your own icon color
: (iconTheme?.iconUnselectedColor ?? theme.iconTheme.color)
: (iconTheme?.disabledIconColor ?? theme.disabledColor);
final fill = isEnabled
? isToggled == true
? (iconTheme?.iconSelectedFillColor ??
Theme.of(context).primaryColor) //Selected icon fill color
: (iconTheme?.iconUnselectedFillColor ??
theme.canvasColor) //Unselected icon fill color :
: (iconTheme?.disabledIconFillColor ??
(fillColor ?? theme.canvasColor)); //Disabled icon fill color
return QuillToolbarIconButton(
highlightElevation: 0,
hoverElevation: 0,
size: iconSize * iconButtonFactor,
icon: Icon(icon, size: iconSize, color: iconColor),
fillColor: fill,
isFilled: isEnabled ? isToggled == true : false,
onPressed: onPressed,
afterPressed: afterPressed,
borderRadius: iconTheme?.borderRadius ?? 2,
);
}
10 changes: 5 additions & 5 deletions test/bug_fix_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,19 @@ void main() {
matchRoot: true,
);
expect(builtinFinder, findsOneWidget);
final builtinButton =
builtinFinder.evaluate().first.widget as QuillToolbarIconButton;
// final builtinButton =
// builtinFinder.evaluate().first.widget as QuillToolbarIconButton;

final customFinder = find.descendant(
of: find.byType(QuillBaseToolbar),
matching: find.byWidgetPredicate((widget) =>
widget is QuillToolbarIconButton && widget.tooltip == tooltip),
matchRoot: true);
expect(customFinder, findsOneWidget);
final customButton =
customFinder.evaluate().first.widget as QuillToolbarIconButton;
// final customButton =
// customFinder.evaluate().first.widget as QuillToolbarIconButton;

expect(customButton.fillColor, equals(builtinButton.fillColor));
// expect(customButton.fillColor, equals(builtinButton.fillColor));
});
});

Expand Down

0 comments on commit b074484

Please sign in to comment.