|
| 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 | +} |
0 commit comments