Skip to content

Commit dab4043

Browse files
committed
refactor: customize form component themes and update layout
This commit introduces a centralized `FormThemes` widget to override the default styles of form components (Checkbox, Radio, RadioCard, Slider, and Switch) and updates the global theme state with specific border and input colors. ### Key Changes: * **Theme State Updates (`lib/theme/cubit/theme_state.dart`):** * Added `border` and `input` color definitions to both light and dark `ColorScheme` configurations to ensure consistent UI framing. * **New Form Theme Overrides (`lib/screens/widgets/overrides/form_themes.dart`):** * Created `FormThemes` widget using `ComponentTheme` to provide custom styling for common form elements. * Implemented adaptive styling for `Checkbox`, `Radio`, `RadioCard`, `Slider`, and `Switch` that reacts to the current dark/light mode state. * **Layout Integration (`lib/screens/widgets/layouts/override_theme_layout.dart`):** * Wrapped the application's base layout with the new `FormThemes` provider to apply the custom styles across the application. * **Cleanup (`lib/screens/components/forms/forms_screen.dart`):** * Removed a redundant `Switch` example from the `FormsScreen` documentation/example page.
1 parent b3773b6 commit dab4043

4 files changed

Lines changed: 64 additions & 31 deletions

File tree

lib/screens/components/forms/forms_screen.dart

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -493,35 +493,6 @@ class _FormsScreenState extends State<FormsScreen> {
493493
],
494494
).withPadding(horizontal: 10),
495495
Gap(20),
496-
CodeCard(
497-
title: 'Toggle Switch',
498-
example: Switch(
499-
value: toggleValue,
500-
onChanged: (value) {
501-
setState(() {
502-
toggleValue = value;
503-
});
504-
},
505-
leading: const Text('Option 1'),
506-
trailing: const Text('Option 2'),
507-
),
508-
lines: [
509-
CodeCommentLine("# Am Anfang der Klasse angeben"),
510-
CodeTextLine("bool toggleValue = false;"),
511-
CodeCommentLine("# Beispiel für Toggle Switches"),
512-
CodeTextLine("Switch("),
513-
CodeTextLine(" value: toggleValue,"),
514-
CodeTextLine(" onChanged: (value) {"),
515-
CodeTextLine(" setState(() {"),
516-
CodeTextLine(" toggleValue = value;"),
517-
CodeTextLine(" });"),
518-
CodeTextLine(" },"),
519-
CodeTextLine(" leading: const Text('Option 1'),"),
520-
CodeTextLine(" trailing: const Text('Option 2'),"),
521-
CodeTextLine("),"),
522-
],
523-
).withPadding(horizontal: 10),
524-
Gap(20),
525496
CodeCard(
526497
title: 'Slider',
527498
example: Column(

lib/screens/widgets/layouts/override_theme_layout.dart

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import 'package:police_flutter_template/screens/widgets/overrides/form_themes.dart';
12
import 'package:shadcn_flutter/shadcn_flutter.dart';
23

34
import '../overrides/button_themes.dart';
@@ -11,8 +12,10 @@ class OverrideThemeLayout extends StatelessWidget {
1112

1213
@override
1314
Widget build(BuildContext context) {
14-
return ButtonThemes(
15-
child: ContainerThemes(child: CardThemes(child: child)),
15+
return FormThemes(
16+
child: ButtonThemes(
17+
child: ContainerThemes(child: CardThemes(child: child)),
18+
),
1619
);
1720
}
1821
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import 'package:flutter_bloc/flutter_bloc.dart';
2+
import 'package:shadcn_flutter/shadcn_flutter.dart';
3+
4+
import '../../../theme/cubit/theme_cubit.dart';
5+
6+
class FormThemes extends StatelessWidget {
7+
const FormThemes({super.key, required this.child});
8+
9+
final Widget child;
10+
11+
@override
12+
Widget build(BuildContext context) {
13+
final isDark = context.watch<ThemeCubit>().state.isDarkMode;
14+
return ComponentTheme(
15+
data: CheckboxTheme(
16+
backgroundColor: isDark ? Colors.gray[800] : Colors.white,
17+
activeColor: isDark ? Colors.gray[500] : Colors.blue[900],
18+
borderColor: isDark ? Colors.gray[100] : Colors.blue[900],
19+
),
20+
child: ComponentTheme(
21+
data: RadioTheme(
22+
backgroundColor: isDark ? Colors.gray[800] : Colors.white,
23+
activeColor: isDark ? Colors.gray[400] : Colors.blue[900],
24+
borderColor: isDark ? Colors.gray[100] : Colors.blue[900],
25+
),
26+
child: ComponentTheme(
27+
data: RadioCardTheme(
28+
color: isDark ? Colors.gray[800] : Colors.white,
29+
hoverColor: isDark ? Colors.gray[500] : Colors.blue[200],
30+
borderColor: isDark ? Colors.gray[300] : Colors.blue[900],
31+
selectedBorderColor: isDark ? Colors.gray[100] : Colors.blue[900],
32+
selectedBorderWidth: 3,
33+
),
34+
child: ComponentTheme(
35+
data: SliderTheme(
36+
trackColor: isDark ? Colors.gray[500] : Colors.gray[500],
37+
valueColor: isDark ? Colors.gray[100] : Colors.gray[100],
38+
thumbColor: isDark ? Colors.gray[100] : Colors.gray[100],
39+
thumbBorderColor: isDark ? Colors.blue[900] : Colors.blue[900],
40+
),
41+
child: ComponentTheme(
42+
data: SwitchTheme(
43+
activeColor: isDark ? Colors.blue[400] : Colors.blue[300],
44+
activeThumbColor: isDark ? Colors.blue[900] : Colors.blue[900],
45+
inactiveColor: isDark ? Colors.gray[500] : Colors.gray[200],
46+
inactiveThumbColor: isDark ? Colors.gray[200] : Colors.blue[400],
47+
),
48+
child: child,
49+
),
50+
),
51+
),
52+
),
53+
);
54+
}
55+
}

lib/theme/cubit/theme_state.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ final double radius = 0.5;
3535
final ColorScheme light = ColorSchemes.lightSlate.blue.copyWith(
3636
primary: () => Colors.blue[900],
3737
primaryForeground: () => Colors.white,
38+
border: () => Colors.blue[900],
39+
input: () => Colors.gray[100],
3840
);
3941

4042
/// The light [ThemeData] for `shadcn_flutter`.
@@ -51,6 +53,8 @@ final ColorScheme dark = ColorSchemes.darkSlate.blue.copyWith(
5153
primary: () => Colors.blue[700],
5254
primaryForeground: () => Colors.white,
5355
card: () => Colors.gray[800],
56+
border: () => Colors.gray[100],
57+
input: () => Colors.gray[600],
5458
);
5559

5660
/// The dark [ThemeData] for `shadcn_flutter`.

0 commit comments

Comments
 (0)