Skip to content

Commit

Permalink
Add debug label to FThemeData (#313)
Browse files Browse the repository at this point in the history
* Tidy up themes

* Replace DoubleProperty with PercentageProperty

* More tweaks
  • Loading branch information
Pante authored Dec 17, 2024
1 parent d2e613c commit 22cb0ed
Show file tree
Hide file tree
Showing 17 changed files with 113 additions and 95 deletions.
4 changes: 3 additions & 1 deletion forui/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ Bump minimum Flutter version to 3.27.0.

* Add `FSelectMenuTile.builder`.

* Add `resizeToAvoidBottomInset` to `FScaffold(...)`.
* Add `FScaffold.resizeToAvoidBottomInset`.

* Add `FThemeData.debugLabel`.

### Changes

Expand Down
10 changes: 5 additions & 5 deletions forui/lib/src/theme/breakpoints.dart
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,10 @@ final class FBreakpoints with Diagnosticable {
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties);
properties
..add(DoubleProperty('sm', sm))
..add(DoubleProperty('md', md))
..add(DoubleProperty('lg', lg))
..add(DoubleProperty('xl', xl))
..add(DoubleProperty('xl2', xl2));
..add(DoubleProperty('sm', sm, defaultValue: 640))
..add(DoubleProperty('md', md, defaultValue: 768))
..add(DoubleProperty('lg', lg, defaultValue: 1024))
..add(DoubleProperty('xl', xl, defaultValue: 1280))
..add(DoubleProperty('xl2', xl2, defaultValue: 1536));
}
}
4 changes: 2 additions & 2 deletions forui/lib/src/theme/color_scheme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,8 @@ final class FColorScheme with Diagnosticable {
..add(ColorProperty('error', error))
..add(ColorProperty('errorForeground', errorForeground))
..add(ColorProperty('border', border))
..add(DoubleProperty('enabledHoveredOpacity', enabledHoveredOpacity))
..add(DoubleProperty('disabledOpacity', disabledOpacity));
..add(PercentProperty('enabledHoveredOpacity', enabledHoveredOpacity))
..add(PercentProperty('disabledOpacity', disabledOpacity));
}

@override
Expand Down
15 changes: 11 additions & 4 deletions forui/lib/src/theme/theme_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ import 'package:meta/meta.dart';
/// [FThemeData] and widget styles provide an `inherit(...)` constructor. The constructor configures the theme data/
/// widget style using the defaults provided by the [colorScheme], [typography], and [style].
final class FThemeData with Diagnosticable {
/// A label that is used in the [toString] output. Intended to aid with identifying themes in debug output.
final String? debugLabel;

/// The responsive breakpoints.
final FBreakpoints breakpoints;

Expand Down Expand Up @@ -152,19 +155,22 @@ final class FThemeData with Diagnosticable {
required this.textFieldStyle,
required this.tooltipStyle,
required this.tileGroupStyle,
this.debugLabel,
this.breakpoints = const FBreakpoints(),
this.typography = const FTypography(),
});

