Skip to content

Commit 7bda19b

Browse files
AhmedAmineZrAhmed Amine ZribiTayebsed93
authored
feat: add themeboxcolored for lightDark mode (#223)(#233)
* feat: add themeboxcolored for lightDark mode * feat: Add ThemeBox to Checkbox * feat: Add ThemeBox for component divider * feat: Add ThemeBox component RadioButton * feat: change Column by CustomizableSection * feat: replace Divider by OudsDivider * review: fix listen controller to rebuild widget * review: fix import in ouds control item * review: change CustomizableSection by Column * feat: Add ChangeLog * fix: enabled state button ouds * feat: replace imports * review: fix some error token and fix changelog --------- Co-authored-by: Ahmed Amine Zribi <ahmedamine.zribi@sofrecom> Co-authored-by: Tayeb Sedraia <tayeb.sedraia@orange.com>
1 parent de00dbf commit 7bda19b

12 files changed

Lines changed: 466 additions & 98 deletions

File tree

app/CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77
## [Unreleased](https://github.com/Orange-OpenSource/ouds-flutter/compare/0.3.0...develop)
88

99
### Added
10+
- [DemoApp] Display components in both light/dark mode ([#223](https://github.com/Orange-OpenSource/ouds-flutter/issues/223))
1011
- [DemoApp] Add token version in About page and documentation ([#142](https://github.com/Orange-OpenSource/ouds-flutter/issues/#142))
1112

1213
### Changed
1314
- [DemoApp][Library] Update tokens 1.1.0 ([#225](https://github.com/Orange-OpenSource/ouds-flutter/issues/225))
1415

1516
### Fixed
16-
1717
- [DemoApp][Library] Delayed pressed state ([#220](https://github.com/Orange-OpenSource/ouds-flutter/issues/220))
1818
- [DemoApp] Update cards backgrounds token ([#204](https://github.com/Orange-OpenSource/ouds-flutter/issues/204))
1919
- [DemoApp][Library] Token `size` values now adapt based on device type ([#218](https://github.com/Orange-OpenSource/ouds-flutter/issues/218))

app/lib/ui/components/button/button_demo_screen.dart

Lines changed: 42 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import 'package:ouds_flutter_demo/ui/utilities/customizable/customizable_section
2727
import 'package:ouds_flutter_demo/ui/utilities/customizable/customizable_switch.dart';
2828
import 'package:ouds_flutter_demo/ui/utilities/customizable/customizable_textfield.dart';
2929
import 'package:ouds_flutter_demo/ui/utilities/sheets_bottom/ouds_sheets_bottom.dart';
30+
import 'package:ouds_flutter_demo/ui/utilities/theme_colored_box.dart';
3031
import 'package:provider/provider.dart';
3132

3233
/// This screen displays a button demo and allows customization of button properties
@@ -107,23 +108,53 @@ class _ButtonDemoState extends State<_ButtonDemo> {
107108
@override
108109
Widget build(BuildContext context) {
109110
customizationState = ButtonCustomization.of(context);
110-
themeController = Provider.of<ThemeController>(context, listen: false);
111+
themeController = Provider.of<ThemeController>(context, listen: true);
111112

112113
// Adding post-frame callback to update theme based on customization state
113114
WidgetsBinding.instance.addPostFrameCallback((_) {
114115
themeController?.setOnColoredSurface(customizationState?.hasOnColoredBox);
115116
});
116117

117-
return OudsColoredBox(
118-
color: customizationState?.hasOnColoredBox == true ? OudsColoredBoxColor.brandPrimary : OudsColoredBoxColor.statusNeutralMuted,
119-
child: OudsButton(
120-
label: ButtonCustomizationUtils.getText(customizationState),
121-
icon: ButtonCustomizationUtils.getIcon(customizationState),
122-
hierarchy: ButtonCustomizationUtils.getHierarchy(customizationState?.selectedHierarchy as Object),
123-
style: ButtonCustomizationUtils.getStyle(customizationState?.selectedStyle as Object),
124-
onPressed: customizationState?.hasEnabled == true ? () {} : null,
125-
),
126-
);
118+
if (customizationState?.hasOnColoredBox == true) {
119+
return OudsColoredBox(
120+
color: customizationState?.hasOnColoredBox == true ? OudsColoredBoxColor.brandPrimary : OudsColoredBoxColor.statusNeutralMuted,
121+
child: OudsButton(
122+
label: ButtonCustomizationUtils.getText(customizationState),
123+
icon: ButtonCustomizationUtils.getIcon(customizationState),
124+
hierarchy: ButtonCustomizationUtils.getHierarchy(customizationState?.selectedHierarchy as Object),
125+
style: ButtonCustomizationUtils.getStyle(customizationState?.selectedStyle as Object),
126+
onPressed: customizationState?.hasEnabled == true ? () {} : null,
127+
),
128+
);
129+
} else {
130+
return Column(
131+
children: [
132+
/// [themeMode] we test here theme of system and inverse theme mode if is not dark
133+
ThemeBox(
134+
themeContract: themeController!.currentTheme,
135+
themeMode: themeController!.isInverseDarkTheme ? ThemeMode.light : ThemeMode.dark,
136+
child: OudsButton(
137+
label: ButtonCustomizationUtils.getText(customizationState),
138+
icon: ButtonCustomizationUtils.getIcon(customizationState),
139+
hierarchy: ButtonCustomizationUtils.getHierarchy(customizationState?.selectedHierarchy as Object),
140+
style: ButtonCustomizationUtils.getStyle(customizationState?.selectedStyle as Object),
141+
onPressed: customizationState?.hasEnabled == true ? () {} : null,
142+
),
143+
),
144+
ThemeBox(
145+
themeContract: themeController!.currentTheme,
146+
themeMode: themeController!.isInverseDarkTheme ? ThemeMode.dark : ThemeMode.light,
147+
child: OudsButton(
148+
label: ButtonCustomizationUtils.getText(customizationState),
149+
icon: ButtonCustomizationUtils.getIcon(customizationState),
150+
hierarchy: ButtonCustomizationUtils.getHierarchy(customizationState?.selectedHierarchy as Object),
151+
style: ButtonCustomizationUtils.getStyle(customizationState?.selectedStyle as Object),
152+
onPressed: customizationState?.hasEnabled == true ? () {} : null,
153+
),
154+
)
155+
],
156+
);
157+
}
127158
}
128159
}
129160

app/lib/ui/components/checkbox/checkbox_demo_screen.dart

Lines changed: 76 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212

1313
import 'package:flutter/material.dart';
1414
import 'package:ouds_core/components/checkbox/ouds_checkbox.dart';
15-
import 'package:ouds_core/components/ouds_colored_box.dart';
1615
import 'package:ouds_flutter_demo/l10n/app_localizations.dart';
1716
import 'package:ouds_flutter_demo/main_app_bar.dart';
1817
import 'package:ouds_flutter_demo/ui/components/checkbox/checkbox_code_generator.dart';
@@ -23,6 +22,7 @@ import 'package:ouds_flutter_demo/ui/utilities/customizable/customizable_section
2322
import 'package:ouds_flutter_demo/ui/utilities/customizable/customizable_switch.dart';
2423
import 'package:ouds_flutter_demo/ui/utilities/detail_screen_header.dart';
2524
import 'package:ouds_flutter_demo/ui/utilities/sheets_bottom/ouds_sheets_bottom.dart';
25+
import 'package:ouds_flutter_demo/ui/utilities/theme_colored_box.dart';
2626
import 'package:provider/provider.dart';
2727

2828
/// This screen displays a checkbox demo and allows customization of checkbox properties
@@ -82,7 +82,7 @@ class _Body extends StatefulWidget {
8282
class _BodyState extends State<_Body> {
8383
@override
8484
Widget build(BuildContext context) {
85-
ThemeController? themeController = Provider.of<ThemeController>(context, listen: false);
85+
ThemeController? themeController = Provider.of<ThemeController>(context, listen: true);
8686
return DetailScreenDescription(
8787
widget: Column(
8888
children: [
@@ -110,47 +110,91 @@ class _CheckboxDemo extends StatefulWidget {
110110
}
111111

112112
class _CheckboxDemoState extends State<_CheckboxDemo> {
113-
ThemeController? themeController;
114113
bool? isCheckedFirst = false;
115114
bool? isCheckedSecond = false;
116115

117116
CheckboxCustomizationState? customizationState;
117+
ThemeController? themeController;
118118

119119
@override
120120
Widget build(BuildContext context) {
121121
customizationState = CheckboxCustomization.of(context);
122+
themeController = Provider.of<ThemeController>(context, listen: false);
122123

123-
return OudsColoredBox(
124-
color: OudsColoredBoxColor.statusNeutralMuted,
125-
child: Row(
126-
mainAxisAlignment: MainAxisAlignment.center,
127-
children: [
128-
OudsCheckbox(
129-
value: isCheckedFirst,
130-
onChanged: customizationState?.hasEnabled == true
131-
? (bool? newValue) {
132-
setState(() {
133-
isCheckedFirst = newValue;
134-
});
135-
}
136-
: null,
137-
isError: customizationState!.hasError,
138-
tristate: widget.indeterminate,
124+
// Adding post-frame callback to update theme based on customization state
125+
WidgetsBinding.instance.addPostFrameCallback((_) {
126+
themeController?.setOnColoredSurface(customizationState?.hasOnColoredBox);
127+
});
128+
129+
return Column(
130+
children: [
131+
ThemeBox(
132+
themeContract: themeController!.currentTheme,
133+
themeMode: themeController!.isInverseDarkTheme ? ThemeMode.light : ThemeMode.dark,
134+
child: Row(
135+
mainAxisAlignment: MainAxisAlignment.center,
136+
children: [
137+
OudsCheckbox(
138+
value: isCheckedFirst,
139+
onChanged: customizationState?.hasEnabled == true
140+
? (bool? newValue) {
141+
setState(() {
142+
isCheckedFirst = newValue;
143+
});
144+
}
145+
: null,
146+
isError: customizationState!.hasError,
147+
tristate: widget.indeterminate,
148+
),
149+
OudsCheckbox(
150+
value: isCheckedSecond,
151+
onChanged: customizationState?.hasEnabled == true
152+
? (bool? newValue) {
153+
setState(() {
154+
isCheckedSecond = newValue;
155+
});
156+
}
157+
: null,
158+
isError: customizationState!.hasError ? true : false,
159+
tristate: widget.indeterminate,
160+
),
161+
],
139162
),
140-
OudsCheckbox(
141-
value: isCheckedSecond,
142-
onChanged: customizationState?.hasEnabled == true
143-
? (bool? newValue) {
144-
setState(() {
145-
isCheckedSecond = newValue;
146-
});
147-
}
148-
: null,
149-
isError: customizationState!.hasError ? true : false,
150-
tristate: widget.indeterminate,
163+
),
164+
ThemeBox(
165+
themeContract: themeController!.currentTheme,
166+
themeMode: themeController!.isInverseDarkTheme ? ThemeMode.dark : ThemeMode.light,
167+
child: Row(
168+
mainAxisAlignment: MainAxisAlignment.center,
169+
children: [
170+
OudsCheckbox(
171+
value: isCheckedFirst,
172+
onChanged: customizationState?.hasEnabled == true
173+
? (bool? newValue) {
174+
setState(() {
175+
isCheckedFirst = newValue;
176+
});
177+
}
178+
: null,
179+
isError: customizationState!.hasError,
180+
tristate: widget.indeterminate,
181+
),
182+
OudsCheckbox(
183+
value: isCheckedSecond,
184+
onChanged: customizationState?.hasEnabled == true
185+
? (bool? newValue) {
186+
setState(() {
187+
isCheckedSecond = newValue;
188+
});
189+
}
190+
: null,
191+
isError: customizationState!.hasError ? true : false,
192+
tristate: widget.indeterminate,
193+
),
194+
],
151195
),
152-
],
153-
),
196+
),
197+
],
154198
);
155199
}
156200
}

app/lib/ui/components/checkbox/checkbox_item_demo_screen.dart

Lines changed: 84 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212

1313
import 'package:flutter/material.dart';
1414
import 'package:ouds_core/components/checkbox/ouds_checkbox_item.dart';
15-
import 'package:ouds_core/components/ouds_colored_box.dart';
1615
import 'package:ouds_flutter_demo/l10n/app_localizations.dart';
1716
import 'package:ouds_flutter_demo/main_app_bar.dart';
1817
import 'package:ouds_flutter_demo/ui/components/control_item/control_item_code_generator.dart';
@@ -27,6 +26,7 @@ import 'package:ouds_flutter_demo/ui/utilities/customizable/customizable_switch.
2726
import 'package:ouds_flutter_demo/ui/utilities/customizable/customizable_textfield.dart';
2827
import 'package:ouds_flutter_demo/ui/utilities/detail_screen_header.dart';
2928
import 'package:ouds_flutter_demo/ui/utilities/sheets_bottom/ouds_sheets_bottom.dart';
29+
import 'package:ouds_flutter_demo/ui/utilities/theme_colored_box.dart';
3030
import 'package:provider/provider.dart';
3131

3232
/// This screen displays a checkbox demo and allows customization of checkbox properties.
@@ -54,7 +54,8 @@ class _ControlItemDemoScreenState extends State<ControlItemDemoScreen> {
5454
return ControlItemCustomization(
5555
child: Scaffold(
5656
key: _scaffoldKey,
57-
appBar: widget.indeterminate ? MainAppBar(title: context.l10n.app_components_checkbox_indeterminateCheckboxItem_label) : MainAppBar(title: context.l10n.app_components_checkbox_checkboxItem_label),
57+
appBar:
58+
widget.indeterminate ? MainAppBar(title: context.l10n.app_components_checkbox_indeterminateCheckboxItem_label) : MainAppBar(title: context.l10n.app_components_checkbox_checkboxItem_label),
5859
body: SafeArea(
5960
child: ExcludeSemantics(
6061
excluding: !_isBottomSheetExpanded,
@@ -84,7 +85,7 @@ class _Body extends StatefulWidget {
8485
class _BodyState extends State<_Body> {
8586
@override
8687
Widget build(BuildContext context) {
87-
final themeController = Provider.of<ThemeController>(context, listen: false);
88+
final themeController = Provider.of<ThemeController>(context, listen: true);
8889
return DetailScreenDescription(
8990
widget: Column(
9091
children: [
@@ -114,16 +115,25 @@ class _CheckboxItemDemoState extends State<_CheckboxItemDemo> {
114115
bool? isCheckedSecond = false;
115116

116117
ControlItemCustomizationState? customizationState;
118+
ThemeController? themeController;
117119

118120
@override
119121
Widget build(BuildContext context) {
120122
customizationState = ControlItemCustomization.of(context);
121-
return OudsColoredBox(
122-
color: OudsColoredBoxColor.statusNeutralMuted,
123-
child: Column(
124-
children: [
125-
Center(
126-
child: OudsCheckboxItem(
123+
themeController = Provider.of<ThemeController>(context, listen: false);
124+
125+
// Adding post-frame callback to update theme based on customization state
126+
WidgetsBinding.instance.addPostFrameCallback((_) {
127+
themeController?.setOnColoredSurface(customizationState?.hasOnColoredBox);
128+
});
129+
130+
return Column(children: [
131+
ThemeBox(
132+
themeContract: themeController!.currentTheme,
133+
themeMode: themeController!.isInverseDarkTheme ? ThemeMode.light : ThemeMode.dark,
134+
child: Column(
135+
children: [
136+
OudsCheckboxItem(
127137
value: isCheckedFirst,
128138
onChanged: customizationState!.hasEnabled
129139
? (bool? newValue) {
@@ -141,28 +151,72 @@ class _CheckboxItemDemoState extends State<_CheckboxItemDemo> {
141151
divider: customizationState!.hasDivider ? true : false,
142152
tristate: widget.indeterminate,
143153
),
144-
),
145-
OudsCheckboxItem(
146-
value: isCheckedSecond,
147-
onChanged: customizationState!.hasEnabled
148-
? (bool? newValue) {
149-
setState(() {
150-
isCheckedSecond = newValue;
151-
});
152-
}
153-
: null,
154-
title: ControlItemCustomizationUtils.getLabelText(customizationState!),
155-
helperTitle: ControlItemCustomizationUtils.getHelperLabelText(customizationState!),
156-
reversed: customizationState!.hasReversed ? true : false,
157-
readOnly: customizationState!.hasReadOnly ? true : false,
158-
icon: customizationState!.hasIcon ? AppAssets.icons.icHeart : null,
159-
isError: customizationState!.hasError ? true : false,
160-
divider: customizationState!.hasDivider ? true : false,
161-
tristate: widget.indeterminate,
162-
),
163-
],
154+
OudsCheckboxItem(
155+
value: isCheckedSecond,
156+
onChanged: customizationState!.hasEnabled
157+
? (bool? newValue) {
158+
setState(() {
159+
isCheckedSecond = newValue;
160+
});
161+
}
162+
: null,
163+
title: ControlItemCustomizationUtils.getLabelText(customizationState!),
164+
helperTitle: ControlItemCustomizationUtils.getHelperLabelText(customizationState!),
165+
reversed: customizationState!.hasReversed ? true : false,
166+
readOnly: customizationState!.hasReadOnly ? true : false,
167+
icon: customizationState!.hasIcon ? AppAssets.icons.icHeart : null,
168+
isError: customizationState!.hasError ? true : false,
169+
divider: customizationState!.hasDivider ? true : false,
170+
tristate: widget.indeterminate,
171+
),
172+
],
173+
),
164174
),
165-
);
175+
ThemeBox(
176+
themeContract: themeController!.currentTheme,
177+
themeMode: themeController!.isInverseDarkTheme ? ThemeMode.dark : ThemeMode.light,
178+
child: Column(
179+
children: [
180+
OudsCheckboxItem(
181+
value: isCheckedFirst,
182+
onChanged: customizationState!.hasEnabled
183+
? (bool? newValue) {
184+
setState(() {
185+
isCheckedFirst = newValue;
186+
});
187+
}
188+
: null,
189+
title: ControlItemCustomizationUtils.getLabelText(customizationState!),
190+
helperTitle: ControlItemCustomizationUtils.getHelperLabelText(customizationState!),
191+
reversed: customizationState!.hasReversed ? true : false,
192+
readOnly: customizationState!.hasReadOnly ? true : false,
193+
icon: customizationState!.hasIcon ? AppAssets.icons.icHeart : null,
194+
isError: customizationState!.hasError ? true : false,
195+
divider: customizationState!.hasDivider ? true : false,
196+
tristate: widget.indeterminate,
197+
),
198+
OudsCheckboxItem(
199+
value: isCheckedSecond,
200+
onChanged: customizationState!.hasEnabled
201+
? (bool? newValue) {
202+
setState(() {
203+
isCheckedSecond = newValue;
204+
});
205+
}
206+
: null,
207+
title: ControlItemCustomizationUtils.getLabelText(customizationState!),
208+
helperTitle: ControlItemCustomizationUtils.getHelperLabelText(customizationState!),
209+
reversed: customizationState!.hasReversed ? true : false,
210+
readOnly: customizationState!.hasReadOnly ? true : false,
211+
icon: customizationState!.hasIcon ? AppAssets.icons.icHeart : null,
212+
isError: customizationState!.hasError ? true : false,
213+
divider: customizationState!.hasDivider ? true : false,
214+
tristate: widget.indeterminate,
215+
),
216+
],
217+
),
218+
)
219+
]);
166220
}
167221
}
168222

0 commit comments

Comments
 (0)