mirror of
https://github.com/koloideal/Casha.git
synced 2026-06-10 10:25:28 +03:00
update
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import '../../core/constants.dart';
|
||||
|
||||
class AmountFormatNotifier extends StateNotifier<AmountFormat> {
|
||||
AmountFormatNotifier() : super(AmountFormat.commasDot) {
|
||||
_load();
|
||||
}
|
||||
|
||||
void _load() async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
final index = prefs.getInt('amount_format') ?? 0;
|
||||
state = AmountFormat.values[index];
|
||||
}
|
||||
|
||||
void set(AmountFormat format) async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
state = format;
|
||||
await prefs.setInt('amount_format', format.index);
|
||||
}
|
||||
}
|
||||
|
||||
final amountFormatProvider = StateNotifierProvider<AmountFormatNotifier, AmountFormat>(
|
||||
(ref) => AmountFormatNotifier(),
|
||||
);
|
||||
@@ -1,9 +1,9 @@
|
||||
String formatAmount(String symbol, double amount) {
|
||||
import '../../core/constants.dart';
|
||||
|
||||
String formatAmount(String symbol, double amount, AmountFormat fmt) {
|
||||
// Symbols that need a space after them (prefix symbols like Br, ₽ etc.)
|
||||
const spaceAfter = {'Br', '₽'};
|
||||
final formatted = amount.toStringAsFixed(2);
|
||||
if (spaceAfter.contains(symbol)) {
|
||||
return '$symbol $formatted';
|
||||
}
|
||||
return '$symbol$formatted';
|
||||
final formatted = fmt.format(amount);
|
||||
final sep = spaceAfter.contains(symbol) ? ' ' : '';
|
||||
return '$symbol$sep$formatted';
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user