/// Creates a [FThemeData] that configures the widget styles using the given properties.
factory FThemeData.inherit({
required FColorScheme colorScheme,
String? debugLabel,
FStyle? style,
FTypography? typography,
}) {
typography ??= FTypography.inherit(colorScheme: colorScheme);
style ??= FStyle.inherit(colorScheme: colorScheme, typography: typography);
return FThemeData(
debugLabel: debugLabel,
colorScheme: colorScheme,
typography: typography,
style: style,
Expand Down Expand Up @@ -320,10 +326,11 @@ final class FThemeData with Diagnosticable {
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties);
properties
..add(DiagnosticsProperty('breakpoints', breakpoints, level: DiagnosticLevel.debug))
..add(DiagnosticsProperty('colorScheme', colorScheme, level: DiagnosticLevel.debug))
..add(DiagnosticsProperty('typography', typography, level: DiagnosticLevel.debug))
..add(DiagnosticsProperty('style', style, level: DiagnosticLevel.debug))
..add(StringProperty('debugLabel', debugLabel, showName: false))
..add(DiagnosticsProperty('breakpoints', breakpoints))
..add(DiagnosticsProperty('colorScheme', colorScheme))
..add(DiagnosticsProperty('typography', typography))
..add(DiagnosticsProperty('style', style))
..add(DiagnosticsProperty('accordionStyle', accordionStyle))
..add(DiagnosticsProperty('alertStyles', alertStyles, level: DiagnosticLevel.debug))
..add(DiagnosticsProperty('avatarStyle', avatarStyle, level: DiagnosticLevel.debug))
Expand Down
18 changes: 18 additions & 0 deletions forui/lib/src/theme/themes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ extension FThemes on Never {
/// The light and dark variants of the [Zinc](https://ui.shadcn.com/themes) theme.
static final zinc = (
light: FThemeData.inherit(
debugLabel: 'Zinc Light ThemeData',
colorScheme: const FColorScheme(
brightness: Brightness.light,
barrier: Color(0x33000000),
Expand All @@ -27,6 +28,7 @@ extension FThemes on Never {
),
),
dark: FThemeData.inherit(
debugLabel: 'Zinc Dark ThemeData',
colorScheme: const FColorScheme(
brightness: Brightness.dark,
barrier: Color(0x7A000000),
Expand All @@ -50,6 +52,7 @@ extension FThemes on Never {
/// The light and dark variants of the [Slate](https://ui.shadcn.com/themes) theme.
static final slate = (
light: FThemeData.inherit(
debugLabel: 'Slate Light ThemeData',
colorScheme: const FColorScheme(
brightness: Brightness.light,
barrier: Color(0x33000000),
Expand All @@ -69,6 +72,7 @@ extension FThemes on Never {
),
),
dark: FThemeData.inherit(
debugLabel: 'Slate Dark ThemeData',
colorScheme: const FColorScheme(
brightness: Brightness.dark,
barrier: Color(0x7A000000),
Expand All @@ -92,6 +96,7 @@ extension FThemes on Never {
/// The light and dark variants of the [Red](https://ui.shadcn.com/themes) theme.
static final red = (
light: FThemeData.inherit(
debugLabel: 'Red Light ThemeData',
colorScheme: const FColorScheme(
brightness: Brightness.light,
barrier: Color(0x33000000),
Expand All @@ -111,6 +116,7 @@ extension FThemes on Never {
),
),
dark: FThemeData.inherit(
debugLabel: 'Red Dark ThemeData',
colorScheme: const FColorScheme(
brightness: Brightness.dark,
barrier: Color(0x7A000000),
Expand All @@ -134,6 +140,7 @@ extension FThemes on Never {
/// The light and dark variants of the [Rose](https://ui.shadcn.com/themes) theme.
static final rose = (
light: FThemeData.inherit(
debugLabel: 'Rose Light ThemeData',
colorScheme: const FColorScheme(
brightness: Brightness.light,
barrier: Color(0x33000000),
Expand All @@ -153,6 +160,7 @@ extension FThemes on Never {
),
),
dark: FThemeData.inherit(
debugLabel: 'Rose Dark ThemeData',
colorScheme: const FColorScheme(
brightness: Brightness.dark,
barrier: Color(0x7A000000),
Expand All @@ -176,6 +184,7 @@ extension FThemes on Never {
/// The light and dark variants of the [Orange](https://ui.shadcn.com/themes) theme.
static final orange = (
light: FThemeData.inherit(
debugLabel: 'Orange Light ThemeData',
colorScheme: const FColorScheme(
brightness: Brightness.light,
barrier: Color(0x33000000),
Expand All @@ -195,6 +204,7 @@ extension FThemes on Never {
),
),
dark: FThemeData.inherit(
debugLabel: 'Orange Dark ThemeData',
colorScheme: const FColorScheme(
brightness: Brightness.dark,
barrier: Color(0x7A000000),
Expand All @@ -218,6 +228,7 @@ extension FThemes on Never {
/// The light and dark variants of the [Green](https://ui.shadcn.com/themes) theme.
static final green = (
light: FThemeData.inherit(
debugLabel: 'Green Light ThemeData',
colorScheme: const FColorScheme(
brightness: Brightness.light,
barrier: Color(0x33000000),
Expand All @@ -237,6 +248,7 @@ extension FThemes on Never {
),
),
dark: FThemeData.inherit(
debugLabel: 'Green Dark ThemeData',
colorScheme: const FColorScheme(
brightness: Brightness.dark,
barrier: Color(0x7A000000),
Expand All @@ -260,6 +272,7 @@ extension FThemes on Never {
/// The light and dark variants of the [Blue](https://ui.shadcn.com/themes) theme.
static final blue = (
light: FThemeData.inherit(
debugLabel: 'Blue Light ThemeData',
colorScheme: const FColorScheme(
brightness: Brightness.light,
barrier: Color(0x33000000),
Expand All @@ -279,6 +292,7 @@ extension FThemes on Never {
),
),
dark: FThemeData.inherit(
debugLabel: 'Blue Dark ThemeData',
colorScheme: const FColorScheme(
brightness: Brightness.dark,
barrier: Color(0x7A000000),
Expand All @@ -302,6 +316,7 @@ extension FThemes on Never {
/// The light and dark variants of the [Yellow](https://ui.shadcn.com/themes) theme.
static final yellow = (
light: FThemeData.inherit(
debugLabel: 'Yellow Light ThemeData',
colorScheme: const FColorScheme(
brightness: Brightness.light,
barrier: Color(0x33000000),
Expand All @@ -321,6 +336,7 @@ extension FThemes on Never {
),
),
dark: FThemeData.inherit(
debugLabel: 'Yellow Dark ThemeData',
colorScheme: const FColorScheme(
brightness: Brightness.dark,
barrier: Color(0x7A000000),
Expand All @@ -344,6 +360,7 @@ extension FThemes on Never {
/// The light and dark variants of the [Violet](https://ui.shadcn.com/themes) theme.
static final violet = (
light: FThemeData.inherit(
debugLabel: 'Violet Light ThemeData',
colorScheme: const FColorScheme(
brightness: Brightness.light,
barrier: Color(0x33000000),
Expand All @@ -363,6 +380,7 @@ extension FThemes on Never {
),
),
dark: FThemeData.inherit(
debugLabel: 'Violet Dark ThemeData',
colorScheme: const FColorScheme(
brightness: Brightness.dark,
barrier: Color(0x7A000000),
Expand Down
26 changes: 13 additions & 13 deletions forui/lib/src/theme/typography.dart
Original file line number Diff line number Diff line change
Expand Up @@ -228,19 +228,19 @@ final class FTypography with Diagnosticable {
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties);
properties
..add(StringProperty('family', defaultFontFamily, defaultValue: 'packages/forui/Inter'))
..add(DiagnosticsProperty('xs', xs, defaultValue: 12))
..add(DiagnosticsProperty('sm', sm, defaultValue: 14))
..add(DiagnosticsProperty('base', base, defaultValue: 16))
..add(DiagnosticsProperty('lg', lg, defaultValue: 18))
..add(DiagnosticsProperty('xl', xl, defaultValue: 20))
..add(DiagnosticsProperty('xl2', xl2, defaultValue: 22))
..add(DiagnosticsProperty('xl3', xl3, defaultValue: 30))
..add(DiagnosticsProperty('xl4', xl4, defaultValue: 36))
..add(DiagnosticsProperty('xl5', xl5, defaultValue: 48))
..add(DiagnosticsProperty('xl6', xl6, defaultValue: 60))
..add(DiagnosticsProperty('xl7', xl7, defaultValue: 72))
..add(DiagnosticsProperty('xl8', xl8, defaultValue: 96));
..add(StringProperty('defaultFontFamily', defaultFontFamily, defaultValue: 'packages/forui/Inter'))
..add(DiagnosticsProperty('xs', xs))
..add(DiagnosticsProperty('sm', sm))
..add(DiagnosticsProperty('base', base))
..add(DiagnosticsProperty('lg', lg))
..add(DiagnosticsProperty('xl', xl))
..add(DiagnosticsProperty('xl2', xl2))
..add(DiagnosticsProperty('xl3', xl3))
..add(DiagnosticsProperty('xl4', xl4))
..add(DiagnosticsProperty('xl5', xl5))
..add(DiagnosticsProperty('xl6', xl6))
..add(DiagnosticsProperty('xl7', xl7))
..add(DiagnosticsProperty('xl8', xl8));
}

@override
Expand Down
4 changes: 2 additions & 2 deletions forui/lib/src/widgets/accordion/accordion_item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ class _Expandable extends SingleChildRenderObjectWidget {
@override
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties);
properties.add(DoubleProperty('value', value));
properties.add(PercentProperty('value', value));
}
}

Expand Down Expand Up @@ -243,7 +243,7 @@ class _RenderExpandable extends RenderBox with RenderObjectWithChildMixin<Render
@override
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties);
properties.add(DoubleProperty('value', value));
properties.add(PercentProperty('value', value));
}
}

Expand Down
30 changes: 15 additions & 15 deletions forui/lib/src/widgets/calendar/calendar_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import 'package:sugar/sugar.dart';

bool _true(DateTime _) => true;

DateTime _stripTimezone(DateTime date) => DateTime.utc(date.year, date.month, date.day);
DateTime _truncateAndStripTimezone(DateTime date) => DateTime.utc(date.year, date.month, date.day);

/// A controller that controls date selection in a calendar.
///
Expand Down Expand Up @@ -124,22 +124,22 @@ class _AutoDateController extends FCalendarController<DateTime?> {
DateTime? initialSelection,
Predicate<DateTime>? selectable,
}) : _selectable = selectable ?? _true,
super(initialSelection = initialSelection == null ? null : _stripTimezone(initialSelection));
super(initialSelection = initialSelection == null ? null : _truncateAndStripTimezone(initialSelection));

@override
bool selectable(DateTime date) => _selectable(_stripTimezone(date));
bool selectable(DateTime date) => _selectable(_truncateAndStripTimezone(date));

@override
bool selected(DateTime date) => value == _stripTimezone(date);
bool selected(DateTime date) => value == _truncateAndStripTimezone(date);

@override
void select(DateTime date) {
date = _stripTimezone(date);
date = _truncateAndStripTimezone(date);
super.value = value == date ? null : date;
}

@override
set value(DateTime? value) => super.value = value == null ? null : _stripTimezone(value);
set value(DateTime? value) => super.value = value == null ? null : _truncateAndStripTimezone(value);
}

class _DateController extends FCalendarController<DateTime?> {
Expand Down Expand Up @@ -170,22 +170,22 @@ final class _AutoDatesController extends FCalendarController<Set<DateTime>> {
Set<DateTime> initialSelections = const {},
Predicate<DateTime>? selectable,
}) : _selectable = selectable ?? _true,
super(initialSelections.map(_stripTimezone).toSet());
super(initialSelections.map(_truncateAndStripTimezone).toSet());

@override
bool selectable(DateTime date) => _selectable(_stripTimezone(date));
bool selectable(DateTime date) => _selectable(_truncateAndStripTimezone(date));

@override
bool selected(DateTime date) => value.contains(_stripTimezone(date));
bool selected(DateTime date) => value.contains(_truncateAndStripTimezone(date));

@override
void select(DateTime date) {
final copy = {...value};
super.value = copy..toggle(_stripTimezone(date));
super.value = copy..toggle(_truncateAndStripTimezone(date));
}

@override
set value(Set<DateTime> value) => super.value = value.map(_stripTimezone).toSet();
set value(Set<DateTime> value) => super.value = value.map(_truncateAndStripTimezone).toSet();
}

final class _DatesController extends FCalendarController<Set<DateTime>> {
Expand Down Expand Up @@ -219,7 +219,7 @@ final class _AutoRangeController extends FCalendarController<(DateTime, DateTime
super(
initialSelection = initialSelection == null
? null
: (_stripTimezone(initialSelection.$1), _stripTimezone(initialSelection.$2)),
: (_truncateAndStripTimezone(initialSelection.$1), _truncateAndStripTimezone(initialSelection.$2)),
) {
final range = value;
assert(
Expand All @@ -229,7 +229,7 @@ final class _AutoRangeController extends FCalendarController<(DateTime, DateTime
}

@override
bool selectable(DateTime date) => _selectable(_stripTimezone(date));
bool selectable(DateTime date) => _selectable(_truncateAndStripTimezone(date));

@override
bool selected(DateTime date) {
Expand All @@ -243,7 +243,7 @@ final class _AutoRangeController extends FCalendarController<(DateTime, DateTime

@override
void select(DateTime date) {
date = _stripTimezone(date);
date = _truncateAndStripTimezone(date);
if (value == null) {
super.value = (date, date);
return;
Expand All @@ -265,7 +265,7 @@ final class _AutoRangeController extends FCalendarController<(DateTime, DateTime

@override
set value((DateTime, DateTime)? value) =>
super.value = value == null ? null : (_stripTimezone(value.$1), _stripTimezone(value.$2));
super.value = value == null ? null : (_truncateAndStripTimezone(value.$1), _truncateAndStripTimezone(value.$2));
}

final class _RangeController extends FCalendarController<(DateTime, DateTime)?> {
Expand Down
2 changes: 1 addition & 1 deletion forui/lib/src/widgets/progress.dart
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class FProgress extends StatelessWidget {
super.debugFillProperties(properties);
properties
..add(DiagnosticsProperty('style', style))
..add(DoubleProperty('value', value));
..add(PercentProperty('value', value));
}
}

Expand Down
Loading

0 comments on commit 22cb0ed

Please sign in to comment.