| 1 | import "package:cake_wallet/new-ui/widgets/money/money_settings_cubit.dart"; |
| 2 | import "package:cw_core/amount/money.dart"; |
| 3 | import "package:cw_core/currency.dart"; |
| 4 | import "package:flutter/widgets.dart"; |
| 5 | import "package:flutter_bloc/flutter_bloc.dart"; |
| 6 | |
| 7 | /// The [CurrencySymbolText] widget displays [Currency.symbol] based on |
| 8 | /// usersettings as a formated string of text with single style. |
| 9 | class CurrencySymbolText extends StatelessWidget { |
| 10 | const CurrencySymbolText( |
| 11 | this.currency, { |
| 12 | super.key, |
| 13 | this.style, |
| 14 | this.strutStyle, |
| 15 | this.textAlign, |
| 16 | this.textDirection, |
| 17 | this.locale, |
| 18 | this.softWrap, |
| 19 | this.overflow, |
| 20 | this.textScaler, |
| 21 | this.maxLines, |
| 22 | this.semanticsLabel, |
| 23 | this.semanticsIdentifier, |
| 24 | this.textWidthBasis, |
| 25 | this.textHeightBehavior, |
| 26 | this.selectionColor, |
| 27 | this.useBaseUnit, |
| 28 | }); |
| 29 | |
| 30 | /// The currency to display. |
| 31 | final Currency currency; |
| 32 | |
| 33 | /// If non-null, the style to use for this text. |
| 34 | /// |
| 35 | /// If the style's "inherit" property is true, the style will be merged with |
| 36 | /// the closest enclosing [DefaultTextStyle]. Otherwise, the style will |
| 37 | /// replace the closest enclosing [DefaultTextStyle]. |
| 38 | /// |
| 39 | /// The user or platform may override this [style]'s [TextStyle.fontWeight], |
| 40 | /// [TextStyle.height], [TextStyle.letterSpacing], and [TextStyle.wordSpacing] |
| 41 | /// via a [MediaQuery] ancestor's [MediaQueryData.boldText], |
| 42 | /// [MediaQueryData.lineHeightScaleFactorOverride], |
| 43 | /// [MediaQueryData.letterSpacingOverride], and [MediaQueryData.wordSpacingOverride] |
| 44 | /// regardless of its [TextStyle.inherit] value. |
| 45 | final TextStyle? style; |
| 46 | |
| 47 | /// The user or platform may override this [strutStyle]'s [StrutStyle.height] |
| 48 | /// via a [MediaQuery] ancestor's [MediaQueryData.lineHeightScaleFactorOverride]. |
| 49 | final StrutStyle? strutStyle; |
| 50 | |
| 51 | /// How the text should be aligned horizontally. |
| 52 | final TextAlign? textAlign; |
| 53 | |
| 54 | /// The directionality of the text. |
| 55 | /// |
| 56 | /// This decides how [textAlign] values like [TextAlign.start] and |
| 57 | /// [TextAlign.end] are interpreted. |
| 58 | /// |
| 59 | /// This is also used to disambiguate how to render bidirectional text. For |
| 60 | /// example, if the [data] is an English phrase followed by a Hebrew phrase, |
| 61 | /// in a [TextDirection.ltr] context the English phrase will be on the left |
| 62 | /// and the Hebrew phrase to its right, while in a [TextDirection.rtl] |
| 63 | /// context, the English phrase will be on the right and the Hebrew phrase on |
| 64 | /// its left. |
| 65 | /// |
| 66 | /// Defaults to the ambient [Directionality], if any. |
| 67 | final TextDirection? textDirection; |
| 68 | |
| 69 | /// Used to select a font when the same Unicode character can |
| 70 | /// be rendered differently, depending on the locale. |
| 71 | /// |
| 72 | /// It's rarely necessary to set this property. By default its value |
| 73 | /// is inherited from the enclosing app with `Localizations.localeOf(context)`. |
| 74 | /// |
| 75 | /// See [RenderParagraph.locale] for more information. |
| 76 | final Locale? locale; |
| 77 | |
| 78 | /// Whether the text should break at soft line breaks. |
| 79 | /// |
| 80 | /// If false, the glyphs in the text will be positioned as if there was unlimited horizontal space. |
| 81 | final bool? softWrap; |
| 82 | |
| 83 | /// How visual overflow should be handled. |
| 84 | /// |
| 85 | /// If this is null [TextStyle.overflow] will be used, otherwise the value |
| 86 | /// from the nearest [DefaultTextStyle] ancestor will be used. |
| 87 | final TextOverflow? overflow; |
| 88 | |
| 89 | final TextScaler? textScaler; |
| 90 | |
| 91 | /// An optional maximum number of lines for the text to span, wrapping if necessary. |
| 92 | /// If the text exceeds the given number of lines, it will be truncated according |
| 93 | /// to [overflow]. |
| 94 | /// |
| 95 | /// If this is 1, text will not wrap. Otherwise, text will be wrapped at the |
| 96 | /// edge of the box. |
| 97 | /// |
| 98 | /// If this is null, but there is an ambient [DefaultTextStyle] that specifies |
| 99 | /// an explicit number for its [DefaultTextStyle.maxLines], then the |
| 100 | /// [DefaultTextStyle] value will take precedence. You can use a [RichText] |
| 101 | /// widget directly to entirely override the [DefaultTextStyle]. |
| 102 | final int? maxLines; |
| 103 | |
| 104 | /// An alternative semantics label for this text. |
| 105 | /// |
| 106 | /// If present, the semantics of this widget will contain this value instead |
| 107 | /// of the actual text. This will overwrite any of the semantics labels applied |
| 108 | /// directly to the [TextSpan]s. |
| 109 | /// |
| 110 | /// This is useful for replacing abbreviations or shorthands with the full |
| 111 | /// text value: |
| 112 | /// |
| 113 | /// ```dart |
| 114 | /// const Text(r'$$', semanticsLabel: 'Double dollars') |
| 115 | /// ``` |
| 116 | final String? semanticsLabel; |
| 117 | |
| 118 | /// A unique identifier for the semantics node for this widget. |
| 119 | /// |
| 120 | /// This is useful for cases where the text widget needs to have a uniquely |
| 121 | /// identifiable ID that is recognized through the automation tools without |
| 122 | /// having a dependency on the actual content of the text that can possibly be |
| 123 | /// dynamic in nature. |
| 124 | final String? semanticsIdentifier; |
| 125 | |
| 126 | final TextWidthBasis? textWidthBasis; |
| 127 | |
| 128 | final TextHeightBehavior? textHeightBehavior; |
| 129 | |
| 130 | /// The color to use when painting the selection. |
| 131 | /// |
| 132 | /// This is ignored if [SelectionContainer.maybeOf] returns null |
| 133 | /// in the [BuildContext] of the [Text] widget. |
| 134 | /// |
| 135 | /// If null, the ambient [DefaultSelectionStyle] is used (if any); failing |
| 136 | /// that, the selection color defaults to [DefaultSelectionStyle.defaultColor] |
| 137 | /// (semi-transparent grey). |
| 138 | final Color? selectionColor; |
| 139 | |
| 140 | /// Show the amount in the base unit format of [Money.currency] |
| 141 | /// |
| 142 | /// If null, the displayAmountsInSatoshi setting is used. |
| 143 | final bool? useBaseUnit; |
| 144 | |
| 145 | @override |
| 146 | Widget build(BuildContext context) => BlocBuilder<MoneySettingsCubit, MoneySettingsState>( |
| 147 | builder: (context, state) => Text( |
| 148 | state.getSymbol(currency, overrideSettings: useBaseUnit), |
| 149 | style: style, |
| 150 | strutStyle: strutStyle, |
| 151 | textAlign: textAlign, |
| 152 | textDirection: textDirection, |
| 153 | locale: locale, |
| 154 | softWrap: softWrap, |
| 155 | overflow: overflow, |
| 156 | textScaler: textScaler, |
| 157 | maxLines: maxLines, |
| 158 | semanticsLabel: semanticsLabel, |
| 159 | semanticsIdentifier: semanticsIdentifier, |
| 160 | textWidthBasis: textWidthBasis, |
| 161 | textHeightBehavior: textHeightBehavior, |
| 162 | selectionColor: selectionColor, |
| 163 | ), |
| 164 | ); |
| 165 | } |