mirror of
https://github.com/koloideal/Casha.git
synced 2026-08-08 17:51:14 +03:00
Compare commits
7 Commits
1a6ad1fe27
...
4727835402
| Author | SHA1 | Date | |
|---|---|---|---|
| 4727835402 | |||
| 65ea30339d | |||
| 3adac05cdf | |||
| 5891440a0c | |||
| f2d444cb16 | |||
| 2b89545248 | |||
| 6fdf4eedf1 |
@@ -20,6 +20,15 @@ lib/
|
|||||||
├── data/ # Database schema, repositories
|
├── data/ # Database schema, repositories
|
||||||
├── features/ # Feature modules (provider + screen + widgets)
|
├── features/ # Feature modules (provider + screen + widgets)
|
||||||
├── shared/ # Cross-feature models, providers, services, widgets
|
├── shared/ # Cross-feature models, providers, services, widgets
|
||||||
|
│ ├── feature_flags/
|
||||||
|
│ │ ├── feature_flags.dart # abstract class FeatureFlags
|
||||||
|
│ │ ├── free_feature_flags.dart # FreeFeatureFlags implements FeatureFlags
|
||||||
|
│ │ ├── vip_feature_flags.dart # VipFeatureFlags implements FeatureFlags
|
||||||
|
│ │ └── feature_flags_provider.dart # featureFlagsProvider
|
||||||
|
│ └── paywall/
|
||||||
|
│ ├── paywall_guard.dart # PaywallGuard widget
|
||||||
|
│ ├── paywall_banner.dart # inline upsell banner
|
||||||
|
│ └── paywall_screen.dart # full-screen paywall
|
||||||
└── main.dart
|
└── main.dart
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -46,6 +55,8 @@ lib/
|
|||||||
- `services/` — `ExchangeRateService`, `StorageService`
|
- `services/` — `ExchangeRateService`, `StorageService`
|
||||||
- `utils/` — `CurrencyUtils`
|
- `utils/` — `CurrencyUtils`
|
||||||
- `widgets/` — `BynSign`, `ErrorSnackbar`
|
- `widgets/` — `BynSign`, `ErrorSnackbar`
|
||||||
|
- `feature_flags/` — `FeatureFlags` abstraction and plan-specific implementations
|
||||||
|
- `paywall/` — `PaywallGuard`, `PaywallBanner`, `PaywallScreen`
|
||||||
|
|
||||||
## Architecture Rules
|
## Architecture Rules
|
||||||
|
|
||||||
@@ -57,6 +68,14 @@ lib/
|
|||||||
- Database queries are in repositories only — no raw Drift queries in providers or widgets
|
- Database queries are in repositories only — no raw Drift queries in providers or widgets
|
||||||
- After any changes to Drift tables or DAOs, run `dart run build_runner build --delete-conflicting-outputs`
|
- After any changes to Drift tables or DAOs, run `dart run build_runner build --delete-conflicting-outputs`
|
||||||
|
|
||||||
|
### Feature Gating Rules
|
||||||
|
|
||||||
|
- Never check `user.isVip` or `plan == UserPlan.vip` directly in widgets or screens
|
||||||
|
- All access control goes through `featureFlagsProvider` — read the relevant flag, wrap with `PaywallGuard`
|
||||||
|
- Quantity limits (e.g. max accounts) are enforced inside repositories, not in widgets — throw `FeatureLimitException` on violation
|
||||||
|
- Routes that are entirely VIP-only use GoRouter `redirect` reading `featureFlagsProvider`
|
||||||
|
- Adding a new gated feature means: add a getter to `FeatureFlags`, implement in `FreeFeatureFlags` and `VipFeatureFlags`, then use in UI/repo
|
||||||
|
|
||||||
## Code Style
|
## Code Style
|
||||||
|
|
||||||
**No comments anywhere in the codebase.** No `//`, no `/* */`, no `///` doc comments. Code must be self-explanatory through naming.
|
**No comments anywhere in the codebase.** No `//`, no `/* */`, no `///` doc comments. Code must be self-explanatory through naming.
|
||||||
@@ -110,6 +129,44 @@ result.when(
|
|||||||
|
|
||||||
**Colors for accounts** — use `CardColorService`, not hardcoded colors.
|
**Colors for accounts** — use `CardColorService`, not hardcoded colors.
|
||||||
|
|
||||||
|
**Feature gating** — wrap gated UI with `PaywallGuard`:
|
||||||
|
```dart
|
||||||
|
class ExportScreen extends ConsumerWidget {
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context, WidgetRef ref) {
|
||||||
|
final flags = ref.watch(featureFlagsProvider);
|
||||||
|
return PaywallGuard(
|
||||||
|
canAccess: flags.canExportCsv,
|
||||||
|
child: ExportContent(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**Quantity limits in repositories**:
|
||||||
|
```dart
|
||||||
|
Future<Result<void>> createAccount(Account account) async {
|
||||||
|
final flags = ref.read(featureFlagsProvider);
|
||||||
|
final count = await _db.countAccounts();
|
||||||
|
if (flags.maxAccounts != -1 && count >= flags.maxAccounts) {
|
||||||
|
return Result.failure(FeatureLimitException());
|
||||||
|
}
|
||||||
|
return Result.success(await _db.insertAccount(account));
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**VIP-only routes** — use GoRouter redirect, never guard inside the screen itself:
|
||||||
|
```dart
|
||||||
|
GoRoute(
|
||||||
|
path: '/analytics',
|
||||||
|
redirect: (context, state) {
|
||||||
|
final flags = ref.read(featureFlagsProvider);
|
||||||
|
return flags.canSeeAnalytics ? null : '/paywall';
|
||||||
|
},
|
||||||
|
builder: (context, state) => AnalyticsScreen(),
|
||||||
|
),
|
||||||
|
```
|
||||||
|
|
||||||
## Existing Features
|
## Existing Features
|
||||||
|
|
||||||
- **dashboard** — main screen with account carousel (`BalanceCard`), transaction list, search, filter chips, budget progress, account editor overlay
|
- **dashboard** — main screen with account carousel (`BalanceCard`), transaction list, search, filter chips, budget progress, account editor overlay
|
||||||
@@ -126,3 +183,6 @@ result.when(
|
|||||||
- Do not use `BuildContext` across async gaps without checking `mounted`
|
- Do not use `BuildContext` across async gaps without checking `mounted`
|
||||||
- Do not hardcode user-facing strings — use `AppStrings`
|
- Do not hardcode user-facing strings — use `AppStrings`
|
||||||
- Do not format currency amounts manually — use `CurrencyUtils`
|
- Do not format currency amounts manually — use `CurrencyUtils`
|
||||||
|
- Do not check `user.isVip` or `plan == UserPlan.vip` in widgets or screens — use `featureFlagsProvider`
|
||||||
|
- Do not enforce feature limits in widgets — put them in repositories and throw `FeatureLimitException`
|
||||||
|
- Do not add a new gated feature without adding a corresponding getter to `FeatureFlags` and implementing it in both `FreeFeatureFlags` and `VipFeatureFlags`
|
||||||
@@ -8,6 +8,7 @@ import '../features/categories/screen.dart';
|
|||||||
import '../features/settings/screen.dart';
|
import '../features/settings/screen.dart';
|
||||||
import '../features/settings/categories/category_manager_screen.dart';
|
import '../features/settings/categories/category_manager_screen.dart';
|
||||||
import '../shared/models/transaction.dart';
|
import '../shared/models/transaction.dart';
|
||||||
|
import '../shared/paywall/paywall_screen.dart';
|
||||||
|
|
||||||
final _shellKey = GlobalKey<NavigatorState>();
|
final _shellKey = GlobalKey<NavigatorState>();
|
||||||
|
|
||||||
@@ -49,6 +50,10 @@ final appRouter = GoRouter(
|
|||||||
path: '/settings/categories',
|
path: '/settings/categories',
|
||||||
builder: (context, state) => const CategoryManagerScreen(),
|
builder: (context, state) => const CategoryManagerScreen(),
|
||||||
),
|
),
|
||||||
|
GoRoute(
|
||||||
|
path: '/paywall',
|
||||||
|
builder: (context, state) => const PaywallScreen(),
|
||||||
|
),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -26,6 +26,14 @@ class AppCategories {
|
|||||||
'Shopping',
|
'Shopping',
|
||||||
'Health',
|
'Health',
|
||||||
'Entertainment',
|
'Entertainment',
|
||||||
|
'Housing',
|
||||||
|
'Education',
|
||||||
|
'Travel',
|
||||||
|
'Utilities',
|
||||||
|
'Clothing',
|
||||||
|
'Sports',
|
||||||
|
'Beauty',
|
||||||
|
'Pets',
|
||||||
'Other'
|
'Other'
|
||||||
];
|
];
|
||||||
|
|
||||||
@@ -35,6 +43,8 @@ class AppCategories {
|
|||||||
'Gift',
|
'Gift',
|
||||||
'Investment',
|
'Investment',
|
||||||
'Refund',
|
'Refund',
|
||||||
|
'Business',
|
||||||
|
'Savings',
|
||||||
'Other'
|
'Other'
|
||||||
];
|
];
|
||||||
|
|
||||||
@@ -50,11 +60,21 @@ class AppCategories {
|
|||||||
'Shopping': Icons.shopping_bag_rounded,
|
'Shopping': Icons.shopping_bag_rounded,
|
||||||
'Health': Icons.favorite_rounded,
|
'Health': Icons.favorite_rounded,
|
||||||
'Entertainment': Icons.movie_rounded,
|
'Entertainment': Icons.movie_rounded,
|
||||||
|
'Housing': Icons.home_rounded,
|
||||||
|
'Education': Icons.school_rounded,
|
||||||
|
'Travel': Icons.flight_rounded,
|
||||||
|
'Utilities': Icons.bolt_rounded,
|
||||||
|
'Clothing': Icons.checkroom_rounded,
|
||||||
|
'Sports': Icons.fitness_center_rounded,
|
||||||
|
'Beauty': Icons.brush_rounded,
|
||||||
|
'Pets': Icons.pets_rounded,
|
||||||
'Salary': Icons.work_rounded,
|
'Salary': Icons.work_rounded,
|
||||||
'Freelance': Icons.laptop_rounded,
|
'Freelance': Icons.laptop_rounded,
|
||||||
'Gift': Icons.card_giftcard_rounded,
|
'Gift': Icons.card_giftcard_rounded,
|
||||||
'Investment': Icons.trending_up_rounded,
|
'Investment': Icons.trending_up_rounded,
|
||||||
'Refund': Icons.money_rounded,
|
'Refund': Icons.money_rounded,
|
||||||
|
'Business': Icons.business_center_rounded,
|
||||||
|
'Savings': Icons.savings_rounded,
|
||||||
'Other': Icons.category_rounded,
|
'Other': Icons.category_rounded,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -64,11 +84,21 @@ class AppCategories {
|
|||||||
'Shopping': Color(0xFFFFD369),
|
'Shopping': Color(0xFFFFD369),
|
||||||
'Health': Color(0xFF69FFB4),
|
'Health': Color(0xFF69FFB4),
|
||||||
'Entertainment': Color(0xFFFF69B4),
|
'Entertainment': Color(0xFFFF69B4),
|
||||||
|
'Housing': Color(0xFF69B4FF),
|
||||||
|
'Education': Color(0xFFFFB469),
|
||||||
|
'Travel': Color(0xFF69FFB4),
|
||||||
|
'Utilities': Color(0xFFFFD369),
|
||||||
|
'Clothing': Color(0xFFFF69B4),
|
||||||
|
'Sports': Color(0xFF69FFB4),
|
||||||
|
'Beauty': Color(0xFFFF69B4),
|
||||||
|
'Pets': Color(0xFFB4FF69),
|
||||||
'Salary': Color(0xFF4CAF8C),
|
'Salary': Color(0xFF4CAF8C),
|
||||||
'Freelance': Color(0xFF69FFB4),
|
'Freelance': Color(0xFF69FFB4),
|
||||||
'Gift': Color(0xFFFFB469),
|
'Gift': Color(0xFFFFB469),
|
||||||
'Investment': Color(0xFF69B4FF),
|
'Investment': Color(0xFF69B4FF),
|
||||||
'Refund': Color(0xFFB4FF69),
|
'Refund': Color(0xFFB4FF69),
|
||||||
|
'Business': Color(0xFFFF8C69),
|
||||||
|
'Savings': Color(0xFF4CAF8C),
|
||||||
'Other': Color(0xFFB469FF),
|
'Other': Color(0xFFB469FF),
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -78,11 +108,21 @@ class AppCategories {
|
|||||||
'Shopping': 'shopping_bag',
|
'Shopping': 'shopping_bag',
|
||||||
'Health': 'heart',
|
'Health': 'heart',
|
||||||
'Entertainment': 'movie',
|
'Entertainment': 'movie',
|
||||||
|
'Housing': 'home',
|
||||||
|
'Education': 'school',
|
||||||
|
'Travel': 'flight',
|
||||||
|
'Utilities': 'bolt',
|
||||||
|
'Clothing': 'checkroom',
|
||||||
|
'Sports': 'fitness',
|
||||||
|
'Beauty': 'brush',
|
||||||
|
'Pets': 'pets',
|
||||||
'Salary': 'work',
|
'Salary': 'work',
|
||||||
'Freelance': 'laptop',
|
'Freelance': 'laptop',
|
||||||
'Gift': 'gift',
|
'Gift': 'gift',
|
||||||
'Investment': 'trending_up',
|
'Investment': 'trending_up',
|
||||||
'Refund': 'money',
|
'Refund': 'money',
|
||||||
|
'Business': 'work',
|
||||||
|
'Savings': 'savings',
|
||||||
'Other': 'category',
|
'Other': 'category',
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -108,6 +148,22 @@ class AppCategories {
|
|||||||
'Pets': 'Питомцы',
|
'Pets': 'Питомцы',
|
||||||
'Business': 'Бизнес',
|
'Business': 'Бизнес',
|
||||||
'Savings': 'Накопления',
|
'Savings': 'Накопления',
|
||||||
|
'Dining': 'Ресторан',
|
||||||
|
'Cafe': 'Кафе',
|
||||||
|
'Coffee': 'Кофе',
|
||||||
|
'Restaurant': 'Ресторан',
|
||||||
|
'Fuel': 'Топливо',
|
||||||
|
'Taxi': 'Такси',
|
||||||
|
'Phone': 'Связь',
|
||||||
|
'Internet': 'Интернет',
|
||||||
|
'Insurance': 'Страховка',
|
||||||
|
'Taxes': 'Налоги',
|
||||||
|
'Medicine': 'Медицина',
|
||||||
|
'Children': 'Дети',
|
||||||
|
'Hobby': 'Хобби',
|
||||||
|
'Music': 'Музыка',
|
||||||
|
'Games': 'Игры',
|
||||||
|
'Books': 'Книги',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -168,7 +168,7 @@ class AppStrings {
|
|||||||
}
|
}
|
||||||
|
|
||||||
String get colorPrimary => _ru ? 'Основной' : 'Primary';
|
String get colorPrimary => _ru ? 'Основной' : 'Primary';
|
||||||
String get colorSecondary => _ru ? 'Второй' : 'Secondary';
|
String get colorSecondary => _ru ? 'Второй' : 'Second';
|
||||||
String get colorSecond => _ru ? 'Второй' : 'Second';
|
String get colorSecond => _ru ? 'Второй' : 'Second';
|
||||||
String get colorSolid => _ru ? 'Однотон' : 'Solid';
|
String get colorSolid => _ru ? 'Однотон' : 'Solid';
|
||||||
String get gradientLinear => _ru ? 'Линейный' : 'Linear';
|
String get gradientLinear => _ru ? 'Линейный' : 'Linear';
|
||||||
@@ -239,4 +239,26 @@ class AppStrings {
|
|||||||
String get categorySaved => _ru ? 'Категория сохранена' : 'Category saved';
|
String get categorySaved => _ru ? 'Категория сохранена' : 'Category saved';
|
||||||
|
|
||||||
String get dateLocale => _ru ? 'ru_RU' : 'en_US';
|
String get dateLocale => _ru ? 'ru_RU' : 'en_US';
|
||||||
|
|
||||||
|
String get premium => _ru ? 'Премиум' : 'Premium';
|
||||||
|
String get premiumStatus => _ru ? 'Статус премиум' : 'Premium status';
|
||||||
|
String get premiumDescription => _ru
|
||||||
|
? 'Разблокируйте цвета карточек, высоту и до 8 счетов'
|
||||||
|
: 'Unlock card colors, card height and up to 8 accounts';
|
||||||
|
String get premiumEnabled => _ru ? 'Включён' : 'Enabled';
|
||||||
|
String get premiumDisabled => _ru ? 'Выключен' : 'Disabled';
|
||||||
|
String get premiumFeatureLocked =>
|
||||||
|
_ru ? 'Доступно в премиум' : 'Premium feature';
|
||||||
|
String get accountLimitReached => _ru
|
||||||
|
? 'Достигнут лиммт счетов. Обновите до премиум для большего количества.'
|
||||||
|
: 'Account limit reached. Upgrade to premium for more accounts.';
|
||||||
|
String accountsLimitLabel(int max) =>
|
||||||
|
_ru ? 'Максимум $max счетов.' : 'Maximum $max accounts.';
|
||||||
|
|
||||||
|
String get premiumFeatureColors =>
|
||||||
|
_ru ? 'Настройка цветов карточек' : 'Custom card colors';
|
||||||
|
String get premiumFeatureHeight =>
|
||||||
|
_ru ? 'Изменение высоты карточки' : 'Resizable card height';
|
||||||
|
String get premiumFeatureAccounts =>
|
||||||
|
_ru ? 'До 8 счетов' : 'Up to 8 accounts';
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,19 +1,21 @@
|
|||||||
import 'package:drift/drift.dart';
|
import 'package:drift/drift.dart';
|
||||||
import '../database/app_database.dart';
|
import '../database/app_database.dart';
|
||||||
import '../../shared/models/account.dart' as model;
|
import '../../shared/models/account.dart' as model;
|
||||||
|
import '../../shared/feature_flags/feature_flags.dart';
|
||||||
|
|
||||||
class AccountLimitException implements Exception {
|
class FeatureLimitException implements Exception {
|
||||||
final String message;
|
final String message;
|
||||||
AccountLimitException(this.message);
|
FeatureLimitException(this.message);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String toString() => 'AccountLimitException: $message';
|
String toString() => 'FeatureLimitException: $message';
|
||||||
}
|
}
|
||||||
|
|
||||||
class AccountRepository {
|
class AccountRepository {
|
||||||
final AppDatabase _db;
|
final AppDatabase _db;
|
||||||
|
final FeatureFlags _featureFlags;
|
||||||
|
|
||||||
AccountRepository(this._db);
|
AccountRepository(this._db, this._featureFlags);
|
||||||
|
|
||||||
Stream<List<model.Account>> watchAll() {
|
Stream<List<model.Account>> watchAll() {
|
||||||
return (_db.select(_db.accounts)
|
return (_db.select(_db.accounts)
|
||||||
@@ -163,6 +165,11 @@ class AccountRepository {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<int> add(model.Account account) async {
|
Future<int> add(model.Account account) async {
|
||||||
|
final existing = await getAll();
|
||||||
|
final nonMainCount = existing.where((a) => !a.isMain).length;
|
||||||
|
if (nonMainCount >= _featureFlags.maxAccounts) {
|
||||||
|
throw FeatureLimitException('Account limit reached (${_featureFlags.maxAccounts})');
|
||||||
|
}
|
||||||
return await _db.into(_db.accounts).insert(
|
return await _db.into(_db.accounts).insert(
|
||||||
AccountsCompanion.insert(
|
AccountsCompanion.insert(
|
||||||
name: account.name,
|
name: account.name,
|
||||||
|
|||||||
@@ -396,7 +396,7 @@ class _AddTransactionScreenState extends ConsumerState<AddTransactionScreen>
|
|||||||
child: child!,
|
child: child!,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
if (picked != null) {
|
if (picked != null && mounted) {
|
||||||
setState(() => _selectedDate = picked);
|
setState(() => _selectedDate = picked);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -423,7 +423,7 @@ class _AddTransactionScreenState extends ConsumerState<AddTransactionScreen>
|
|||||||
child: child!,
|
child: child!,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
if (picked != null) {
|
if (picked != null && mounted) {
|
||||||
setState(() => _selectedTime = picked);
|
setState(() => _selectedTime = picked);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,6 +27,9 @@ class AccountSelector extends ConsumerWidget {
|
|||||||
|
|
||||||
return accountsAsync.when(
|
return accountsAsync.when(
|
||||||
data: (accounts) {
|
data: (accounts) {
|
||||||
|
if (accounts.isEmpty) {
|
||||||
|
return const SizedBox.shrink();
|
||||||
|
}
|
||||||
final txAccountId = ref
|
final txAccountId = ref
|
||||||
.read(addTransactionProvider(initial))
|
.read(addTransactionProvider(initial))
|
||||||
.selectedAccountId;
|
.selectedAccountId;
|
||||||
|
|||||||
@@ -3,6 +3,20 @@ import '../../shared/models/transaction.dart';
|
|||||||
import '../dashboard/provider.dart';
|
import '../dashboard/provider.dart';
|
||||||
import '../settings/provider.dart';
|
import '../settings/provider.dart';
|
||||||
|
|
||||||
|
enum StatsTimeFilter { allTime, month }
|
||||||
|
|
||||||
|
final statsTimeFilterProvider =
|
||||||
|
NotifierProvider<_StatsTimeFilterNotifier, StatsTimeFilter>(
|
||||||
|
_StatsTimeFilterNotifier.new,
|
||||||
|
);
|
||||||
|
|
||||||
|
class _StatsTimeFilterNotifier extends Notifier<StatsTimeFilter> {
|
||||||
|
@override
|
||||||
|
StatsTimeFilter build() => StatsTimeFilter.month;
|
||||||
|
|
||||||
|
void set(StatsTimeFilter v) => state = v;
|
||||||
|
}
|
||||||
|
|
||||||
class StatsSummary {
|
class StatsSummary {
|
||||||
final double income;
|
final double income;
|
||||||
final double expense;
|
final double expense;
|
||||||
@@ -43,10 +57,10 @@ CurrencyInfo _statsCurrencyInfo(Ref ref) {
|
|||||||
|
|
||||||
List<Transaction> _statsScopedTransactions(Ref ref) {
|
List<Transaction> _statsScopedTransactions(Ref ref) {
|
||||||
final txs = ref.watch(accountFilteredTransactionsProvider);
|
final txs = ref.watch(accountFilteredTransactionsProvider);
|
||||||
final timeFilter = ref.watch(timeFilterProvider);
|
final timeFilter = ref.watch(statsTimeFilterProvider);
|
||||||
var filtered = txs.where((t) => t.category != 'Transfer');
|
var filtered = txs.where((t) => t.category != 'Transfer');
|
||||||
|
|
||||||
if (timeFilter == TimeFilter.lastMonth) {
|
if (timeFilter == StatsTimeFilter.month) {
|
||||||
final now = DateTime.now();
|
final now = DateTime.now();
|
||||||
filtered = filtered.where(
|
filtered = filtered.where(
|
||||||
(t) => t.date.year == now.year && t.date.month == now.month,
|
(t) => t.date.year == now.year && t.date.month == now.month,
|
||||||
|
|||||||
@@ -30,15 +30,13 @@ class _CategoriesScreenState extends ConsumerState<CategoriesScreen> {
|
|||||||
final s = ref.watch(stringsProvider);
|
final s = ref.watch(stringsProvider);
|
||||||
final isRu = s.locale == AppLocale.ru;
|
final isRu = s.locale == AppLocale.ru;
|
||||||
final catalog = ref.watch(categoryCatalogProvider);
|
final catalog = ref.watch(categoryCatalogProvider);
|
||||||
|
final timeFilter = ref.watch(statsTimeFilterProvider);
|
||||||
final summary = ref.watch(statsSummaryProvider);
|
final summary = ref.watch(statsSummaryProvider);
|
||||||
final data = _showIncome
|
final data = _showIncome
|
||||||
? ref.watch(categoryIncomeProvider)
|
? ref.watch(categoryIncomeProvider)
|
||||||
: ref.watch(categoryExpenseProvider);
|
: ref.watch(categoryExpenseProvider);
|
||||||
final total = data.values.fold(0.0, (a, b) => a + b);
|
final total = data.values.fold(0.0, (a, b) => a + b);
|
||||||
final currencyInfo = ref.watch(statsCurrencyProvider);
|
final currencyInfo = ref.watch(statsCurrencyProvider);
|
||||||
final monthlyData = _showIncome
|
|
||||||
? ref.watch(monthlyIncomeBreakdownProvider)
|
|
||||||
: ref.watch(monthlyBreakdownProvider);
|
|
||||||
|
|
||||||
final sortedEntries = data.entries.toList()
|
final sortedEntries = data.entries.toList()
|
||||||
..sort((a, b) => b.value.compareTo(a.value));
|
..sort((a, b) => b.value.compareTo(a.value));
|
||||||
@@ -47,22 +45,16 @@ class _CategoriesScreenState extends ConsumerState<CategoriesScreen> {
|
|||||||
|
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
backgroundColor: Theme.of(context).scaffoldBackgroundColor,
|
backgroundColor: Theme.of(context).scaffoldBackgroundColor,
|
||||||
appBar: AppBar(
|
|
||||||
title: Text(
|
|
||||||
s.statistics,
|
|
||||||
style: Theme.of(context).textTheme.titleLarge?.copyWith(
|
|
||||||
fontWeight: FontWeight.w700,
|
|
||||||
color: Theme.of(context).colorScheme.onSurface,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
body: SafeArea(
|
body: SafeArea(
|
||||||
child: ListView(
|
child: ListView(
|
||||||
padding: const EdgeInsets.fromLTRB(20, 8, 20, 100),
|
padding: const EdgeInsets.fromLTRB(20, 16, 20, 100),
|
||||||
children: [
|
children: [
|
||||||
const AccountScopeChips(),
|
const AccountScopeChips(),
|
||||||
const SizedBox(height: 16),
|
const SizedBox(height: 16),
|
||||||
_IncomeExpenseToggle(
|
Row(
|
||||||
|
children: [
|
||||||
|
Expanded(
|
||||||
|
child: _IncomeExpenseToggle(
|
||||||
isIncome: _showIncome,
|
isIncome: _showIncome,
|
||||||
onChanged: (val) {
|
onChanged: (val) {
|
||||||
HapticService.selection();
|
HapticService.selection();
|
||||||
@@ -72,58 +64,37 @@ class _CategoriesScreenState extends ConsumerState<CategoriesScreen> {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
const SizedBox(height: 16),
|
|
||||||
_InsightCard(
|
|
||||||
title: s.overview,
|
|
||||||
subtitle: s.analyticsInsight,
|
|
||||||
child: GridView.count(
|
|
||||||
crossAxisCount: 2,
|
|
||||||
shrinkWrap: true,
|
|
||||||
physics: const NeverScrollableScrollPhysics(),
|
|
||||||
mainAxisSpacing: 10,
|
|
||||||
crossAxisSpacing: 10,
|
|
||||||
childAspectRatio: 1.22,
|
|
||||||
children: [
|
|
||||||
_MetricTile(
|
|
||||||
label: s.income,
|
|
||||||
value: summary.income,
|
|
||||||
currencyInfo: currencyInfo,
|
|
||||||
color: AppColors.income,
|
|
||||||
icon: Icons.south_west_rounded,
|
|
||||||
),
|
),
|
||||||
_MetricTile(
|
const SizedBox(width: 10),
|
||||||
label: s.expenses,
|
Expanded(
|
||||||
value: summary.expense,
|
child: _TimePeriodToggle(
|
||||||
currencyInfo: currencyInfo,
|
filter: timeFilter,
|
||||||
color: AppColors.expense,
|
onChanged: (val) {
|
||||||
icon: Icons.north_east_rounded,
|
HapticService.selection();
|
||||||
|
ref.read(statsTimeFilterProvider.notifier).set(val);
|
||||||
|
setState(() => _touchedIndex = -1);
|
||||||
|
},
|
||||||
),
|
),
|
||||||
_MetricTile(
|
|
||||||
label: s.netBalance,
|
|
||||||
value: summary.balance,
|
|
||||||
currencyInfo: currencyInfo,
|
|
||||||
color: summary.balance >= 0 ? AppColors.accent : AppColors.warning,
|
|
||||||
icon: Icons.account_balance_wallet_rounded,
|
|
||||||
),
|
|
||||||
_CountTile(
|
|
||||||
label: s.transactionsCount,
|
|
||||||
value: summary.transactionCount,
|
|
||||||
color: AppColors.accent,
|
|
||||||
icon: Icons.receipt_long_rounded,
|
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
const SizedBox(height: 16),
|
||||||
|
_OverviewCard(
|
||||||
|
isIncome: _showIncome,
|
||||||
|
amount: _showIncome ? summary.income : summary.expense,
|
||||||
|
transactionCount: summary.transactionCount,
|
||||||
|
currencyInfo: currencyInfo,
|
||||||
),
|
),
|
||||||
const SizedBox(height: 16),
|
const SizedBox(height: 16),
|
||||||
_InsightCard(
|
// _InsightCard(
|
||||||
title: s.monthlyTrend,
|
// title: s.monthlyTrend,
|
||||||
subtitle: s.lastSixMonths,
|
// subtitle: s.lastSixMonths,
|
||||||
child: _MonthlyTrendSection(
|
// child: _MonthlyTrendSection(
|
||||||
data: monthlyData,
|
// data: monthlyData,
|
||||||
color: _showIncome ? AppColors.income : AppColors.expense,
|
// color: _showIncome ? AppColors.income : AppColors.expense,
|
||||||
),
|
// ),
|
||||||
),
|
// ),
|
||||||
const SizedBox(height: 16),
|
// const SizedBox(height: 16),
|
||||||
if (data.isEmpty)
|
if (data.isEmpty)
|
||||||
_EmptyState(isIncome: _showIncome)
|
_EmptyState(isIncome: _showIncome)
|
||||||
else ...[
|
else ...[
|
||||||
@@ -252,6 +223,9 @@ class _PieChartSection extends ConsumerWidget {
|
|||||||
final fmt = ref.watch(amountFormatProvider);
|
final fmt = ref.watch(amountFormatProvider);
|
||||||
final entries = data.entries.toList();
|
final entries = data.entries.toList();
|
||||||
final accent = isIncome ? AppColors.income : AppColors.expense;
|
final accent = isIncome ? AppColors.income : AppColors.expense;
|
||||||
|
if (entries.isEmpty) {
|
||||||
|
return const SizedBox.shrink();
|
||||||
|
}
|
||||||
final selectedIndex = touchedIndex >= 0 ? touchedIndex : 0;
|
final selectedIndex = touchedIndex >= 0 ? touchedIndex : 0;
|
||||||
final selectedEntry = entries[selectedIndex.clamp(0, entries.length - 1)];
|
final selectedEntry = entries[selectedIndex.clamp(0, entries.length - 1)];
|
||||||
final selectedAmount = selectedEntry.value;
|
final selectedAmount = selectedEntry.value;
|
||||||
@@ -287,7 +261,9 @@ class _PieChartSection extends ConsumerWidget {
|
|||||||
color: color,
|
color: color,
|
||||||
value: val,
|
value: val,
|
||||||
title: isTouched
|
title: isTouched
|
||||||
|
? total > 0
|
||||||
? '${(val / total * 100).toStringAsFixed(0)}%'
|
? '${(val / total * 100).toStringAsFixed(0)}%'
|
||||||
|
: '0%'
|
||||||
: '',
|
: '',
|
||||||
radius: isTouched ? 60 : 52,
|
radius: isTouched ? 60 : 52,
|
||||||
titleStyle: const TextStyle(
|
titleStyle: const TextStyle(
|
||||||
@@ -360,7 +336,9 @@ class _PieChartSection extends ConsumerWidget {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
Text(
|
Text(
|
||||||
'${(selectedAmount / total * 100).toStringAsFixed(1)}%',
|
total > 0
|
||||||
|
? '${(selectedAmount / total * 100).toStringAsFixed(1)}%'
|
||||||
|
: '0%',
|
||||||
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
|
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
|
||||||
fontWeight: FontWeight.w700,
|
fontWeight: FontWeight.w700,
|
||||||
color: accent,
|
color: accent,
|
||||||
@@ -867,6 +845,121 @@ class _EmptyState extends ConsumerWidget {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class _TimePeriodToggle extends ConsumerWidget {
|
||||||
|
final StatsTimeFilter filter;
|
||||||
|
final ValueChanged<StatsTimeFilter> onChanged;
|
||||||
|
|
||||||
|
const _TimePeriodToggle({
|
||||||
|
required this.filter,
|
||||||
|
required this.onChanged,
|
||||||
|
});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context, WidgetRef ref) {
|
||||||
|
final s = ref.watch(stringsProvider);
|
||||||
|
final theme = Theme.of(context);
|
||||||
|
|
||||||
|
return Container(
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: theme.colorScheme.surface,
|
||||||
|
borderRadius: BorderRadius.circular(12),
|
||||||
|
border: Border.all(
|
||||||
|
color: theme.colorScheme.onSurface.withOpacity(0.06),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
padding: const EdgeInsets.all(2),
|
||||||
|
child: Row(
|
||||||
|
children: [
|
||||||
|
Expanded(
|
||||||
|
child: _ToggleChip(
|
||||||
|
label: s.filterMonth,
|
||||||
|
isSelected: filter == StatsTimeFilter.month,
|
||||||
|
color: AppColors.accent,
|
||||||
|
onTap: () => onChanged(StatsTimeFilter.month),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Expanded(
|
||||||
|
child: _ToggleChip(
|
||||||
|
label: s.filterAllTime,
|
||||||
|
isSelected: filter == StatsTimeFilter.allTime,
|
||||||
|
color: AppColors.accent,
|
||||||
|
onTap: () => onChanged(StatsTimeFilter.allTime),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class _OverviewCard extends ConsumerWidget {
|
||||||
|
final bool isIncome;
|
||||||
|
final double amount;
|
||||||
|
final int transactionCount;
|
||||||
|
final CurrencyInfo currencyInfo;
|
||||||
|
|
||||||
|
const _OverviewCard({
|
||||||
|
required this.isIncome,
|
||||||
|
required this.amount,
|
||||||
|
required this.transactionCount,
|
||||||
|
required this.currencyInfo,
|
||||||
|
});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context, WidgetRef ref) {
|
||||||
|
final s = ref.watch(stringsProvider);
|
||||||
|
final fmt = ref.watch(amountFormatProvider);
|
||||||
|
final theme = Theme.of(context);
|
||||||
|
final color = isIncome ? AppColors.income : AppColors.expense;
|
||||||
|
|
||||||
|
return Container(
|
||||||
|
width: double.infinity,
|
||||||
|
padding: const EdgeInsets.symmetric(vertical: 28, horizontal: 20),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: theme.colorScheme.surface,
|
||||||
|
borderRadius: BorderRadius.circular(24),
|
||||||
|
border: Border.all(
|
||||||
|
color: theme.colorScheme.onSurface.withOpacity(0.06),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
child: Column(
|
||||||
|
children: [
|
||||||
|
Text(
|
||||||
|
isIncome ? s.income : s.expenses,
|
||||||
|
style: theme.textTheme.bodySmall?.copyWith(
|
||||||
|
color: theme.colorScheme.onSurface.withOpacity(0.5),
|
||||||
|
fontWeight: FontWeight.w600,
|
||||||
|
fontSize: 13,
|
||||||
|
letterSpacing: 0.5,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 12),
|
||||||
|
FittedBox(
|
||||||
|
fit: BoxFit.scaleDown,
|
||||||
|
child: _FormattedAmount(
|
||||||
|
amount: amount,
|
||||||
|
currencyInfo: currencyInfo,
|
||||||
|
color: color,
|
||||||
|
fontSize: 40,
|
||||||
|
fontWeight: FontWeight.w800,
|
||||||
|
format: fmt,
|
||||||
|
center: true,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 14),
|
||||||
|
Text(
|
||||||
|
'$transactionCount ${s.transactionsCount.toLowerCase()}',
|
||||||
|
style: theme.textTheme.bodySmall?.copyWith(
|
||||||
|
color: theme.colorScheme.onSurface.withOpacity(0.4),
|
||||||
|
fontSize: 13,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class _IncomeExpenseToggle extends ConsumerWidget {
|
class _IncomeExpenseToggle extends ConsumerWidget {
|
||||||
final bool isIncome;
|
final bool isIncome;
|
||||||
final ValueChanged<bool> onChanged;
|
final ValueChanged<bool> onChanged;
|
||||||
@@ -889,7 +982,7 @@ class _IncomeExpenseToggle extends ConsumerWidget {
|
|||||||
color: theme.colorScheme.onSurface.withOpacity(0.06),
|
color: theme.colorScheme.onSurface.withOpacity(0.06),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
padding: const EdgeInsets.all(4),
|
padding: const EdgeInsets.all(2),
|
||||||
child: Row(
|
child: Row(
|
||||||
children: [
|
children: [
|
||||||
Expanded(
|
Expanded(
|
||||||
@@ -933,7 +1026,7 @@ class _ToggleChip extends StatelessWidget {
|
|||||||
onTap: onTap,
|
onTap: onTap,
|
||||||
child: AnimatedContainer(
|
child: AnimatedContainer(
|
||||||
duration: const Duration(milliseconds: 200),
|
duration: const Duration(milliseconds: 200),
|
||||||
padding: const EdgeInsets.symmetric(vertical: 10),
|
padding: const EdgeInsets.symmetric(vertical: 8, horizontal: 4),
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: isSelected ? color.withOpacity(0.15) : Colors.transparent,
|
color: isSelected ? color.withOpacity(0.15) : Colors.transparent,
|
||||||
borderRadius: BorderRadius.circular(8),
|
borderRadius: BorderRadius.circular(8),
|
||||||
@@ -941,8 +1034,10 @@ class _ToggleChip extends StatelessWidget {
|
|||||||
child: Text(
|
child: Text(
|
||||||
label,
|
label,
|
||||||
textAlign: TextAlign.center,
|
textAlign: TextAlign.center,
|
||||||
|
maxLines: 1,
|
||||||
|
overflow: TextOverflow.ellipsis,
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
fontSize: 14,
|
fontSize: 13,
|
||||||
fontWeight: isSelected ? FontWeight.w700 : FontWeight.w500,
|
fontWeight: isSelected ? FontWeight.w700 : FontWeight.w500,
|
||||||
color: isSelected
|
color: isSelected
|
||||||
? color
|
? color
|
||||||
|
|||||||
@@ -33,7 +33,15 @@ class AccountScopeChips extends ConsumerWidget {
|
|||||||
HapticService.selection();
|
HapticService.selection();
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
const SizedBox(width: 6),
|
if (accounts.isNotEmpty) ...[
|
||||||
|
const SizedBox(width: 8),
|
||||||
|
Container(
|
||||||
|
width: 1,
|
||||||
|
height: 16,
|
||||||
|
color: Theme.of(context).colorScheme.onSurface.withOpacity(0.15),
|
||||||
|
),
|
||||||
|
const SizedBox(width: 8),
|
||||||
|
],
|
||||||
...accounts.asMap().entries.map((entry) {
|
...accounts.asMap().entries.map((entry) {
|
||||||
final index = entry.key + 1;
|
final index = entry.key + 1;
|
||||||
final account = entry.value;
|
final account = entry.value;
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import '../../core/utils/result.dart';
|
|||||||
import '../../data/database/app_database.dart' as db;
|
import '../../data/database/app_database.dart' as db;
|
||||||
import '../../data/repositories/transaction_repository.dart';
|
import '../../data/repositories/transaction_repository.dart';
|
||||||
import '../../data/repositories/account_repository.dart';
|
import '../../data/repositories/account_repository.dart';
|
||||||
|
import '../../shared/feature_flags/feature_flags_provider.dart';
|
||||||
import '../../shared/models/transaction.dart';
|
import '../../shared/models/transaction.dart';
|
||||||
import '../../shared/models/account.dart';
|
import '../../shared/models/account.dart';
|
||||||
import '../../shared/services/storage_service.dart';
|
import '../../shared/services/storage_service.dart';
|
||||||
@@ -27,7 +28,8 @@ final transactionRepositoryProvider = Provider<TransactionRepository>((ref) {
|
|||||||
|
|
||||||
final accountRepositoryProvider = Provider<AccountRepository>((ref) {
|
final accountRepositoryProvider = Provider<AccountRepository>((ref) {
|
||||||
final db = ref.watch(appDatabaseProvider);
|
final db = ref.watch(appDatabaseProvider);
|
||||||
return AccountRepository(db);
|
final flags = ref.watch(featureFlagsProvider);
|
||||||
|
return AccountRepository(db, flags);
|
||||||
});
|
});
|
||||||
|
|
||||||
final storageServiceProvider = Provider<StorageService>((ref) {
|
final storageServiceProvider = Provider<StorageService>((ref) {
|
||||||
|
|||||||
@@ -5,7 +5,9 @@ import 'package:intl/intl.dart';
|
|||||||
import '../../core/l10n/locale_provider.dart';
|
import '../../core/l10n/locale_provider.dart';
|
||||||
import '../../core/services/card_color_service.dart';
|
import '../../core/services/card_color_service.dart';
|
||||||
import '../../core/services/haptic_service.dart';
|
import '../../core/services/haptic_service.dart';
|
||||||
|
import '../../data/repositories/account_repository.dart';
|
||||||
import '../../shared/models/account.dart';
|
import '../../shared/models/account.dart';
|
||||||
|
import '../../shared/feature_flags/feature_flags_provider.dart';
|
||||||
import '../settings/provider.dart';
|
import '../settings/provider.dart';
|
||||||
import 'provider.dart';
|
import 'provider.dart';
|
||||||
import 'widgets/account_editor_overlay/account_editor_overlay.dart';
|
import 'widgets/account_editor_overlay/account_editor_overlay.dart';
|
||||||
@@ -56,6 +58,7 @@ class _DashboardScreenState extends ConsumerState<DashboardScreen> {
|
|||||||
bool isAddingAccount = false;
|
bool isAddingAccount = false;
|
||||||
|
|
||||||
void _onCardLongPress() {
|
void _onCardLongPress() {
|
||||||
|
if (!ref.read(featureFlagsProvider).canEditCardColors) return;
|
||||||
final colors = ref.read(cardColorsProvider);
|
final colors = ref.read(cardColorsProvider);
|
||||||
savedPrimary = colors.primary;
|
savedPrimary = colors.primary;
|
||||||
savedSecondary = colors.secondary;
|
savedSecondary = colors.secondary;
|
||||||
@@ -179,6 +182,7 @@ class _DashboardScreenState extends ConsumerState<DashboardScreen> {
|
|||||||
createdAt: DateTime.now(),
|
createdAt: DateTime.now(),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
try {
|
||||||
final newId = await ref.read(accountRepositoryProvider).add(newAccount);
|
final newId = await ref.read(accountRepositoryProvider).add(newAccount);
|
||||||
|
|
||||||
await CardColorService.save(
|
await CardColorService.save(
|
||||||
@@ -188,6 +192,15 @@ class _DashboardScreenState extends ConsumerState<DashboardScreen> {
|
|||||||
tempDarkGradientType,
|
tempDarkGradientType,
|
||||||
accountId: newId,
|
accountId: newId,
|
||||||
);
|
);
|
||||||
|
} on FeatureLimitException {
|
||||||
|
if (mounted) {
|
||||||
|
final s = ref.read(stringsProvider);
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
SnackBar(content: Text(s.accountLimitReached)),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
} else if (editingAccount != null) {
|
} else if (editingAccount != null) {
|
||||||
await ref
|
await ref
|
||||||
.read(accountCardColorsProvider(editingAccount!.id).notifier)
|
.read(accountCardColorsProvider(editingAccount!.id).notifier)
|
||||||
@@ -222,6 +235,7 @@ class _DashboardScreenState extends ConsumerState<DashboardScreen> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!mounted) return;
|
||||||
overlayEntry?.remove();
|
overlayEntry?.remove();
|
||||||
overlayEntry = null;
|
overlayEntry = null;
|
||||||
setState(() {
|
setState(() {
|
||||||
@@ -278,8 +292,9 @@ class _DashboardScreenState extends ConsumerState<DashboardScreen> {
|
|||||||
final activeIndex = ref.watch(activeAccountIndexProvider);
|
final activeIndex = ref.watch(activeAccountIndexProvider);
|
||||||
final accountsAsync = ref.watch(accountsProvider);
|
final accountsAsync = ref.watch(accountsProvider);
|
||||||
final accountCount = accountsAsync.value?.length ?? 0;
|
final accountCount = accountsAsync.value?.length ?? 0;
|
||||||
|
final maxAccounts = ref.watch(featureFlagsProvider).maxAccounts;
|
||||||
final isOnAddAccountPage =
|
final isOnAddAccountPage =
|
||||||
accountCount < 5 && activeIndex == accountCount + 1;
|
accountCount < maxAccounts && activeIndex == accountCount + 1;
|
||||||
|
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
backgroundColor: Theme.of(context).scaffoldBackgroundColor,
|
backgroundColor: Theme.of(context).scaffoldBackgroundColor,
|
||||||
@@ -437,6 +452,7 @@ class _AccountsInfoBlock extends ConsumerWidget {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
Widget build(BuildContext context, WidgetRef ref) {
|
||||||
final s = ref.watch(stringsProvider);
|
final s = ref.watch(stringsProvider);
|
||||||
|
final maxAccounts = ref.watch(featureFlagsProvider).maxAccounts;
|
||||||
final onSurface = Theme.of(context).colorScheme.onSurface;
|
final onSurface = Theme.of(context).colorScheme.onSurface;
|
||||||
return Padding(
|
return Padding(
|
||||||
padding: const EdgeInsets.only(bottom: 60),
|
padding: const EdgeInsets.only(bottom: 60),
|
||||||
@@ -478,7 +494,7 @@ class _AccountsInfoBlock extends ConsumerWidget {
|
|||||||
const SizedBox(height: 8),
|
const SizedBox(height: 8),
|
||||||
_InfoRow(
|
_InfoRow(
|
||||||
icon: Icons.lock_outline_rounded,
|
icon: Icons.lock_outline_rounded,
|
||||||
text: s.accountsInfoLimit,
|
text: s.accountsLimitLabel(maxAccounts),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import '../../../../core/constants.dart';
|
|||||||
import '../../../../core/utils/card_layout.dart';
|
import '../../../../core/utils/card_layout.dart';
|
||||||
import '../../../../shared/models/account.dart';
|
import '../../../../shared/models/account.dart';
|
||||||
import '../../../../shared/models/transaction.dart';
|
import '../../../../shared/models/transaction.dart';
|
||||||
|
import '../../../../shared/feature_flags/feature_flags_provider.dart';
|
||||||
import '../../../../shared/widgets/byn_sign.dart';
|
import '../../../../shared/widgets/byn_sign.dart';
|
||||||
import '../../../settings/provider.dart';
|
import '../../../settings/provider.dart';
|
||||||
import '../../provider.dart';
|
import '../../provider.dart';
|
||||||
@@ -87,15 +88,16 @@ class _AccountEditorOverlayState extends State<AccountEditorOverlay> {
|
|||||||
final mq = MediaQuery.of(widget.context);
|
final mq = MediaQuery.of(widget.context);
|
||||||
final layout = CardOverlayLayout.fromMediaQuery(mq);
|
final layout = CardOverlayLayout.fromMediaQuery(mq);
|
||||||
final cardTop = layout.cardTop;
|
final cardTop = layout.cardTop;
|
||||||
final cardHeight = layout.cardHeight;
|
|
||||||
final editorPanelHeight = layout.editorPanelHeight;
|
final editorPanelHeight = layout.editorPanelHeight;
|
||||||
final editorPanelTop = cardTop + cardHeight + layout.sectionGap;
|
|
||||||
final colorPanelTop = editorPanelTop + editorPanelHeight + layout.sectionGap;
|
|
||||||
final colorPanelHeight = layout.colorPanelHeight(mq, colorPanelTop);
|
|
||||||
|
|
||||||
return Consumer(
|
return Consumer(
|
||||||
builder: (context, ref, _) {
|
builder: (context, ref, _) {
|
||||||
final exchangeService = ref.watch(exchangeRateServiceProvider);
|
final exchangeService = ref.watch(exchangeRateServiceProvider);
|
||||||
|
final cardHeight = ref.watch(cardHeightProvider);
|
||||||
|
final isPremium = ref.watch(featureFlagsProvider).canEditCardColors;
|
||||||
|
final editorPanelTop = cardTop + cardHeight + layout.sectionGap;
|
||||||
|
final colorPanelTop = editorPanelTop + editorPanelHeight + layout.sectionGap;
|
||||||
|
final colorPanelHeight = isPremium ? layout.colorPanelHeight(mq, colorPanelTop) : 0.0;
|
||||||
|
|
||||||
double previewBalance = 0.0;
|
double previewBalance = 0.0;
|
||||||
if (!dash.isAddingAccount) {
|
if (!dash.isAddingAccount) {
|
||||||
@@ -220,6 +222,7 @@ class _AccountEditorOverlayState extends State<AccountEditorOverlay> {
|
|||||||
Brightness.dark
|
Brightness.dark
|
||||||
? dash.tempDarkGradientType
|
? dash.tempDarkGradientType
|
||||||
: dash.tempLightGradientType,
|
: dash.tempLightGradientType,
|
||||||
|
cardHeight: cardHeight,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -248,6 +251,7 @@ class _AccountEditorOverlayState extends State<AccountEditorOverlay> {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
if (isPremium) ...[
|
||||||
Positioned(
|
Positioned(
|
||||||
top: colorPanelTop,
|
top: colorPanelTop,
|
||||||
left: 20,
|
left: 20,
|
||||||
@@ -278,6 +282,7 @@ class _AccountEditorOverlayState extends State<AccountEditorOverlay> {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
],
|
||||||
if (_showCurrencyDropdown)
|
if (_showCurrencyDropdown)
|
||||||
Positioned(
|
Positioned(
|
||||||
top: editorPanelTop + 62,
|
top: editorPanelTop + 62,
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import '../../../core/utils/card_layout.dart';
|
|||||||
import '../../../shared/utils/card_gradient.dart';
|
import '../../../shared/utils/card_gradient.dart';
|
||||||
import '../../../core/services/haptic_service.dart';
|
import '../../../core/services/haptic_service.dart';
|
||||||
import '../../../shared/providers/amount_format_provider.dart';
|
import '../../../shared/providers/amount_format_provider.dart';
|
||||||
|
import '../../../shared/feature_flags/feature_flags_provider.dart';
|
||||||
import '../../../shared/widgets/byn_sign.dart';
|
import '../../../shared/widgets/byn_sign.dart';
|
||||||
import '../../settings/provider.dart';
|
import '../../settings/provider.dart';
|
||||||
import '../provider.dart';
|
import '../provider.dart';
|
||||||
@@ -37,6 +38,8 @@ class BalanceCard extends ConsumerStatefulWidget {
|
|||||||
final GradientType? previewGradientType;
|
final GradientType? previewGradientType;
|
||||||
final String? accountName;
|
final String? accountName;
|
||||||
final CardColors? accountColors;
|
final CardColors? accountColors;
|
||||||
|
final double? cardHeight;
|
||||||
|
final Widget? resizeHandle;
|
||||||
|
|
||||||
const BalanceCard({
|
const BalanceCard({
|
||||||
super.key,
|
super.key,
|
||||||
@@ -48,6 +51,8 @@ class BalanceCard extends ConsumerStatefulWidget {
|
|||||||
this.previewGradientType,
|
this.previewGradientType,
|
||||||
this.accountName,
|
this.accountName,
|
||||||
this.accountColors,
|
this.accountColors,
|
||||||
|
this.cardHeight,
|
||||||
|
this.resizeHandle,
|
||||||
});
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -106,6 +111,7 @@ class BalanceCardState extends ConsumerState<BalanceCard>
|
|||||||
.toList();
|
.toList();
|
||||||
|
|
||||||
final textColorMode = ref.watch(cardTextColorProvider);
|
final textColorMode = ref.watch(cardTextColorProvider);
|
||||||
|
final canEditCardColors = ref.watch(featureFlagsProvider).canEditCardColors;
|
||||||
final Color onCard = switch (textColorMode) {
|
final Color onCard = switch (textColorMode) {
|
||||||
CardTextColorMode.white => Colors.white,
|
CardTextColorMode.white => Colors.white,
|
||||||
CardTextColorMode.black => Colors.black,
|
CardTextColorMode.black => Colors.black,
|
||||||
@@ -130,9 +136,12 @@ class BalanceCardState extends ConsumerState<BalanceCard>
|
|||||||
..setEntry(3, 2, 0.001)
|
..setEntry(3, 2, 0.001)
|
||||||
..rotateX(_tiltX * 0.42)
|
..rotateX(_tiltX * 0.42)
|
||||||
..rotateY(_tiltY * 0.42),
|
..rotateY(_tiltY * 0.42),
|
||||||
child: Container(
|
child: Stack(
|
||||||
|
clipBehavior: Clip.none,
|
||||||
|
children: [
|
||||||
|
Container(
|
||||||
width: double.infinity,
|
width: double.infinity,
|
||||||
height: kBalanceCardHeight,
|
height: widget.cardHeight ?? kBalanceCardHeight,
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
borderRadius: BorderRadius.circular(20),
|
borderRadius: BorderRadius.circular(20),
|
||||||
gradient: buildCardGradient(primary, secondary, gradientType),
|
gradient: buildCardGradient(primary, secondary, gradientType),
|
||||||
@@ -317,6 +326,7 @@ class BalanceCardState extends ConsumerState<BalanceCard>
|
|||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
if (canEditCardColors)
|
||||||
Positioned(
|
Positioned(
|
||||||
bottom: 8,
|
bottom: 8,
|
||||||
left: 0,
|
left: 0,
|
||||||
@@ -334,6 +344,14 @@ class BalanceCardState extends ConsumerState<BalanceCard>
|
|||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
),
|
||||||
|
if (widget.resizeHandle != null)
|
||||||
|
Positioned(
|
||||||
|
right: 0,
|
||||||
|
bottom: 0,
|
||||||
|
child: widget.resizeHandle!,
|
||||||
|
),
|
||||||
|
],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import '../../../core/utils/card_layout.dart';
|
|||||||
import '../../../core/services/haptic_service.dart';
|
import '../../../core/services/haptic_service.dart';
|
||||||
import '../../../shared/models/account.dart';
|
import '../../../shared/models/account.dart';
|
||||||
import '../../../shared/models/transaction.dart';
|
import '../../../shared/models/transaction.dart';
|
||||||
|
import '../../../shared/feature_flags/feature_flags_provider.dart';
|
||||||
import '../../settings/provider.dart';
|
import '../../settings/provider.dart';
|
||||||
import '../provider.dart';
|
import '../provider.dart';
|
||||||
import 'balance_card.dart';
|
import 'balance_card.dart';
|
||||||
@@ -59,15 +60,17 @@ class _BalanceCardCarouselState extends ConsumerState<BalanceCardCarousel> {
|
|||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final accountsAsync = ref.watch(accountsProvider);
|
final accountsAsync = ref.watch(accountsProvider);
|
||||||
final activeIndex = ref.watch(activeAccountIndexProvider);
|
final activeIndex = ref.watch(activeAccountIndexProvider);
|
||||||
|
final cardHeight = ref.watch(cardHeightProvider);
|
||||||
|
final maxAccounts = ref.watch(featureFlagsProvider).maxAccounts;
|
||||||
|
|
||||||
return accountsAsync.when(
|
return accountsAsync.when(
|
||||||
data: (accounts) {
|
data: (accounts) {
|
||||||
final totalPages = 1 + accounts.length + (accounts.length < 5 ? 1 : 0);
|
final totalPages = 1 + accounts.length + (accounts.length < maxAccounts ? 1 : 0);
|
||||||
|
|
||||||
return Column(
|
return Column(
|
||||||
children: [
|
children: [
|
||||||
SizedBox(
|
SizedBox(
|
||||||
height: kBalanceCardCarouselHeight,
|
height: cardHeight + 10,
|
||||||
child: OverflowBox(
|
child: OverflowBox(
|
||||||
maxWidth: MediaQuery.of(context).size.width,
|
maxWidth: MediaQuery.of(context).size.width,
|
||||||
child: PageView.builder(
|
child: PageView.builder(
|
||||||
@@ -96,6 +99,7 @@ class _BalanceCardCarouselState extends ConsumerState<BalanceCardCarousel> {
|
|||||||
previewPrimary: widget.previewPrimary,
|
previewPrimary: widget.previewPrimary,
|
||||||
previewSecondary: widget.previewSecondary,
|
previewSecondary: widget.previewSecondary,
|
||||||
previewGradientType: widget.previewGradientType,
|
previewGradientType: widget.previewGradientType,
|
||||||
|
cardHeight: cardHeight,
|
||||||
);
|
);
|
||||||
} else if (index <= accounts.length) {
|
} else if (index <= accounts.length) {
|
||||||
final account = accounts[index - 1];
|
final account = accounts[index - 1];
|
||||||
@@ -134,10 +138,12 @@ class _BalanceCardCarouselState extends ConsumerState<BalanceCardCarousel> {
|
|||||||
widget.onAccountLongPress?.call(account),
|
widget.onAccountLongPress?.call(account),
|
||||||
accountName: account.name,
|
accountName: account.name,
|
||||||
accountColors: accountColors,
|
accountColors: accountColors,
|
||||||
|
cardHeight: cardHeight,
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
cardWidget = AddAccountCard(
|
cardWidget = AddAccountCard(
|
||||||
onTap: widget.onAddAccountTap,
|
onTap: widget.onAddAccountTap,
|
||||||
|
cardHeight: cardHeight,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -154,15 +160,15 @@ class _BalanceCardCarouselState extends ConsumerState<BalanceCardCarousel> {
|
|||||||
],
|
],
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
loading: () => const SizedBox(
|
loading: () => SizedBox(
|
||||||
height: kBalanceCardCarouselHeight,
|
height: cardHeight + 10,
|
||||||
child: Center(child: CircularProgressIndicator()),
|
child: const Center(child: CircularProgressIndicator()),
|
||||||
),
|
),
|
||||||
error: (error, stack) {
|
error: (error, stack) {
|
||||||
return Column(
|
return Column(
|
||||||
children: [
|
children: [
|
||||||
SizedBox(
|
SizedBox(
|
||||||
height: kBalanceCardCarouselHeight,
|
height: cardHeight + 10,
|
||||||
child: BalanceCard(
|
child: BalanceCard(
|
||||||
balance: widget.balance,
|
balance: widget.balance,
|
||||||
currencyInfo: widget.currencyInfo,
|
currencyInfo: widget.currencyInfo,
|
||||||
@@ -170,6 +176,7 @@ class _BalanceCardCarouselState extends ConsumerState<BalanceCardCarousel> {
|
|||||||
previewPrimary: widget.previewPrimary,
|
previewPrimary: widget.previewPrimary,
|
||||||
previewSecondary: widget.previewSecondary,
|
previewSecondary: widget.previewSecondary,
|
||||||
previewGradientType: widget.previewGradientType,
|
previewGradientType: widget.previewGradientType,
|
||||||
|
cardHeight: cardHeight,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
const SizedBox(height: 12),
|
const SizedBox(height: 12),
|
||||||
@@ -183,8 +190,9 @@ class _BalanceCardCarouselState extends ConsumerState<BalanceCardCarousel> {
|
|||||||
|
|
||||||
class AddAccountCard extends StatelessWidget {
|
class AddAccountCard extends StatelessWidget {
|
||||||
final VoidCallback? onTap;
|
final VoidCallback? onTap;
|
||||||
|
final double? cardHeight;
|
||||||
|
|
||||||
const AddAccountCard({super.key, this.onTap});
|
const AddAccountCard({super.key, this.onTap, this.cardHeight});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
@@ -199,7 +207,7 @@ class AddAccountCard extends StatelessWidget {
|
|||||||
painter: _DashedBorderPainter(),
|
painter: _DashedBorderPainter(),
|
||||||
child: Container(
|
child: Container(
|
||||||
width: double.infinity,
|
width: double.infinity,
|
||||||
height: kAddAccountCardHeight,
|
height: cardHeight ?? kAddAccountCardHeight,
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: Theme.of(context).colorScheme.surface.withOpacity(0.4),
|
color: Theme.of(context).colorScheme.surface.withOpacity(0.4),
|
||||||
borderRadius: BorderRadius.circular(20),
|
borderRadius: BorderRadius.circular(20),
|
||||||
|
|||||||
@@ -5,7 +5,9 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|||||||
import '../../../core/l10n/app_strings.dart';
|
import '../../../core/l10n/app_strings.dart';
|
||||||
import '../../../core/l10n/locale_provider.dart';
|
import '../../../core/l10n/locale_provider.dart';
|
||||||
import '../../../core/services/card_color_service.dart';
|
import '../../../core/services/card_color_service.dart';
|
||||||
|
import '../../../core/services/haptic_service.dart';
|
||||||
import '../../../core/utils/card_layout.dart';
|
import '../../../core/utils/card_layout.dart';
|
||||||
|
import '../../../shared/feature_flags/feature_flags_provider.dart';
|
||||||
import '../../settings/provider.dart';
|
import '../../settings/provider.dart';
|
||||||
import '../provider.dart';
|
import '../provider.dart';
|
||||||
import 'balance_card.dart';
|
import 'balance_card.dart';
|
||||||
@@ -37,8 +39,14 @@ class _FullScreenBlurOverlayState extends State<FullScreenBlurOverlay> {
|
|||||||
final mq = MediaQuery.of(widget.context);
|
final mq = MediaQuery.of(widget.context);
|
||||||
final layout = CardOverlayLayout.fromMediaQuery(mq);
|
final layout = CardOverlayLayout.fromMediaQuery(mq);
|
||||||
final cardTop = layout.cardTop;
|
final cardTop = layout.cardTop;
|
||||||
final cardHeight = layout.cardHeight;
|
|
||||||
final panelTop = cardTop + cardHeight + layout.cardPreviewGap;
|
return Consumer(
|
||||||
|
builder: (context, ref, _) {
|
||||||
|
final cardHeight = ref.watch(cardHeightProvider);
|
||||||
|
final isPremium = ref.watch(featureFlagsProvider).canEditCardHeight;
|
||||||
|
final heightDelta = (kBalanceCardHeight - cardHeight) / 2;
|
||||||
|
final adjustedCardTop = cardTop + heightDelta;
|
||||||
|
final panelTop = adjustedCardTop + cardHeight + layout.cardPreviewGap;
|
||||||
final panelHeight = layout.colorPanelHeight(mq, panelTop);
|
final panelHeight = layout.colorPanelHeight(mq, panelTop);
|
||||||
|
|
||||||
return Material(
|
return Material(
|
||||||
@@ -60,7 +68,7 @@ class _FullScreenBlurOverlayState extends State<FullScreenBlurOverlay> {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
Positioned(
|
Positioned(
|
||||||
top: cardTop,
|
top: adjustedCardTop,
|
||||||
left: 0,
|
left: 0,
|
||||||
right: 0,
|
right: 0,
|
||||||
child: FractionallySizedBox(
|
child: FractionallySizedBox(
|
||||||
@@ -69,7 +77,10 @@ class _FullScreenBlurOverlayState extends State<FullScreenBlurOverlay> {
|
|||||||
height: cardHeight,
|
height: cardHeight,
|
||||||
child: Padding(
|
child: Padding(
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 8),
|
padding: const EdgeInsets.symmetric(horizontal: 8),
|
||||||
child: Consumer(
|
child: Stack(
|
||||||
|
clipBehavior: Clip.none,
|
||||||
|
children: [
|
||||||
|
Consumer(
|
||||||
builder: (ctx, ref, _) => BalanceCard(
|
builder: (ctx, ref, _) => BalanceCard(
|
||||||
balance: ref.read(totalBalanceProvider),
|
balance: ref.read(totalBalanceProvider),
|
||||||
currencyInfo: ref.read(currencyProvider),
|
currencyInfo: ref.read(currencyProvider),
|
||||||
@@ -80,8 +91,20 @@ class _FullScreenBlurOverlayState extends State<FullScreenBlurOverlay> {
|
|||||||
Theme.of(widget.context).brightness == Brightness.dark
|
Theme.of(widget.context).brightness == Brightness.dark
|
||||||
? dash.tempDarkGradientType
|
? dash.tempDarkGradientType
|
||||||
: dash.tempLightGradientType,
|
: dash.tempLightGradientType,
|
||||||
|
cardHeight: cardHeight,
|
||||||
|
resizeHandle: isPremium ? _CornerResizeHandle(
|
||||||
|
cardHeight: cardHeight,
|
||||||
|
onHeightChanged: (newHeight) {
|
||||||
|
ref.read(cardHeightProvider.notifier).set(newHeight);
|
||||||
|
if (ref.read(hapticEnabledProvider)) {
|
||||||
|
HapticService.selection();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
) : null,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -132,6 +155,8 @@ class _FullScreenBlurOverlayState extends State<FullScreenBlurOverlay> {
|
|||||||
],
|
],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildPanel(double panelHeight, CardOverlayLayout layout) {
|
Widget _buildPanel(double panelHeight, CardOverlayLayout layout) {
|
||||||
@@ -784,3 +809,103 @@ class PanelTab extends StatelessWidget {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class _CornerResizeHandle extends StatefulWidget {
|
||||||
|
final double cardHeight;
|
||||||
|
final ValueChanged<double> onHeightChanged;
|
||||||
|
|
||||||
|
const _CornerResizeHandle({
|
||||||
|
required this.cardHeight,
|
||||||
|
required this.onHeightChanged,
|
||||||
|
});
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<_CornerResizeHandle> createState() => _CornerResizeHandleState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _CornerResizeHandleState extends State<_CornerResizeHandle> {
|
||||||
|
bool _dragging = false;
|
||||||
|
double _lastHeight = 0;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final theme = Theme.of(context);
|
||||||
|
|
||||||
|
return GestureDetector(
|
||||||
|
onVerticalDragStart: (_) {
|
||||||
|
setState(() => _dragging = true);
|
||||||
|
_lastHeight = widget.cardHeight;
|
||||||
|
},
|
||||||
|
onVerticalDragUpdate: (details) {
|
||||||
|
final newHeight = widget.cardHeight + details.delta.dy * 2;
|
||||||
|
if ((newHeight - _lastHeight).abs() > 0.5) {
|
||||||
|
widget.onHeightChanged(newHeight);
|
||||||
|
_lastHeight = newHeight;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
onVerticalDragEnd: (_) => setState(() => _dragging = false),
|
||||||
|
behavior: HitTestBehavior.opaque,
|
||||||
|
child: SizedBox(
|
||||||
|
width: 48,
|
||||||
|
height: 48,
|
||||||
|
child: CustomPaint(
|
||||||
|
size: const Size(48, 48),
|
||||||
|
painter: _CornerDashedPainter(
|
||||||
|
color: theme.colorScheme.onSurface.withOpacity(_dragging ? 0.8 : 0.5),
|
||||||
|
radius: 20,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class _CornerDashedPainter extends CustomPainter {
|
||||||
|
final Color color;
|
||||||
|
final double radius;
|
||||||
|
|
||||||
|
const _CornerDashedPainter({
|
||||||
|
required this.color,
|
||||||
|
required this.radius,
|
||||||
|
});
|
||||||
|
|
||||||
|
@override
|
||||||
|
void paint(Canvas canvas, Size size) {
|
||||||
|
final paint = Paint()
|
||||||
|
..color = color
|
||||||
|
..strokeWidth = 2.5
|
||||||
|
..style = PaintingStyle.stroke
|
||||||
|
..strokeCap = StrokeCap.round;
|
||||||
|
|
||||||
|
const dashLength = 6.0;
|
||||||
|
const dashSpace = 5.0;
|
||||||
|
const extraLine = 8.0;
|
||||||
|
|
||||||
|
final cornerCenter = Offset(size.width - radius, size.height - radius);
|
||||||
|
|
||||||
|
final path = Path()
|
||||||
|
..moveTo(cornerCenter.dx - extraLine, size.height)
|
||||||
|
..lineTo(cornerCenter.dx, size.height)
|
||||||
|
..arcToPoint(
|
||||||
|
Offset(size.width, cornerCenter.dy),
|
||||||
|
radius: Radius.circular(radius),
|
||||||
|
clockwise: false,
|
||||||
|
)
|
||||||
|
..lineTo(size.width, cornerCenter.dy - extraLine);
|
||||||
|
final metrics = path.computeMetrics();
|
||||||
|
|
||||||
|
for (final metric in metrics) {
|
||||||
|
double distance = 0;
|
||||||
|
while (distance < metric.length) {
|
||||||
|
final end = (distance + dashLength).clamp(0.0, metric.length);
|
||||||
|
final extracted = metric.extractPath(distance, end);
|
||||||
|
canvas.drawPath(extracted, paint);
|
||||||
|
distance += dashLength + dashSpace;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool shouldRepaint(covariant _CornerDashedPainter oldDelegate) =>
|
||||||
|
color != oldDelegate.color;
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import 'dart:async';
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||||
import '../../../core/constants.dart';
|
import '../../../core/constants.dart';
|
||||||
@@ -44,6 +46,11 @@ class _CategoryEditorSheetState extends ConsumerState<CategoryEditorSheet> {
|
|||||||
bool _translatingEn = false;
|
bool _translatingEn = false;
|
||||||
bool _translatingRu = false;
|
bool _translatingRu = false;
|
||||||
bool _saving = false;
|
bool _saving = false;
|
||||||
|
DateTime? _lastTranslateTime;
|
||||||
|
bool _enOverflow = false;
|
||||||
|
bool _ruOverflow = false;
|
||||||
|
Timer? _enOverflowTimer;
|
||||||
|
Timer? _ruOverflowTimer;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
@@ -62,6 +69,8 @@ class _CategoryEditorSheetState extends ConsumerState<CategoryEditorSheet> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
void dispose() {
|
void dispose() {
|
||||||
|
_enOverflowTimer?.cancel();
|
||||||
|
_ruOverflowTimer?.cancel();
|
||||||
_enController.dispose();
|
_enController.dispose();
|
||||||
_ruController.dispose();
|
_ruController.dispose();
|
||||||
super.dispose();
|
super.dispose();
|
||||||
@@ -71,21 +80,50 @@ class _CategoryEditorSheetState extends ConsumerState<CategoryEditorSheet> {
|
|||||||
if (_enController.text.trim().isNotEmpty && _enSuggestion != null) {
|
if (_enController.text.trim().isNotEmpty && _enSuggestion != null) {
|
||||||
setState(() => _enSuggestion = null);
|
setState(() => _enSuggestion = null);
|
||||||
}
|
}
|
||||||
|
if (_enController.text.length >= 20) {
|
||||||
|
_enOverflowTimer?.cancel();
|
||||||
|
setState(() => _enOverflow = true);
|
||||||
|
_enOverflowTimer = Timer(const Duration(seconds: 1), () {
|
||||||
|
if (mounted) setState(() => _enOverflow = false);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _onRuChanged() {
|
void _onRuChanged() {
|
||||||
if (_ruController.text.trim().isNotEmpty && _ruSuggestion != null) {
|
if (_ruController.text.trim().isNotEmpty && _ruSuggestion != null) {
|
||||||
setState(() => _ruSuggestion = null);
|
setState(() => _ruSuggestion = null);
|
||||||
}
|
}
|
||||||
|
if (_ruController.text.length >= 20) {
|
||||||
|
_ruOverflowTimer?.cancel();
|
||||||
|
setState(() => _ruOverflow = true);
|
||||||
|
_ruOverflowTimer = Timer(const Duration(seconds: 1), () {
|
||||||
|
if (mounted) setState(() => _ruOverflow = false);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool _isThrottled() {
|
||||||
|
final now = DateTime.now();
|
||||||
|
if (_lastTranslateTime != null &&
|
||||||
|
now.difference(_lastTranslateTime!) < const Duration(seconds: 2)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
_lastTranslateTime = now;
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _translateToRu() async {
|
Future<void> _translateToRu() async {
|
||||||
final source = _enController.text.trim();
|
final source = _enController.text.trim();
|
||||||
if (source.isEmpty) return;
|
if (source.isEmpty) return;
|
||||||
setState(() => _translatingRu = true);
|
setState(() => _translatingRu = true);
|
||||||
final result = await ref
|
final service = ref.read(translationServiceProvider);
|
||||||
.read(translationServiceProvider)
|
TranslationResult? result;
|
||||||
.translate(source, TranslateDirection.enToRu);
|
if (_isThrottled()) {
|
||||||
|
final dict = service.dictionaryLookup(source, TranslateDirection.enToRu);
|
||||||
|
result = dict != null ? TranslationResult(dict, fromCache: true) : null;
|
||||||
|
} else {
|
||||||
|
result = await service.translate(source, TranslateDirection.enToRu);
|
||||||
|
}
|
||||||
if (!mounted) return;
|
if (!mounted) return;
|
||||||
setState(() {
|
setState(() {
|
||||||
_translatingRu = false;
|
_translatingRu = false;
|
||||||
@@ -100,9 +138,14 @@ class _CategoryEditorSheetState extends ConsumerState<CategoryEditorSheet> {
|
|||||||
final source = _ruController.text.trim();
|
final source = _ruController.text.trim();
|
||||||
if (source.isEmpty) return;
|
if (source.isEmpty) return;
|
||||||
setState(() => _translatingEn = true);
|
setState(() => _translatingEn = true);
|
||||||
final result = await ref
|
final service = ref.read(translationServiceProvider);
|
||||||
.read(translationServiceProvider)
|
TranslationResult? result;
|
||||||
.translate(source, TranslateDirection.ruToEn);
|
if (_isThrottled()) {
|
||||||
|
final dict = service.dictionaryLookup(source, TranslateDirection.ruToEn);
|
||||||
|
result = dict != null ? TranslationResult(dict, fromCache: true) : null;
|
||||||
|
} else {
|
||||||
|
result = await service.translate(source, TranslateDirection.ruToEn);
|
||||||
|
}
|
||||||
if (!mounted) return;
|
if (!mounted) return;
|
||||||
setState(() {
|
setState(() {
|
||||||
_translatingEn = false;
|
_translatingEn = false;
|
||||||
@@ -122,21 +165,45 @@ class _CategoryEditorSheetState extends ConsumerState<CategoryEditorSheet> {
|
|||||||
}
|
}
|
||||||
setState(() => _saving = true);
|
setState(() => _saving = true);
|
||||||
HapticService.medium();
|
HapticService.medium();
|
||||||
|
|
||||||
|
String labelEn = _enController.text.trim();
|
||||||
|
String labelRu = _ruController.text.trim();
|
||||||
|
|
||||||
|
if (labelEn.isEmpty && labelRu.isNotEmpty) {
|
||||||
|
final result = await ref
|
||||||
|
.read(translationServiceProvider)
|
||||||
|
.translate(labelRu, TranslateDirection.ruToEn);
|
||||||
|
if (result != null && result.text.isNotEmpty) {
|
||||||
|
labelEn = result.text;
|
||||||
|
} else {
|
||||||
|
labelEn = labelRu;
|
||||||
|
}
|
||||||
|
} else if (labelRu.isEmpty && labelEn.isNotEmpty) {
|
||||||
|
final result = await ref
|
||||||
|
.read(translationServiceProvider)
|
||||||
|
.translate(labelEn, TranslateDirection.enToRu);
|
||||||
|
if (result != null && result.text.isNotEmpty) {
|
||||||
|
labelRu = result.text;
|
||||||
|
} else {
|
||||||
|
labelRu = labelEn;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
final actions = ref.read(categoryActionsProvider);
|
final actions = ref.read(categoryActionsProvider);
|
||||||
final existing = widget.existing;
|
final existing = widget.existing;
|
||||||
final result = existing != null && existing.id != null
|
final result = existing != null && existing.id != null
|
||||||
? await actions.edit(
|
? await actions.edit(
|
||||||
id: existing.id!,
|
id: existing.id!,
|
||||||
type: _type,
|
type: _type,
|
||||||
labelEn: _enController.text,
|
labelEn: labelEn,
|
||||||
labelRu: _ruController.text,
|
labelRu: labelRu,
|
||||||
iconName: _iconName,
|
iconName: _iconName,
|
||||||
colorValue: _colorValue,
|
colorValue: _colorValue,
|
||||||
)
|
)
|
||||||
: await actions.create(
|
: await actions.create(
|
||||||
type: _type,
|
type: _type,
|
||||||
labelEn: _enController.text,
|
labelEn: labelEn,
|
||||||
labelRu: _ruController.text,
|
labelRu: labelRu,
|
||||||
iconName: _iconName,
|
iconName: _iconName,
|
||||||
colorValue: _colorValue,
|
colorValue: _colorValue,
|
||||||
);
|
);
|
||||||
@@ -180,14 +247,14 @@ class _CategoryEditorSheetState extends ConsumerState<CategoryEditorSheet> {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
const SizedBox(height: 16),
|
const SizedBox(height: 28),
|
||||||
Text(
|
Text(
|
||||||
widget.existing != null ? s.editCategory : s.newCategory,
|
widget.existing != null ? s.editCategory : s.newCategory,
|
||||||
style: theme.textTheme.titleLarge?.copyWith(
|
style: theme.textTheme.titleLarge?.copyWith(
|
||||||
fontWeight: FontWeight.w700,
|
fontWeight: FontWeight.w700,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
const SizedBox(height: 20),
|
const SizedBox(height: 24),
|
||||||
_TypeToggle(
|
_TypeToggle(
|
||||||
type: _type,
|
type: _type,
|
||||||
onChanged: (t) => setState(() => _type = t),
|
onChanged: (t) => setState(() => _type = t),
|
||||||
@@ -201,6 +268,7 @@ class _CategoryEditorSheetState extends ConsumerState<CategoryEditorSheet> {
|
|||||||
hint: s.nameEnHint,
|
hint: s.nameEnHint,
|
||||||
suggestion: _enSuggestion,
|
suggestion: _enSuggestion,
|
||||||
isTranslating: _translatingEn,
|
isTranslating: _translatingEn,
|
||||||
|
isOverflow: _enOverflow,
|
||||||
canTranslate: _ruController.text.trim().isNotEmpty,
|
canTranslate: _ruController.text.trim().isNotEmpty,
|
||||||
translatingLabel: s.translating,
|
translatingLabel: s.translating,
|
||||||
applyLabel: s.applyTranslation,
|
applyLabel: s.applyTranslation,
|
||||||
@@ -217,6 +285,7 @@ class _CategoryEditorSheetState extends ConsumerState<CategoryEditorSheet> {
|
|||||||
hint: s.nameRuHint,
|
hint: s.nameRuHint,
|
||||||
suggestion: _ruSuggestion,
|
suggestion: _ruSuggestion,
|
||||||
isTranslating: _translatingRu,
|
isTranslating: _translatingRu,
|
||||||
|
isOverflow: _ruOverflow,
|
||||||
canTranslate: _enController.text.trim().isNotEmpty,
|
canTranslate: _enController.text.trim().isNotEmpty,
|
||||||
translatingLabel: s.translating,
|
translatingLabel: s.translating,
|
||||||
applyLabel: s.applyTranslation,
|
applyLabel: s.applyTranslation,
|
||||||
@@ -384,6 +453,7 @@ class _TranslatableField extends StatelessWidget {
|
|||||||
final bool canTranslate;
|
final bool canTranslate;
|
||||||
final String translatingLabel;
|
final String translatingLabel;
|
||||||
final String applyLabel;
|
final String applyLabel;
|
||||||
|
final bool isOverflow;
|
||||||
final VoidCallback onTranslate;
|
final VoidCallback onTranslate;
|
||||||
final VoidCallback onApply;
|
final VoidCallback onApply;
|
||||||
|
|
||||||
@@ -393,6 +463,7 @@ class _TranslatableField extends StatelessWidget {
|
|||||||
required this.hint,
|
required this.hint,
|
||||||
required this.suggestion,
|
required this.suggestion,
|
||||||
required this.isTranslating,
|
required this.isTranslating,
|
||||||
|
required this.isOverflow,
|
||||||
required this.canTranslate,
|
required this.canTranslate,
|
||||||
required this.translatingLabel,
|
required this.translatingLabel,
|
||||||
required this.applyLabel,
|
required this.applyLabel,
|
||||||
@@ -424,7 +495,9 @@ class _TranslatableField extends StatelessWidget {
|
|||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: theme.colorScheme.surface,
|
color: theme.colorScheme.surface,
|
||||||
borderRadius: BorderRadius.circular(14),
|
borderRadius: BorderRadius.circular(14),
|
||||||
border: isDark
|
border: isOverflow
|
||||||
|
? Border.all(color: AppColors.expense, width: 1.5)
|
||||||
|
: isDark
|
||||||
? null
|
? null
|
||||||
: Border.all(color: const Color(0xFFDDDDEE), width: 1),
|
: Border.all(color: const Color(0xFFDDDDEE), width: 1),
|
||||||
),
|
),
|
||||||
@@ -457,10 +530,14 @@ class _TranslatableField extends StatelessWidget {
|
|||||||
TextField(
|
TextField(
|
||||||
controller: controller,
|
controller: controller,
|
||||||
style: theme.textTheme.bodyLarge,
|
style: theme.textTheme.bodyLarge,
|
||||||
|
maxLength: 20,
|
||||||
decoration: InputDecoration(
|
decoration: InputDecoration(
|
||||||
hintText: showGhost ? '' : hint,
|
hintText: showGhost ? '' : hint,
|
||||||
isDense: true,
|
isDense: true,
|
||||||
filled: false,
|
filled: false,
|
||||||
|
counterText: '',
|
||||||
|
enabledBorder: InputBorder.none,
|
||||||
|
focusedBorder: InputBorder.none,
|
||||||
border: InputBorder.none,
|
border: InputBorder.none,
|
||||||
contentPadding: const EdgeInsets.symmetric(
|
contentPadding: const EdgeInsets.symmetric(
|
||||||
horizontal: 14,
|
horizontal: 14,
|
||||||
@@ -537,7 +614,9 @@ class _IconGrid extends StatelessWidget {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final theme = Theme.of(context);
|
final theme = Theme.of(context);
|
||||||
return Wrap(
|
return Center(
|
||||||
|
child: Wrap(
|
||||||
|
alignment: WrapAlignment.center,
|
||||||
spacing: 10,
|
spacing: 10,
|
||||||
runSpacing: 10,
|
runSpacing: 10,
|
||||||
children: kCategoryIcons.entries.map((entry) {
|
children: kCategoryIcons.entries.map((entry) {
|
||||||
@@ -567,6 +646,7 @@ class _IconGrid extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
}).toList(),
|
}).toList(),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -579,7 +659,9 @@ class _ColorRow extends StatelessWidget {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Wrap(
|
return Center(
|
||||||
|
child: Wrap(
|
||||||
|
alignment: WrapAlignment.center,
|
||||||
spacing: 12,
|
spacing: 12,
|
||||||
runSpacing: 12,
|
runSpacing: 12,
|
||||||
children: kCategoryColors.map((color) {
|
children: kCategoryColors.map((color) {
|
||||||
@@ -612,6 +694,7 @@ class _ColorRow extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
}).toList(),
|
}).toList(),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -103,6 +103,31 @@ final exchangeRateServiceProvider = Provider<ExchangeRateService>((ref) {
|
|||||||
return ExchangeRateService(prefs);
|
return ExchangeRateService(prefs);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
final cardHeightProvider = NotifierProvider<CardHeightNotifier, double>(
|
||||||
|
CardHeightNotifier.new,
|
||||||
|
);
|
||||||
|
|
||||||
|
class CardHeightNotifier extends Notifier<double> {
|
||||||
|
static const _key = 'card_height';
|
||||||
|
static const minHeight = 140.0;
|
||||||
|
static const maxHeight = 200.0;
|
||||||
|
static const _defaultHeight = 200.0;
|
||||||
|
|
||||||
|
@override
|
||||||
|
double build() {
|
||||||
|
final prefs = ref.watch(sharedPreferencesProvider);
|
||||||
|
final saved = prefs.getDouble(_key);
|
||||||
|
if (saved == null) return _defaultHeight;
|
||||||
|
return saved.clamp(minHeight, maxHeight);
|
||||||
|
}
|
||||||
|
|
||||||
|
void set(double height) {
|
||||||
|
final clamped = height.clamp(minHeight, maxHeight);
|
||||||
|
state = clamped;
|
||||||
|
ref.read(sharedPreferencesProvider).setDouble(_key, clamped);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
final ratesInitProvider = FutureProvider<void>((ref) async {
|
final ratesInitProvider = FutureProvider<void>((ref) async {
|
||||||
await ref.read(exchangeRateServiceProvider).fetchRates();
|
await ref.read(exchangeRateServiceProvider).fetchRates();
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import 'widgets/language_section.dart';
|
|||||||
import 'widgets/currency_section.dart';
|
import 'widgets/currency_section.dart';
|
||||||
import 'widgets/amount_format_section.dart';
|
import 'widgets/amount_format_section.dart';
|
||||||
import 'widgets/categories_section.dart';
|
import 'widgets/categories_section.dart';
|
||||||
|
import 'widgets/premium_section.dart';
|
||||||
|
|
||||||
class SettingsScreen extends ConsumerWidget {
|
class SettingsScreen extends ConsumerWidget {
|
||||||
const SettingsScreen({super.key});
|
const SettingsScreen({super.key});
|
||||||
@@ -111,24 +112,13 @@ class SettingsScreen extends ConsumerWidget {
|
|||||||
|
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
backgroundColor: Theme.of(context).scaffoldBackgroundColor,
|
backgroundColor: Theme.of(context).scaffoldBackgroundColor,
|
||||||
appBar: AppBar(
|
body: SafeArea(
|
||||||
backgroundColor: Theme.of(context).scaffoldBackgroundColor,
|
child: ListView(
|
||||||
elevation: 0,
|
|
||||||
scrolledUnderElevation: 0,
|
|
||||||
centerTitle: true,
|
|
||||||
title: Text(
|
|
||||||
'Casha',
|
|
||||||
style: Theme.of(context).textTheme.headlineMedium?.copyWith(
|
|
||||||
fontWeight: FontWeight.w800,
|
|
||||||
color: Theme.of(context).colorScheme.onSurface,
|
|
||||||
letterSpacing: -0.5,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
body: ListView(
|
|
||||||
physics: const ClampingScrollPhysics(),
|
physics: const ClampingScrollPhysics(),
|
||||||
padding: const EdgeInsets.fromLTRB(20, 16, 20, 40),
|
padding: const EdgeInsets.fromLTRB(20, 16, 20, 40),
|
||||||
children: [
|
children: [
|
||||||
|
const PremiumSection(),
|
||||||
|
const SizedBox(height: 16),
|
||||||
const ThemeSection(),
|
const ThemeSection(),
|
||||||
const SizedBox(height: 16),
|
const SizedBox(height: 16),
|
||||||
const CardTextColorSection(),
|
const CardTextColorSection(),
|
||||||
@@ -180,6 +170,7 @@ class SettingsScreen extends ConsumerWidget {
|
|||||||
const _FooterWidget(),
|
const _FooterWidget(),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,85 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||||
|
import '../../../core/constants.dart';
|
||||||
|
import '../../../core/l10n/locale_provider.dart';
|
||||||
|
import '../../../core/services/haptic_service.dart';
|
||||||
|
import '../../../shared/providers/current_user_provider.dart';
|
||||||
|
import '../../../shared/models/user_model.dart';
|
||||||
|
|
||||||
|
class PremiumSection extends ConsumerWidget {
|
||||||
|
const PremiumSection({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context, WidgetRef ref) {
|
||||||
|
final s = ref.watch(stringsProvider);
|
||||||
|
final user = ref.watch(currentUserProvider);
|
||||||
|
final isDark = Theme.of(context).brightness == Brightness.dark;
|
||||||
|
|
||||||
|
return Container(
|
||||||
|
padding: const EdgeInsets.all(20),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: Theme.of(context).colorScheme.surface,
|
||||||
|
borderRadius: BorderRadius.circular(16),
|
||||||
|
border: isDark
|
||||||
|
? null
|
||||||
|
: Border.all(color: const Color(0xFFDDDDEE), width: 1),
|
||||||
|
),
|
||||||
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
Row(
|
||||||
|
children: [
|
||||||
|
Container(
|
||||||
|
padding: const EdgeInsets.all(10),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: (user.isVip ? AppColors.accent : AppColors.warning)
|
||||||
|
.withOpacity(0.15),
|
||||||
|
borderRadius: BorderRadius.circular(12),
|
||||||
|
),
|
||||||
|
child: Icon(
|
||||||
|
user.isVip ? Icons.workspace_premium_rounded : Icons.lock_outline_rounded,
|
||||||
|
color: user.isVip ? AppColors.accent : AppColors.warning,
|
||||||
|
size: 20,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(width: 12),
|
||||||
|
Expanded(
|
||||||
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
Text(
|
||||||
|
s.premiumStatus,
|
||||||
|
style: Theme.of(context).textTheme.titleMedium?.copyWith(
|
||||||
|
fontWeight: FontWeight.w600,
|
||||||
|
color: Theme.of(context).colorScheme.onSurface,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Text(
|
||||||
|
s.premiumDescription,
|
||||||
|
style: Theme.of(context).textTheme.bodySmall?.copyWith(
|
||||||
|
color: Theme.of(context)
|
||||||
|
.colorScheme
|
||||||
|
.onSurface
|
||||||
|
.withOpacity(0.6),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Switch(
|
||||||
|
value: user.isVip,
|
||||||
|
onChanged: (value) async {
|
||||||
|
HapticService.light();
|
||||||
|
await ref.read(currentUserProvider.notifier).setPlan(
|
||||||
|
value ? UserPlan.vip : UserPlan.free,
|
||||||
|
);
|
||||||
|
},
|
||||||
|
activeThumbColor: const Color(0xFF7C6DED),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
abstract class FeatureFlags {
|
||||||
|
bool get canEditCardColors;
|
||||||
|
bool get canEditCardHeight;
|
||||||
|
bool get canEditCardTextColor;
|
||||||
|
int get maxAccounts;
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||||
|
import '../providers/current_user_provider.dart';
|
||||||
|
import 'feature_flags.dart';
|
||||||
|
import 'free_feature_flags.dart';
|
||||||
|
import 'vip_feature_flags.dart';
|
||||||
|
|
||||||
|
final featureFlagsProvider = Provider<FeatureFlags>((ref) {
|
||||||
|
final user = ref.watch(currentUserProvider);
|
||||||
|
return user.isVip
|
||||||
|
? const VipFeatureFlags()
|
||||||
|
: const FreeFeatureFlags();
|
||||||
|
});
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
import 'feature_flags.dart';
|
||||||
|
|
||||||
|
class FreeFeatureFlags implements FeatureFlags {
|
||||||
|
const FreeFeatureFlags();
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool get canEditCardColors => false;
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool get canEditCardHeight => false;
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool get canEditCardTextColor => false;
|
||||||
|
|
||||||
|
@override
|
||||||
|
int get maxAccounts => 3;
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
import 'feature_flags.dart';
|
||||||
|
|
||||||
|
class VipFeatureFlags implements FeatureFlags {
|
||||||
|
const VipFeatureFlags();
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool get canEditCardColors => true;
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool get canEditCardHeight => true;
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool get canEditCardTextColor => true;
|
||||||
|
|
||||||
|
@override
|
||||||
|
int get maxAccounts => 8;
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
enum UserPlan { free, vip }
|
||||||
|
|
||||||
|
class UserModel {
|
||||||
|
final UserPlan plan;
|
||||||
|
|
||||||
|
const UserModel({this.plan = UserPlan.free});
|
||||||
|
|
||||||
|
bool get isVip => plan == UserPlan.vip;
|
||||||
|
}
|
||||||
@@ -0,0 +1,55 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||||
|
import '../../core/l10n/app_strings.dart';
|
||||||
|
import '../../core/l10n/locale_provider.dart';
|
||||||
|
|
||||||
|
class PaywallBanner extends ConsumerWidget {
|
||||||
|
final String? message;
|
||||||
|
final VoidCallback? onTap;
|
||||||
|
|
||||||
|
const PaywallBanner({
|
||||||
|
super.key,
|
||||||
|
this.message,
|
||||||
|
this.onTap,
|
||||||
|
});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context, WidgetRef ref) {
|
||||||
|
final s = AppStrings(ref.watch(localeProvider));
|
||||||
|
return GestureDetector(
|
||||||
|
onTap: onTap,
|
||||||
|
child: Container(
|
||||||
|
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: Theme.of(context).colorScheme.surface,
|
||||||
|
borderRadius: BorderRadius.circular(12),
|
||||||
|
border: Border.all(
|
||||||
|
color: Theme.of(context).colorScheme.onSurface.withOpacity(0.15),
|
||||||
|
width: 1,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
child: Row(
|
||||||
|
children: [
|
||||||
|
Icon(
|
||||||
|
Icons.lock_outline_rounded,
|
||||||
|
size: 20,
|
||||||
|
color: Theme.of(context).colorScheme.onSurface.withOpacity(0.5),
|
||||||
|
),
|
||||||
|
const SizedBox(width: 12),
|
||||||
|
Expanded(
|
||||||
|
child: Text(
|
||||||
|
message ?? s.premiumFeatureLocked,
|
||||||
|
style: Theme.of(context).textTheme.bodySmall?.copyWith(
|
||||||
|
color: Theme.of(context)
|
||||||
|
.colorScheme
|
||||||
|
.onSurface
|
||||||
|
.withOpacity(0.6),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||||
|
import 'paywall_banner.dart';
|
||||||
|
|
||||||
|
class PaywallGuard extends ConsumerWidget {
|
||||||
|
final bool canAccess;
|
||||||
|
final Widget child;
|
||||||
|
final Widget? fallback;
|
||||||
|
|
||||||
|
const PaywallGuard({
|
||||||
|
super.key,
|
||||||
|
required this.canAccess,
|
||||||
|
required this.child,
|
||||||
|
this.fallback,
|
||||||
|
});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context, WidgetRef ref) {
|
||||||
|
if (canAccess) return child;
|
||||||
|
return fallback ?? PaywallBanner();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,92 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||||
|
import 'package:go_router/go_router.dart';
|
||||||
|
import '../../core/l10n/app_strings.dart';
|
||||||
|
import '../../core/l10n/locale_provider.dart';
|
||||||
|
|
||||||
|
class PaywallScreen extends ConsumerWidget {
|
||||||
|
const PaywallScreen({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context, WidgetRef ref) {
|
||||||
|
final s = AppStrings(ref.watch(localeProvider));
|
||||||
|
|
||||||
|
return Scaffold(
|
||||||
|
backgroundColor: Theme.of(context).scaffoldBackgroundColor,
|
||||||
|
appBar: AppBar(
|
||||||
|
backgroundColor: Theme.of(context).scaffoldBackgroundColor,
|
||||||
|
elevation: 0,
|
||||||
|
scrolledUnderElevation: 0,
|
||||||
|
leading: IconButton(
|
||||||
|
icon: const Icon(Icons.arrow_back_rounded),
|
||||||
|
onPressed: () => context.pop(),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
body: SafeArea(
|
||||||
|
child: Padding(
|
||||||
|
padding: const EdgeInsets.symmetric(horizontal: 24),
|
||||||
|
child: Column(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
|
children: [
|
||||||
|
Container(
|
||||||
|
padding: const EdgeInsets.all(24),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: const Color(0xFF7C6DED).withOpacity(0.12),
|
||||||
|
shape: BoxShape.circle,
|
||||||
|
),
|
||||||
|
child: const Icon(
|
||||||
|
Icons.workspace_premium_rounded,
|
||||||
|
size: 64,
|
||||||
|
color: Color(0xFF7C6DED),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 24),
|
||||||
|
Text(
|
||||||
|
s.premium,
|
||||||
|
style: Theme.of(context).textTheme.headlineMedium?.copyWith(
|
||||||
|
fontWeight: FontWeight.w700,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 12),
|
||||||
|
Text(
|
||||||
|
s.premiumDescription,
|
||||||
|
textAlign: TextAlign.center,
|
||||||
|
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
|
||||||
|
color: Theme.of(context)
|
||||||
|
.colorScheme
|
||||||
|
.onSurface
|
||||||
|
.withOpacity(0.6),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 32),
|
||||||
|
_FeatureItem(icon: Icons.palette_rounded, label: s.premiumFeatureColors),
|
||||||
|
_FeatureItem(icon: Icons.height_rounded, label: s.premiumFeatureHeight),
|
||||||
|
_FeatureItem(icon: Icons.account_balance_wallet_rounded, label: s.premiumFeatureAccounts),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class _FeatureItem extends StatelessWidget {
|
||||||
|
final IconData icon;
|
||||||
|
final String label;
|
||||||
|
|
||||||
|
const _FeatureItem({required this.icon, required this.label});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Padding(
|
||||||
|
padding: const EdgeInsets.symmetric(vertical: 8),
|
||||||
|
child: Row(
|
||||||
|
children: [
|
||||||
|
Icon(icon, size: 20, color: const Color(0xFF7C6DED)),
|
||||||
|
const SizedBox(width: 12),
|
||||||
|
Text(label, style: Theme.of(context).textTheme.bodyMedium),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -109,8 +109,15 @@ class CategoryCatalog {
|
|||||||
Color colorFor(String key, [Color? fallback]) =>
|
Color colorFor(String key, [Color? fallback]) =>
|
||||||
byKey(key)?.color ?? fallback ?? AppColors.accent;
|
byKey(key)?.color ?? fallback ?? AppColors.accent;
|
||||||
|
|
||||||
String labelFor(String key, bool isRu) =>
|
String labelFor(String key, bool isRu) {
|
||||||
byKey(key)?.label(isRu) ?? key;
|
final cat = byKey(key);
|
||||||
|
if (cat != null) return cat.label(isRu);
|
||||||
|
if (isRu) {
|
||||||
|
final ru = AppCategories.ruLabels[key];
|
||||||
|
if (ru != null) return ru;
|
||||||
|
}
|
||||||
|
return key;
|
||||||
|
}
|
||||||
|
|
||||||
bool hasKey(String key) => byKey(key) != null;
|
bool hasKey(String key) => byKey(key) != null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,32 @@
|
|||||||
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||||
|
import '../../features/dashboard/provider.dart';
|
||||||
|
import '../models/user_model.dart';
|
||||||
|
|
||||||
|
class CurrentUserNotifier extends Notifier<UserModel> {
|
||||||
|
static const _key = 'user_plan';
|
||||||
|
|
||||||
|
@override
|
||||||
|
UserModel build() {
|
||||||
|
final prefs = ref.watch(sharedPreferencesProvider);
|
||||||
|
final planName = prefs.getString(_key);
|
||||||
|
final plan = UserPlan.values.firstWhere(
|
||||||
|
(e) => e.name == planName,
|
||||||
|
orElse: () => UserPlan.free,
|
||||||
|
);
|
||||||
|
return UserModel(plan: plan);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> setPlan(UserPlan plan) async {
|
||||||
|
final prefs = ref.read(sharedPreferencesProvider);
|
||||||
|
state = UserModel(plan: plan);
|
||||||
|
await prefs.setString(_key, plan.name);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> toggleVip() async {
|
||||||
|
await setPlan(state.isVip ? UserPlan.free : UserPlan.vip);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
final currentUserProvider = NotifierProvider<CurrentUserNotifier, UserModel>(
|
||||||
|
CurrentUserNotifier.new,
|
||||||
|
);
|
||||||
@@ -97,6 +97,7 @@ class ExchangeRateService {
|
|||||||
|
|
||||||
final fromRate = currentRates[from] ?? 1.0;
|
final fromRate = currentRates[from] ?? 1.0;
|
||||||
final toRate = currentRates[to] ?? 1.0;
|
final toRate = currentRates[to] ?? 1.0;
|
||||||
|
if (fromRate == 0) return amount;
|
||||||
|
|
||||||
final amountInUsd = amount / fromRate;
|
final amountInUsd = amount / fromRate;
|
||||||
return amountInUsd * toRate;
|
return amountInUsd * toRate;
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ class TranslationService {
|
|||||||
for (final entry in _ruToEn.entries) entry.value.toLowerCase(): entry.key,
|
for (final entry in _ruToEn.entries) entry.value.toLowerCase(): entry.key,
|
||||||
};
|
};
|
||||||
|
|
||||||
String? _dictionaryLookup(String input, TranslateDirection direction) {
|
String? dictionaryLookup(String input, TranslateDirection direction) {
|
||||||
final normalized = input.trim().toLowerCase();
|
final normalized = input.trim().toLowerCase();
|
||||||
if (normalized.isEmpty) return null;
|
if (normalized.isEmpty) return null;
|
||||||
final map = direction == TranslateDirection.ruToEn ? _ruToEn : _enToRu;
|
final map = direction == TranslateDirection.ruToEn ? _ruToEn : _enToRu;
|
||||||
@@ -75,7 +75,7 @@ class TranslationService {
|
|||||||
final trimmed = input.trim();
|
final trimmed = input.trim();
|
||||||
if (trimmed.isEmpty) return null;
|
if (trimmed.isEmpty) return null;
|
||||||
|
|
||||||
final cached = _dictionaryLookup(trimmed, direction);
|
final cached = dictionaryLookup(trimmed, direction);
|
||||||
if (cached != null) {
|
if (cached != null) {
|
||||||
return TranslationResult(cached, fromCache: true);
|
return TranslationResult(cached, fromCache: true);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user