Skip to content

Commit f77da5d

Browse files
nouha06boosted-botAhmedAmineZr
authored
chore: update ToolBarTop with oudsBadge in trailling actions (#642)(#770)
* chore: update tokens * chore: update tokens with version 2.4.0 * chore: update tokens with version 2.4.0 * chore: update version components * chore(version): prepare version 2.0.0 (#747) Prepare version v2.0.0 (#747) * feat: Update `ToolBar Top`, with Badge in Trailing Actions * feat: fix merge conflicts * feat(topbar): add border for top bar badge * chore: update version in doc * chore: update changelog --------- Co-authored-by: boosted-bot <boosted-bot@users.noreply.github.com> Co-authored-by: Ahmed Amine Zribi <ahmedamine.zribi@sofrecom.com>
1 parent 2eef65b commit f77da5d

13 files changed

Lines changed: 882 additions & 573 deletions

app/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77
## [Unreleased](https://github.com/Orange-OpenSource/ouds-flutter/compare/1.3.1...develop)
88
### Added
99
### Changed
10+
- [DemoApp][Library] Update `ToolBar Top`, with Badge in Trailing Actions ([#642](https://github.com/Orange-OpenSource/ouds-flutter/issues/642))
1011
- [DemoApp][Library] update `alert message`, `switch`, `radio`, `checkbox`, `text input`, `pin code input`, `phone number input`, components to use rich text ([#782](https://github.com/Orange-OpenSource/ouds-flutter/issues/782))
1112
- [Library] Update text input component to v1.4 ([#692](https://github.com/Orange-OpenSource/ouds-flutter/issues/692))
1213
- [Library] update `Password input` component to v1.3 ([#689](https://github.com/Orange-OpenSource/ouds-flutter/issues/689))
Lines changed: 53 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
//
32
// Software Name: OUDS Flutter
43
// SPDX-FileCopyrightText: Copyright (c) Orange SA
@@ -15,11 +14,11 @@ import 'package:flutter/cupertino.dart';
1514
import 'package:ouds_core/components/top_bar/ouds_top_bar_action_config.dart';
1615
import 'package:ouds_flutter_demo/l10n/app_localizations.dart';
1716
import 'package:ouds_flutter_demo/ui/components/top_bar/top_bar_customization.dart';
17+
import 'package:ouds_flutter_demo/ui/components/top_bar/top_bar_customization_utils.dart';
1818
import 'package:ouds_flutter_demo/ui/components/top_bar/top_bar_enum.dart';
1919
import 'package:ouds_flutter_demo/ui/theme/theme_controller.dart';
2020
import 'package:ouds_flutter_demo/ui/utilities/app_assets.dart';
2121

22-
2322
/// Utility class to map tag customization options to corresponding OudsToolbarTop attributes.
2423
///
2524
/// This class provides static methods to convert customization enums into the appropriate
@@ -28,48 +27,51 @@ import 'package:ouds_flutter_demo/ui/utilities/app_assets.dart';
2827
/// user-selected options into code that is used for TopAppBar customization and rendering.
2928
3029
class ToolbarTopCustomizationUtils {
31-
3230
/// Minimum number of actions allowed for the Cupertino style of OudsTopBar component.
3331
static const int minActionCount = 1;
32+
3433
/// Maximum number of actions allowed for the Cupertino style of OudsTopBar component.
3534
static const int maxActionCount = 3;
3635

3736
/// Generates a list of consecutive item count values from [minActionCount]
3837
/// to [maxActionCount] (inclusive).
3938
static final cupertinoActionCountOptions = List<int>.generate(
4039
maxActionCount - (minActionCount - 1),
41-
(index) => minActionCount + index,
40+
(index) => minActionCount + index,
4241
);
4342

44-
static List<int> getLimitedActionsCount(BuildContext context){
43+
static List<int> getLimitedActionsCount(BuildContext context) {
4544
int maxActionsIndex = maxActionCount + 1;
4645
return cupertinoActionCountOptions.take(maxActionsIndex).toList();
4746
}
4847

4948
static List<int?>? getDisabledLeadingActionCountOptions(
50-
TopBarCustomizationState? customizationState) {
49+
TopBarCustomizationState? customizationState,
50+
) {
5151
//disable all options if selected type is none
5252
if (customizationState?.selectedLeadingActionType ==
5353
ToolbarTopActionTypeEnum.none) {
54-
return List<int>.generate(maxActionCount+1, (i) => i);
54+
return List<int>.generate(maxActionCount + 1, (i) => i);
5555
}
5656
//if selected type is different to back no option to disable
5757
if (customizationState?.selectedLeadingActionType !=
58-
ToolbarTopActionTypeEnum.back ) {
58+
ToolbarTopActionTypeEnum.back) {
5959
return null;
6060
}
6161
//disable all options > 1 if selected type is back
62-
return List<int>.generate(maxActionCount+1, (i) => i)
63-
.where((value) => value > 1)
64-
.toList();
62+
return List<int>.generate(
63+
maxActionCount + 1,
64+
(i) => i,
65+
).where((value) => value > 1).toList();
6566
}
6667

6768
static List<int?>? getDisabledTrailingActionCountOptions(
68-
TopBarCustomizationState? customizationState) {
69+
TopBarCustomizationState? customizationState,
70+
) {
6971
//disable all options if selected type is none
7072
if (customizationState?.selectedTrailingActionType ==
7173
ToolbarTopActionTypeEnum.none) {
72-
return List<int>.generate(maxActionCount+1, (i) => i);
74+
return List<int>.generate(maxActionCount + 1, (i) => i);
7375
}
7476
return null;
7577
}
@@ -86,26 +88,39 @@ class ToolbarTopCustomizationUtils {
8688
ThemeController? themeController,
8789
required TopBarCustomizationState customizationState,
8890
required bool isLeadingActions,
89-
}){
91+
}) {
9092
final safeActionCount = isLeadingActions
91-
? customizationState.selectedLeadingActionCount.clamp(minActionCount, maxActionCount)
92-
: customizationState.selectedTrailingActionCount.clamp(minActionCount, maxActionCount);
93-
94-
return List.generate(
95-
safeActionCount,
96-
(index) {
97-
return _getCupertinoActionConfig(context, customizationState,themeController,isLeadingActions);
98-
},
99-
);
93+
? customizationState.selectedLeadingActionCount.clamp(
94+
minActionCount,
95+
maxActionCount,
96+
)
97+
: customizationState.selectedTrailingActionCount.clamp(
98+
minActionCount,
99+
maxActionCount,
100+
);
101+
102+
return List.generate(safeActionCount, (index) {
103+
final isLastItem = index == safeActionCount - 1;
104+
105+
return _getCupertinoActionConfig(
106+
context,
107+
customizationState,
108+
themeController,
109+
isLeadingActions,
110+
isLastItem,
111+
safeActionCount,
112+
);
113+
});
100114
}
101115

102116
static OudsTopBarActionConfig _getCupertinoActionConfig(
103-
BuildContext context,
104-
TopBarCustomizationState? customizationState,
105-
ThemeController? themeController,
106-
bool isLeadingAction
107-
){
108-
117+
BuildContext context,
118+
TopBarCustomizationState? customizationState,
119+
ThemeController? themeController,
120+
bool isLeadingAction,
121+
bool isLastItem,
122+
int actionCount,
123+
) {
109124
// Handle null state gracefully to avoid runtime errors.
110125
if (customizationState == null || themeController == null) {
111126
return OudsTopBarActionConfig.none();
@@ -120,19 +135,25 @@ class ToolbarTopCustomizationUtils {
120135
switch (actionType) {
121136
case ToolbarTopActionTypeEnum.text:
122137
return OudsTopBarActionConfig.text(
123-
actionLabel: context.l10n.app_components_common_label_label, // Provide only the relevant parameter.
138+
actionLabel: context
139+
.l10n
140+
.app_components_common_label_label, // Provide only the relevant parameter.
124141
onActionPressed: customizationState.hasEnabled == true ? () {} : null,
125142
);
126143

127144
case ToolbarTopActionTypeEnum.icon:
145+
final isBadgeEligible = actionCount == 1 || isLastItem;
128146
return OudsTopBarActionConfig.icon(
129147
// Provide a relevant icon.
130148
icon: AppAssets.icons.assistanceTipsAndTricks(themeController),
131149
contentDescription: context.l10n.app_components_common_action_a11y,
132150
onActionPressed: customizationState.hasEnabled == true ? () {} : null,
151+
badge: !isLeadingAction && isBadgeEligible
152+
? TopBarCustomizationUtils.getActionBadge(customizationState)
153+
: null,
133154
);
134155
case ToolbarTopActionTypeEnum.back:
135-
// The .back() factory handles its own icon and behavior.
156+
// The .back() factory handles its own icon and behavior.
136157
return OudsTopBarActionConfig.back(
137158
previousPageTitle: customizationState.previousPageTitleText,
138159
onActionPressed: () {
@@ -146,4 +167,4 @@ class ToolbarTopCustomizationUtils {
146167
return OudsTopBarActionConfig.none();
147168
}
148169
}
149-
}
170+
}

0 commit comments

Comments
 (0)