Skip to content

Commit

Permalink
Apply a fontWeight to icon in checkbox
Browse files Browse the repository at this point in the history
  • Loading branch information
bdlukaa committed Aug 20, 2022
1 parent cedd8f2 commit 88849b9
Showing 1 changed file with 92 additions and 1 deletion.
93 changes: 92 additions & 1 deletion lib/src/controls/inputs/checkbox.dart
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class Checkbox extends StatelessWidget {
style.checkedIconColor?.resolve(state) ??
FluentTheme.of(context).inactiveColor,
)
: Icon(
: _Icon(
style.icon,
size: 12,
color: () {
Expand Down Expand Up @@ -371,3 +371,94 @@ class CheckboxThemeData with Diagnosticable {
properties.add(DiagnosticsProperty<EdgeInsetsGeometry?>('margin', margin));
}
}

/// Copy if [Icon], with specified font weight
/// See /~https://github.com/bdlukaa/fluent_ui/issues/471
class _Icon extends StatelessWidget {
const _Icon(
this.icon, {
Key? key,
this.size,
this.color,
}) : super(key: key);

final IconData? icon;

final double? size;

final Color? color;

@override
Widget build(BuildContext context) {
assert(debugCheckHasDirectionality(context));
final TextDirection textDirection = Directionality.of(context);

final IconThemeData iconTheme = IconTheme.of(context);

final double? iconSize = size ?? iconTheme.size;

final List<Shadow>? iconShadows = iconTheme.shadows;

if (icon == null) {
return SizedBox(width: iconSize, height: iconSize);
}

final double iconOpacity = iconTheme.opacity ?? 1.0;
Color iconColor = color ?? iconTheme.color!;
if (iconOpacity != 1.0) {
iconColor = iconColor.withOpacity(iconColor.opacity * iconOpacity);
}

Widget iconWidget = RichText(
overflow: TextOverflow.visible, // Never clip.
textDirection:
textDirection, // Since we already fetched it for the assert...
text: TextSpan(
text: String.fromCharCode(icon!.codePoint),
style: TextStyle(
inherit: false,
color: iconColor,
fontSize: iconSize,
fontWeight: FontWeight.w900,
fontFamily: icon!.fontFamily,
package: icon!.fontPackage,
shadows: iconShadows,
),
),
);

if (icon!.matchTextDirection) {
switch (textDirection) {
case TextDirection.rtl:
iconWidget = Transform(
transform: Matrix4.identity()..scale(-1.0, 1.0, 1.0),
alignment: Alignment.center,
transformHitTests: false,
child: iconWidget,
);
break;
case TextDirection.ltr:
break;
}
}

return ExcludeSemantics(
child: SizedBox(
width: iconSize,
height: iconSize,
child: Center(
child: iconWidget,
),
),
);
}

@override
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties);
properties.add(
IconDataProperty('icon', icon, ifNull: '<empty>', showName: false));
properties.add(DoubleProperty('size', size, defaultValue: null));
properties.add(ColorProperty('color', color, defaultValue: null));
}
}

0 comments on commit 88849b9

Please sign in to comment.