Skip to content

Commit

Permalink
feat: Optionally not follow private mode in the CurrencyDisplayer w…
Browse files Browse the repository at this point in the history
…idget
  • Loading branch information
enrique-lozano committed Aug 7, 2024
1 parent 9cd1d9e commit 58027e1
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 27 deletions.
2 changes: 2 additions & 0 deletions lib/app/transactions/form/transaction_form.page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,7 @@ class _TransactionFormPageState extends State<TransactionFormPage> {
),
child: CurrencyDisplayer(
amountToConvert: transactionAmount,
followPrivateMode: false,
currency: fromAccount?.currency,
),
),
Expand Down Expand Up @@ -651,6 +652,7 @@ class _TransactionFormPageState extends State<TransactionFormPage> {
const SizedBox(height: 8),
CurrencyDisplayer(
amountToConvert: exchangeRateSnapshot.data!,
followPrivateMode: false,
integerStyle: Theme.of(context).textTheme.bodyLarge!.copyWith(
color: AppColors.of(context).onSurface.withAlpha(200)),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,15 @@ class CurrencyDisplayer extends StatelessWidget {
this.integerStyle = const TextStyle(inherit: true),
this.decimalsStyle,
this.currencyStyle,
this.followPrivateMode = true,
});

final double amountToConvert;

/// If `true` (the default value), the widget will display the amount with a
/// blurred effect if the user has the private mode activated
final bool followPrivateMode;

/// The currency of the amount, used to display the symbol.
/// If not specified, will be the user preferred currency
final CurrencyInDB? currency;
Expand All @@ -46,42 +51,51 @@ class CurrencyDisplayer extends StatelessWidget {

final bool showDecimals;

Widget _amountDisplayer(
BuildContext context, {
required CurrencyInDB currency,
}) {
return UINumberFormatter.currency(
amountToConvert: amountToConvert,
currency: currency,
showDecimals: showDecimals,
integerStyle: integerStyle,
decimalsStyle: decimalsStyle,
currencyStyle: currencyStyle,
).getTextWidget(context);
}

@override
Widget build(BuildContext context) {
final valueFontSize = (integerStyle.fontSize ??
DefaultTextStyle.of(context).style.fontSize) ??
16;

if (currency != null) {
return BlurBasedOnPrivateMode(
child: UINumberFormatter.currency(
amountToConvert: amountToConvert,
currency: currency,
showDecimals: showDecimals,
integerStyle: integerStyle,
decimalsStyle: decimalsStyle,
currencyStyle: currencyStyle,
).getTextWidget(context),
);
final displayer = _amountDisplayer(context, currency: currency!);

if (followPrivateMode) {
return BlurBasedOnPrivateMode(child: displayer);
} else {
return displayer;
}
}

return BlurBasedOnPrivateMode(
child: StreamBuilder(
stream: CurrencyService.instance.getUserPreferredCurrency(),
builder: (context, snapshot) {
if (!snapshot.hasData) {
return Skeleton(width: 50, height: valueFontSize);
}

return UINumberFormatter.currency(
amountToConvert: amountToConvert,
currency: snapshot.data!,
showDecimals: showDecimals,
integerStyle: integerStyle,
decimalsStyle: decimalsStyle,
currencyStyle: currencyStyle,
).getTextWidget(context);
}),
return StreamBuilder(
stream: CurrencyService.instance.getUserPreferredCurrency(),
builder: (context, snapshot) {
if (!snapshot.hasData) {
return Skeleton(width: 50, height: valueFontSize);
}

final displayer = _amountDisplayer(context, currency: snapshot.data!);

if (followPrivateMode) {
return BlurBasedOnPrivateMode(child: displayer);
} else {
return displayer;
}
},
);
}
}
Expand Down

0 comments on commit 58027e1

Please sign in to comment.