Skip to content

Commit b3f6f85

Browse files
committed
feat(progress-indicator): add code generator in demo app,update readme file and doc in lib
1 parent 29cbf72 commit b3f6f85

5 files changed

Lines changed: 142 additions & 2 deletions

File tree

app/lib/ui/components/components.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,11 @@ List<Component> components(BuildContext context) {
376376
Component.withVariant(
377377
context.l10n.app_components_progressIndicator_tech,
378378
ComponentContainer(
379-
child: OudsCircularProgressIndicator(progress: 0.75, status: Accent()),
379+
child: OudsCircularProgressIndicator(
380+
progress: 0.75,
381+
status: Accent(),
382+
animated: false,
383+
),
380384
),
381385
context.l10n.app_components_progressIndicator_description_text,
382386
[

app/lib/ui/components/progress_indicator/circular_progress_indicator_demo_screen.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@ import 'package:flutter/material.dart';
1515
import 'package:ouds_core/components/progress_indicator/ouds_circular_progress_indicator.dart';
1616
import 'package:ouds_flutter_demo/l10n/app_localizations.dart';
1717
import 'package:ouds_flutter_demo/main_app_bar.dart';
18+
import 'package:ouds_flutter_demo/ui/components/progress_indicator/progress_indicator_code_generator.dart';
1819
import 'package:ouds_flutter_demo/ui/components/progress_indicator/progress_indicator_customization.dart';
1920
import 'package:ouds_flutter_demo/ui/components/progress_indicator/progress_indicator_customization_utils.dart';
2021
import 'package:ouds_flutter_demo/ui/components/progress_indicator/progress_indicator_enum.dart';
2122
import 'package:ouds_flutter_demo/ui/theme/theme_controller.dart';
23+
import 'package:ouds_flutter_demo/ui/utilities/code.dart';
2224
import 'package:ouds_flutter_demo/ui/utilities/component/status_enum.dart';
2325
import 'package:ouds_flutter_demo/ui/utilities/customizable/customizable_chips.dart';
2426
import 'package:ouds_flutter_demo/ui/utilities/customizable/customizable_dropdown_menu.dart';
@@ -120,7 +122,7 @@ class _BodyState extends State<_Body> {
120122
.spaceScheme(context)
121123
.fixedMedium,
122124
),
123-
//Code(code: LinkCodeGenerator.updateCode(context)),
125+
Code(code: ProgressIndicatorCodeGenerator.updateCode(context)),
124126
ReferenceDesignVersionComponent(
125127
version: OudsComponentVersion.progressIndicator,
126128
),
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
/*
2+
* // Software Name: OUDS Flutter
3+
* // SPDX-FileCopyrightText: Copyright (c) Orange SA
4+
* // SPDX-License-Identifier: MIT
5+
* //
6+
* // This software is distributed under the MIT license,
7+
* // the text of which is available at https://opensource.org/license/MIT/
8+
* // or see the "LICENSE" file for more details.
9+
* //
10+
* // Software description: Flutter library of reusable graphical components
11+
* //
12+
*/
13+
import 'package:flutter/material.dart';
14+
import 'package:ouds_flutter_demo/ui/components/progress_indicator/progress_indicator_customization.dart';
15+
import 'package:ouds_flutter_demo/ui/components/progress_indicator/progress_indicator_customization_utils.dart';
16+
import 'package:ouds_flutter_demo/ui/components/progress_indicator/progress_indicator_enum.dart';
17+
import 'package:ouds_flutter_demo/ui/utilities/component/status_enum.dart';
18+
19+
class ProgressIndicatorCodeGenerator {
20+
// Static method to generate the code based on CircularProgressIndicator customization state
21+
static String updateCode(BuildContext context) {
22+
return """OudsCircularProgressIndicator(
23+
${status(context)},
24+
${progress(context)},
25+
${track(context)},
26+
${animated(context)},
27+
${gapSize(context)},
28+
${semanticLabel(context)},
29+
)""";
30+
}
31+
32+
// Method to generate status
33+
static String status(BuildContext context) {
34+
final customizationState = ProgressIndicatorCustomization.of(context);
35+
36+
return "status: ${_getStatusCode(customizationState!)}";
37+
}
38+
39+
// Method to generate progress
40+
static String progress(BuildContext context) {
41+
final customizationState = ProgressIndicatorCustomization.of(context);
42+
43+
if (customizationState?.selectedType ==
44+
ProgressIndicatorEnumType.indeterminate) {
45+
return "progress: null";
46+
} else {
47+
return "progress: ${customizationState?.progress}";
48+
}
49+
}
50+
51+
// Method to generate track
52+
static String track(BuildContext context) {
53+
final customizationState = ProgressIndicatorCustomization.of(context);
54+
55+
return "track: ${customizationState!.hasTrack}";
56+
}
57+
58+
// Method to generate animated
59+
static String animated(BuildContext context) {
60+
final customizationState = ProgressIndicatorCustomization.of(context);
61+
62+
return "animated: ${customizationState!.hasAnimation}";
63+
}
64+
65+
// Method to generate gapSize
66+
static String gapSize(BuildContext context) {
67+
final customizationState = ProgressIndicatorCustomization.of(context);
68+
69+
return "gapSize: ${ProgressIndicatorCustomizationUtils.getGapSize(customizationState!.selectedGapSize)}";
70+
}
71+
72+
// Method to generate semanticLabel
73+
static String semanticLabel(BuildContext context) {
74+
final customizationState = ProgressIndicatorCustomization.of(context);
75+
76+
final hasProgress =
77+
customizationState!.progress.isNotEmpty &&
78+
(double.tryParse(customizationState.progress) ?? 0.0) > 0.0;
79+
80+
return "semanticLabel: '${hasProgress ? "Uploading file" : "Connecting to server"}'";
81+
}
82+
83+
// Helpers to print enum references as code strings
84+
static String enumStatusValue(dynamic status) {
85+
// Example output: ProgressIndicatorStatusEnum.positive
86+
return "ProgressIndicatorStatusEnum.${status.toString()}";
87+
}
88+
89+
static String enumTypeValue(dynamic type) {
90+
// Example output: ProgressIndicatorTypeEnum.determinate
91+
return "ProgressIndicatorTypeEnum.${type.toString()}";
92+
}
93+
94+
static String enumGapSizeValue(dynamic gapSize) {
95+
// Example output: ProgressIndicatorGapSizeEnum.medium
96+
return "ProgressIndicatorGapSizeEnum.${gapSize.toString()}";
97+
}
98+
99+
/// Generates the code snippet for the `status` property.
100+
static String? _getStatusCode(
101+
ProgressIndicatorCustomizationState customization,
102+
) {
103+
switch (customization.selectedStatus) {
104+
case StatusEnum.accent:
105+
return "Accent()";
106+
case StatusEnum.negative:
107+
return 'Negative()';
108+
case StatusEnum.warning:
109+
return 'Warning()';
110+
case StatusEnum.info:
111+
return 'Info()';
112+
case StatusEnum.positive:
113+
return 'Positive()';
114+
case StatusEnum.neutral:
115+
return "Neutral()";
116+
}
117+
}
118+
}

ouds_core/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,10 @@ It is intended to replace internal frameworks and the previous [ODS](https://git
126126
<td style="padding:10px;">Pin Code Input</td>
127127
<td>1.3.0</td>
128128
</tr>
129+
<tr>
130+
<td style="padding:10px;">Progress Indicator</td>
131+
<td>1.0.0</td>
132+
</tr>
129133
<tr>
130134
<td style="padding:10px;">Radio Button</td>
131135
<td>1.4.0</td>

ouds_core/lib/components/progress_indicator/ouds_circular_progress_indicator.dart

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,18 @@ enum OudsCircularIndicatorGapSize { defaultSize, small }
4040
/// - [track]: If true, displays the track (background) of the indicator.
4141
/// - [semanticLabel]: Semantic label for accessibility.
4242
///
43+
/// ## Example of usage
44+
///
45+
/// ```dart
46+
/// OudsCircularProgressIndicator(
47+
/// status: Positive(),
48+
/// progress: 80,
49+
/// track: false,
50+
/// animated: true,
51+
/// gapSize: OudsCircularIndicatorGapSize.small
52+
/// );
53+
/// ```
54+
///
4355
class OudsCircularProgressIndicator extends StatelessWidget {
4456
final OudsIconStatus status;
4557
final bool animated;

0 commit comments

Comments
 (0)