Skip to content

Commit

Permalink
fix(theme): Material Check/Radio color (#871)
Browse files Browse the repository at this point in the history
Fixes #870
  • Loading branch information
Feichtmeier committed Mar 4, 2024
1 parent eb88458 commit 116e36f
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 5 deletions.
31 changes: 30 additions & 1 deletion example/lib/pages/theme_page/src/controls/toggleables.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,38 @@ import 'package:flutter/material.dart';

import '../constants.dart';

class Toggleables extends StatelessWidget {
class Toggleables extends StatefulWidget {
const Toggleables({super.key});

@override
State<Toggleables> createState() => _ToggleablesState();
}

class _ToggleablesState extends State<Toggleables> {
@override
void initState() {
super.initState();
WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
ScaffoldMessenger.of(context).showMaterialBanner(
MaterialBanner(
content: const Padding(
padding: EdgeInsets.all(8.0),
child: Text(
'Info: those are just Fallback toggleables. Please use YaruCheckBox and YaruRadio instead',
),
),
actions: [
TextButton(
onPressed: () =>
ScaffoldMessenger.of(context).clearMaterialBanners(),
child: const Text('OK'),
),
],
),
);
});
}

@override
Widget build(BuildContext context) {
return Wrap(
Expand Down
24 changes: 20 additions & 4 deletions lib/src/themes/common_themes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -398,12 +398,16 @@ Color _getSwitchTrackColor(Set<MaterialState> states, ColorScheme colorScheme) {

// Checks & Radios

Color _getCheckFillColor(Set<MaterialState> states, ColorScheme colorScheme) {
Color _getToggleFillColor({
required Set<MaterialState> states,
required ColorScheme colorScheme,
required bool radio,
}) {
if (!states.contains(MaterialState.disabled)) {
if (states.contains(MaterialState.selected)) {
return colorScheme.primary;
}
return colorScheme.onSurface.withOpacity(0.75);
return colorScheme.onSurface.withOpacity(radio ? 0.5 : 0.14);
}
if (states.contains(MaterialState.selected)) {
return colorScheme.onSurface.withOpacity(0.2);
Expand All @@ -426,8 +430,16 @@ CheckboxThemeData _createCheckBoxTheme(ColorScheme colorScheme) {
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(kCheckRadius),
),
side: BorderSide(
color: colorScheme.outline
.scale(lightness: colorScheme.isLight ? -0.6 : 0.5),
),
fillColor: MaterialStateProperty.resolveWith(
(states) => _getCheckFillColor(states, colorScheme),
(states) => _getToggleFillColor(
states: states,
colorScheme: colorScheme,
radio: false,
),
),
checkColor: MaterialStateProperty.resolveWith(
(states) => _getCheckColor(states, colorScheme),
Expand All @@ -438,7 +450,11 @@ CheckboxThemeData _createCheckBoxTheme(ColorScheme colorScheme) {
RadioThemeData _createRadioTheme(ColorScheme colorScheme) {
return RadioThemeData(
fillColor: MaterialStateProperty.resolveWith(
(states) => _getCheckFillColor(states, colorScheme),
(states) => _getToggleFillColor(
states: states,
colorScheme: colorScheme,
radio: true,
),
),
);
}
Expand Down

0 comments on commit 116e36f

Please sign in to comment.