mirror of
https://github.com/koloideal/Casha.git
synced 2026-08-08 17:51:14 +03:00
Compare commits
25 Commits
127a917eac
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| c4ac692019 | |||
| 861a9abd02 | |||
| e3c60c4775 | |||
| 64a3f4e34e | |||
| 19db4fe688 | |||
| 00bdd63ea6 | |||
| 7b9bf6d060 | |||
| 4f56e4983c | |||
| 58bfc6b12c | |||
| 4b548adb9a | |||
| 4b5c6be212 | |||
| 186cec8e2a | |||
| cd6113f3c6 | |||
| 4727835402 | |||
| 65ea30339d | |||
| 3adac05cdf | |||
| 5891440a0c | |||
| f2d444cb16 | |||
| 2b89545248 | |||
| 6fdf4eedf1 | |||
| 1a6ad1fe27 | |||
| bc51609f85 | |||
| ed45748c95 | |||
| 83fd8bdbf1 | |||
| 3961327bdb |
@@ -20,6 +20,15 @@ lib/
|
||||
├── data/ # Database schema, repositories
|
||||
├── features/ # Feature modules (provider + screen + 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
|
||||
```
|
||||
|
||||
@@ -46,6 +55,8 @@ lib/
|
||||
- `services/` — `ExchangeRateService`, `StorageService`
|
||||
- `utils/` — `CurrencyUtils`
|
||||
- `widgets/` — `BynSign`, `ErrorSnackbar`
|
||||
- `feature_flags/` — `FeatureFlags` abstraction and plan-specific implementations
|
||||
- `paywall/` — `PaywallGuard`, `PaywallBanner`, `PaywallScreen`
|
||||
|
||||
## Architecture Rules
|
||||
|
||||
@@ -57,6 +68,14 @@ lib/
|
||||
- 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`
|
||||
|
||||
### 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
|
||||
|
||||
**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.
|
||||
|
||||
**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
|
||||
|
||||
- **dashboard** — main screen with account carousel (`BalanceCard`), transaction list, search, filter chips, budget progress, account editor overlay
|
||||
@@ -125,4 +182,7 @@ result.when(
|
||||
- Do not create new providers in `shared/providers/` unless the provider is needed by 2+ features
|
||||
- Do not use `BuildContext` across async gaps without checking `mounted`
|
||||
- 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`
|
||||
@@ -22,6 +22,10 @@ android {
|
||||
targetCompatibility = JavaVersion.VERSION_17
|
||||
}
|
||||
|
||||
kotlinOptions {
|
||||
jvmTarget = "17"
|
||||
}
|
||||
|
||||
defaultConfig {
|
||||
applicationId = "com.kolo.casha"
|
||||
minSdk = flutter.minSdkVersion
|
||||
@@ -30,18 +34,22 @@ android {
|
||||
versionName = flutter.versionName
|
||||
}
|
||||
|
||||
signingConfigs {
|
||||
create("release") {
|
||||
keyAlias = keyProperties["keyAlias"] as String
|
||||
keyPassword = keyProperties["keyPassword"] as String
|
||||
storeFile = file(keyProperties["storeFile"] as String)
|
||||
storePassword = keyProperties["storePassword"] as String
|
||||
if (keyPropertiesFile.exists()) {
|
||||
signingConfigs {
|
||||
create("release") {
|
||||
keyAlias = keyProperties["keyAlias"] as String
|
||||
keyPassword = keyProperties["keyPassword"] as String
|
||||
storeFile = file(keyProperties["storeFile"] as String)
|
||||
storePassword = keyProperties["storePassword"] as String
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
release {
|
||||
signingConfig = signingConfigs.getByName("release")
|
||||
if (keyPropertiesFile.exists()) {
|
||||
signingConfig = signingConfigs.getByName("release")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ pluginManagement {
|
||||
plugins {
|
||||
id("dev.flutter.flutter-plugin-loader") version "1.0.0"
|
||||
id("com.android.application") version "8.11.1" apply false
|
||||
id("org.jetbrains.kotlin.android") version "2.2.20" apply false
|
||||
}
|
||||
|
||||
include(":app")
|
||||
|
||||
@@ -6,13 +6,31 @@ import '../features/dashboard/screen.dart';
|
||||
import '../features/add_transaction/screen.dart';
|
||||
import '../features/categories/screen.dart';
|
||||
import '../features/settings/screen.dart';
|
||||
import '../features/settings/categories/category_manager_screen.dart';
|
||||
import '../features/onboarding/screen.dart';
|
||||
import '../shared/models/transaction.dart';
|
||||
import '../shared/paywall/paywall_screen.dart';
|
||||
import '../shared/services/onboarding_service.dart';
|
||||
import '../shared/widgets/pro_screen.dart';
|
||||
import '../shared/widgets/backup_screen.dart';
|
||||
import '../shared/providers/premium_provider.dart';
|
||||
|
||||
final _shellKey = GlobalKey<NavigatorState>();
|
||||
|
||||
final appRouter = GoRouter(
|
||||
initialLocation: '/dashboard',
|
||||
redirect: (context, state) {
|
||||
final location = state.uri.toString();
|
||||
if (OnboardingService.shouldShowOnboarding && location != '/onboarding') {
|
||||
return '/onboarding';
|
||||
}
|
||||
return null;
|
||||
},
|
||||
routes: [
|
||||
GoRoute(
|
||||
path: '/onboarding',
|
||||
builder: (context, state) => const OnboardingScreen(),
|
||||
),
|
||||
ShellRoute(
|
||||
navigatorKey: _shellKey,
|
||||
builder: (context, state, child) => AppShell(child: child),
|
||||
@@ -44,6 +62,27 @@ final appRouter = GoRouter(
|
||||
return AddTransactionScreen(initial: transaction);
|
||||
},
|
||||
),
|
||||
GoRoute(
|
||||
path: '/settings/categories',
|
||||
builder: (context, state) => const CategoryManagerScreen(),
|
||||
),
|
||||
GoRoute(
|
||||
path: '/paywall',
|
||||
builder: (context, state) => const PaywallScreen(),
|
||||
),
|
||||
GoRoute(
|
||||
path: '/pro',
|
||||
builder: (context, state) => const ProScreen(),
|
||||
),
|
||||
GoRoute(
|
||||
path: '/backup',
|
||||
redirect: (context, state) {
|
||||
final container = ProviderScope.containerOf(context);
|
||||
final isPremium = container.read(isPremiumProvider);
|
||||
return isPremium ? null : '/pro';
|
||||
},
|
||||
builder: (context, state) => const BackupScreen(),
|
||||
),
|
||||
],
|
||||
);
|
||||
|
||||
|
||||
+23
-21
@@ -44,8 +44,8 @@ class AppTheme {
|
||||
scaffoldBackgroundColor: AppColors.background,
|
||||
colorScheme: const ColorScheme.dark(
|
||||
surface: AppColors.surface,
|
||||
primary: AppColors.accent,
|
||||
secondary: AppColors.accent,
|
||||
primary: const Color(0xFF7C6DED),
|
||||
secondary: const Color(0xFF7C6DED),
|
||||
onPrimary: Colors.white,
|
||||
onSurface: AppColors.textPrimary,
|
||||
),
|
||||
@@ -70,11 +70,11 @@ class AppTheme {
|
||||
),
|
||||
navigationBarTheme: NavigationBarThemeData(
|
||||
backgroundColor: AppColors.surface,
|
||||
indicatorColor: AppColors.accent.withOpacity(0.2),
|
||||
indicatorColor: const Color(0xFF7C6DED).withOpacity(0.2),
|
||||
labelTextStyle: WidgetStateProperty.resolveWith((states) {
|
||||
if (states.contains(WidgetState.selected)) {
|
||||
return GoogleFonts.poppins(
|
||||
color: AppColors.accent,
|
||||
color: const Color(0xFF7C6DED),
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w600,
|
||||
);
|
||||
@@ -86,7 +86,7 @@ class AppTheme {
|
||||
}),
|
||||
iconTheme: WidgetStateProperty.resolveWith((states) {
|
||||
if (states.contains(WidgetState.selected)) {
|
||||
return const IconThemeData(color: AppColors.accent);
|
||||
return const IconThemeData(color: const Color(0xFF7C6DED));
|
||||
}
|
||||
return const IconThemeData(color: AppColors.textSecondary);
|
||||
}),
|
||||
@@ -104,14 +104,14 @@ class AppTheme {
|
||||
),
|
||||
focusedBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
borderSide: const BorderSide(color: AppColors.accent, width: 1.5),
|
||||
borderSide: const BorderSide(color: const Color(0xFF7C6DED), width: 1.5),
|
||||
),
|
||||
labelStyle: const TextStyle(color: AppColors.textSecondary),
|
||||
hintStyle: const TextStyle(color: AppColors.textSecondary),
|
||||
),
|
||||
elevatedButtonTheme: ElevatedButtonThemeData(
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: AppColors.accent,
|
||||
backgroundColor: const Color(0xFF7C6DED),
|
||||
foregroundColor: Colors.white,
|
||||
minimumSize: const Size(double.infinity, 52),
|
||||
shape: RoundedRectangleBorder(
|
||||
@@ -132,10 +132,12 @@ class AppTheme {
|
||||
|
||||
static ThemeData get lightTheme {
|
||||
final base = ThemeData.light(useMaterial3: true);
|
||||
final textTheme = GoogleFonts.poppinsTextTheme(base.textTheme).apply(
|
||||
bodyColor: const Color(0xFF1A1A2E),
|
||||
displayColor: const Color(0xFF1A1A2E),
|
||||
fontFamilyFallback: ['Roboto'],
|
||||
final textTheme = _withCyrillicFallback(
|
||||
base.textTheme.apply(
|
||||
fontFamily: 'Poppins',
|
||||
bodyColor: const Color(0xFF1A1A2E),
|
||||
displayColor: const Color(0xFF1A1A2E),
|
||||
),
|
||||
);
|
||||
|
||||
return base.copyWith(
|
||||
@@ -143,8 +145,8 @@ class AppTheme {
|
||||
scaffoldBackgroundColor: const Color(0xFFF0F0F7),
|
||||
colorScheme: const ColorScheme.light(
|
||||
surface: Colors.white,
|
||||
primary: AppColors.accent,
|
||||
secondary: AppColors.accent,
|
||||
primary: const Color(0xFF7C6DED),
|
||||
secondary: const Color(0xFF7C6DED),
|
||||
onPrimary: Colors.white,
|
||||
onSurface: Color(0xFF1A1A2E),
|
||||
),
|
||||
@@ -166,15 +168,15 @@ class AppTheme {
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
iconTheme: const IconThemeData(color: AppColors.accent),
|
||||
iconTheme: const IconThemeData(color: const Color(0xFF7C6DED)),
|
||||
),
|
||||
navigationBarTheme: NavigationBarThemeData(
|
||||
backgroundColor: Colors.white,
|
||||
indicatorColor: AppColors.accent.withOpacity(0.2),
|
||||
indicatorColor: const Color(0xFF7C6DED).withOpacity(0.2),
|
||||
labelTextStyle: WidgetStateProperty.resolveWith((states) {
|
||||
if (states.contains(WidgetState.selected)) {
|
||||
return GoogleFonts.poppins(
|
||||
color: AppColors.accent,
|
||||
color: const Color(0xFF7C6DED),
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w600,
|
||||
);
|
||||
@@ -186,7 +188,7 @@ class AppTheme {
|
||||
}),
|
||||
iconTheme: WidgetStateProperty.resolveWith((states) {
|
||||
if (states.contains(WidgetState.selected)) {
|
||||
return const IconThemeData(color: AppColors.accent);
|
||||
return const IconThemeData(color: const Color(0xFF7C6DED));
|
||||
}
|
||||
return const IconThemeData(color: Color(0xFF9999BB));
|
||||
}),
|
||||
@@ -204,14 +206,14 @@ class AppTheme {
|
||||
),
|
||||
focusedBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
borderSide: const BorderSide(color: AppColors.accent, width: 1.5),
|
||||
borderSide: const BorderSide(color: const Color(0xFF7C6DED), width: 1.5),
|
||||
),
|
||||
labelStyle: const TextStyle(color: Color(0xFF9999BB)),
|
||||
hintStyle: const TextStyle(color: Color(0xFF9999BB)),
|
||||
),
|
||||
elevatedButtonTheme: ElevatedButtonThemeData(
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: AppColors.accent,
|
||||
backgroundColor: const Color(0xFF7C6DED),
|
||||
foregroundColor: Colors.white,
|
||||
minimumSize: const Size(double.infinity, 52),
|
||||
shape: RoundedRectangleBorder(
|
||||
@@ -227,10 +229,10 @@ class AppTheme {
|
||||
color: Color(0xFFDDDDEE),
|
||||
thickness: 1,
|
||||
),
|
||||
iconTheme: const IconThemeData(color: AppColors.accent),
|
||||
iconTheme: const IconThemeData(color: const Color(0xFF7C6DED)),
|
||||
chipTheme: ChipThemeData(
|
||||
backgroundColor: const Color(0xFFEEEEF8),
|
||||
selectedColor: AppColors.accent,
|
||||
selectedColor: const Color(0xFF7C6DED),
|
||||
labelStyle: GoogleFonts.poppins(
|
||||
color: const Color(0xFF1A1A2E),
|
||||
),
|
||||
|
||||
@@ -26,6 +26,14 @@ class AppCategories {
|
||||
'Shopping',
|
||||
'Health',
|
||||
'Entertainment',
|
||||
'Housing',
|
||||
'Education',
|
||||
'Travel',
|
||||
'Utilities',
|
||||
'Clothing',
|
||||
'Sports',
|
||||
'Beauty',
|
||||
'Pets',
|
||||
'Other'
|
||||
];
|
||||
|
||||
@@ -35,6 +43,8 @@ class AppCategories {
|
||||
'Gift',
|
||||
'Investment',
|
||||
'Refund',
|
||||
'Business',
|
||||
'Savings',
|
||||
'Other'
|
||||
];
|
||||
|
||||
@@ -50,11 +60,21 @@ class AppCategories {
|
||||
'Shopping': Icons.shopping_bag_rounded,
|
||||
'Health': Icons.favorite_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,
|
||||
'Freelance': Icons.laptop_rounded,
|
||||
'Gift': Icons.card_giftcard_rounded,
|
||||
'Investment': Icons.trending_up_rounded,
|
||||
'Refund': Icons.money_rounded,
|
||||
'Business': Icons.business_center_rounded,
|
||||
'Savings': Icons.savings_rounded,
|
||||
'Other': Icons.category_rounded,
|
||||
};
|
||||
|
||||
@@ -64,15 +84,141 @@ class AppCategories {
|
||||
'Shopping': Color(0xFFFFD369),
|
||||
'Health': Color(0xFF69FFB4),
|
||||
'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),
|
||||
'Freelance': Color(0xFF69FFB4),
|
||||
'Gift': Color(0xFFFFB469),
|
||||
'Investment': Color(0xFF69B4FF),
|
||||
'Refund': Color(0xFFB4FF69),
|
||||
'Business': Color(0xFFFF8C69),
|
||||
'Savings': Color(0xFF4CAF8C),
|
||||
'Other': Color(0xFFB469FF),
|
||||
};
|
||||
|
||||
static const iconNames = {
|
||||
'Food': 'restaurant',
|
||||
'Transport': 'car',
|
||||
'Shopping': 'shopping_bag',
|
||||
'Health': 'heart',
|
||||
'Entertainment': 'movie',
|
||||
'Housing': 'home',
|
||||
'Education': 'school',
|
||||
'Travel': 'flight',
|
||||
'Utilities': 'bolt',
|
||||
'Clothing': 'checkroom',
|
||||
'Sports': 'fitness',
|
||||
'Beauty': 'brush',
|
||||
'Pets': 'pets',
|
||||
'Salary': 'work',
|
||||
'Freelance': 'laptop',
|
||||
'Gift': 'gift',
|
||||
'Investment': 'trending_up',
|
||||
'Refund': 'money',
|
||||
'Business': 'work',
|
||||
'Savings': 'savings',
|
||||
'Other': 'category',
|
||||
};
|
||||
|
||||
static const ruLabels = {
|
||||
'Food': 'Еда',
|
||||
'Transport': 'Транспорт',
|
||||
'Shopping': 'Покупки',
|
||||
'Entertainment': 'Развлечения',
|
||||
'Health': 'Здоровье',
|
||||
'Housing': 'Жильё',
|
||||
'Education': 'Образование',
|
||||
'Travel': 'Путешествия',
|
||||
'Salary': 'Зарплата',
|
||||
'Freelance': 'Фриланс',
|
||||
'Investment': 'Инвестиции',
|
||||
'Gift': 'Подарок',
|
||||
'Refund': 'Возврат',
|
||||
'Other': 'Другое',
|
||||
'Utilities': 'Коммунальные',
|
||||
'Clothing': 'Одежда',
|
||||
'Sports': 'Спорт',
|
||||
'Beauty': 'Красота',
|
||||
'Pets': 'Питомцы',
|
||||
'Business': 'Бизнес',
|
||||
'Savings': 'Накопления',
|
||||
'Dining': 'Ресторан',
|
||||
'Cafe': 'Кафе',
|
||||
'Coffee': 'Кофе',
|
||||
'Restaurant': 'Ресторан',
|
||||
'Fuel': 'Топливо',
|
||||
'Taxi': 'Такси',
|
||||
'Phone': 'Связь',
|
||||
'Internet': 'Интернет',
|
||||
'Insurance': 'Страховка',
|
||||
'Taxes': 'Налоги',
|
||||
'Medicine': 'Медицина',
|
||||
'Children': 'Дети',
|
||||
'Hobby': 'Хобби',
|
||||
'Music': 'Музыка',
|
||||
'Games': 'Игры',
|
||||
'Books': 'Книги',
|
||||
};
|
||||
}
|
||||
|
||||
const Map<String, IconData> kCategoryIcons = {
|
||||
'restaurant': Icons.restaurant_rounded,
|
||||
'car': Icons.directions_car_rounded,
|
||||
'shopping_bag': Icons.shopping_bag_rounded,
|
||||
'heart': Icons.favorite_rounded,
|
||||
'movie': Icons.movie_rounded,
|
||||
'work': Icons.work_rounded,
|
||||
'laptop': Icons.laptop_rounded,
|
||||
'gift': Icons.card_giftcard_rounded,
|
||||
'trending_up': Icons.trending_up_rounded,
|
||||
'money': Icons.payments_rounded,
|
||||
'category': Icons.category_rounded,
|
||||
'home': Icons.home_rounded,
|
||||
'school': Icons.school_rounded,
|
||||
'flight': Icons.flight_rounded,
|
||||
'fitness': Icons.fitness_center_rounded,
|
||||
'pets': Icons.pets_rounded,
|
||||
'coffee': Icons.local_cafe_rounded,
|
||||
'grocery': Icons.local_grocery_store_rounded,
|
||||
'phone': Icons.smartphone_rounded,
|
||||
'bolt': Icons.bolt_rounded,
|
||||
'water': Icons.water_drop_rounded,
|
||||
'savings': Icons.savings_rounded,
|
||||
'card': Icons.credit_card_rounded,
|
||||
'games': Icons.sports_esports_rounded,
|
||||
'music': Icons.music_note_rounded,
|
||||
'book': Icons.menu_book_rounded,
|
||||
'medical': Icons.medical_services_rounded,
|
||||
'child': Icons.child_care_rounded,
|
||||
'build': Icons.build_rounded,
|
||||
'beauty': Icons.spa_rounded,
|
||||
};
|
||||
|
||||
IconData categoryIconByName(String? name) {
|
||||
return kCategoryIcons[name] ?? Icons.category_rounded;
|
||||
}
|
||||
|
||||
const List<Color> kCategoryColors = [
|
||||
Color(0xFFFF8C69),
|
||||
Color(0xFF69B4FF),
|
||||
Color(0xFFFFD369),
|
||||
Color(0xFF69FFB4),
|
||||
Color(0xFFFF69B4),
|
||||
Color(0xFF4CAF8C),
|
||||
Color(0xFFFFB469),
|
||||
Color(0xFFB4FF69),
|
||||
Color(0xFFB469FF),
|
||||
Color(0xFF7C6DED),
|
||||
Color(0xFFE05C6B),
|
||||
Color(0xFF4DD0E1),
|
||||
];
|
||||
|
||||
enum AmountFormat { commasDot, spacesDot, plain }
|
||||
|
||||
extension AmountFormatExt on AmountFormat {
|
||||
|
||||
+194
-17
@@ -24,9 +24,6 @@ class AppStrings {
|
||||
String get filterMonth => _ru ? 'Месяц' : 'Month';
|
||||
String get income => _ru ? 'Доход' : 'Income';
|
||||
String get expenses => _ru ? 'Расходы' : 'Expenses';
|
||||
String get monthlyBudget => _ru ? 'Бюджет на месяц' : 'Monthly Budget';
|
||||
String get spent => _ru ? 'Потрачено' : 'Spent';
|
||||
String get limit => _ru ? 'Лимит' : 'Limit';
|
||||
String get noTransactions =>
|
||||
_ru ? 'Транзакции не найдены' : 'No transactions found';
|
||||
String get addFirstTx => _ru
|
||||
@@ -80,18 +77,6 @@ class AppStrings {
|
||||
String get language => _ru ? 'Язык' : 'Language';
|
||||
String get langRu => _ru ? 'Русский' : 'Russian';
|
||||
String get langEn => _ru ? 'Английский' : 'English';
|
||||
String get budget => _ru ? 'Бюджет' : 'Budget';
|
||||
String get budgetHint => _ru ? 'Месячный лимит' : 'Monthly limit';
|
||||
String get budgetNone => _ru ? 'Не установлен' : 'Not set';
|
||||
String get monthlyBudgetSetting => _ru ? 'Месячный бюджет' : 'Monthly Budget';
|
||||
String get yourMonthlySpendingLimit =>
|
||||
_ru ? 'Ваш лимит расходов на месяц' : 'Your monthly spending limit';
|
||||
String get setMonthlySpendingLimit => _ru
|
||||
? 'Контролируйте свои расходы за месяц'
|
||||
: 'Track your monthly spending';
|
||||
String get leaveEmptyToRemove => _ru
|
||||
? 'Оставьте пустым для удаления лимита'
|
||||
: 'Leave empty to remove budget limit';
|
||||
String get data => _ru ? 'Данные' : 'Data';
|
||||
String get exportData => _ru ? 'Экспорт данных' : 'Export data';
|
||||
String get clearData => _ru ? 'Очистить данные' : 'Clear all data';
|
||||
@@ -115,11 +100,27 @@ class AppStrings {
|
||||
String get dangerZone => _ru ? 'Опасная зона' : 'Danger Zone';
|
||||
|
||||
String get navDashboard => _ru ? 'Главная' : 'Dashboard';
|
||||
String get navCategories => _ru ? 'Категории' : 'Categories';
|
||||
String get navCategories => _ru ? 'Статистика' : 'Statistics';
|
||||
String get navSettings => _ru ? 'Настройки' : 'Settings';
|
||||
|
||||
String get statistics => _ru ? 'Статистика' : 'Statistics';
|
||||
String get allAccounts => _ru ? 'Все счета' : 'All accounts';
|
||||
String get categories => _ru ? 'Категории' : 'Categories';
|
||||
String get rankedByAmount => _ru ? 'По сумме' : 'Ranked by Amount';
|
||||
String get overview => _ru ? 'Обзор' : 'Overview';
|
||||
String get netBalance => _ru ? 'Чистый баланс' : 'Net Balance';
|
||||
String get averageIncome => _ru ? 'Средний доход' : 'Average Income';
|
||||
String get averageExpense => _ru ? 'Средний расход' : 'Average Expense';
|
||||
String get transactionsCount => _ru ? 'Транзакции' : 'Transactions';
|
||||
String get expenseStructure => _ru ? 'Структура категорий' : 'Category Structure';
|
||||
String get topCategories => _ru ? 'Топ категорий' : 'Top Categories';
|
||||
String get monthlyTrend => _ru ? 'Тренд по месяцам' : 'Monthly Trend';
|
||||
String get topCategory => _ru ? 'Лидер категории' : 'Top Category';
|
||||
String get shareOfTotal => _ru ? 'Доля от общего' : 'Share of Total';
|
||||
String get thisPeriod => _ru ? 'За период' : 'This Period';
|
||||
String get analyticsInsight => _ru ? 'Финансовый срез по выбранному диапазону и счёту' : 'Financial snapshot for the selected range and account';
|
||||
String get noStatisticsYet => _ru ? 'Пока недостаточно данных' : 'Not enough data yet';
|
||||
String get statisticsWillAppear => _ru ? 'Когда появятся операции, здесь будет красивый аналитический обзор' : 'Once you add transactions, a beautiful analytics overview will appear here';
|
||||
String get addCategory => _ru ? 'Добавить категорию' : 'Add Category';
|
||||
String get editCategory => _ru ? 'Редактировать' : 'Edit Category';
|
||||
String get categoryName => _ru ? 'Название' : 'Name';
|
||||
@@ -153,6 +154,7 @@ class AppStrings {
|
||||
'Freelance': 'Фриланс',
|
||||
'Investment': 'Инвестиции',
|
||||
'Gift': 'Подарок',
|
||||
'Refund': 'Возврат',
|
||||
'Other': 'Другое',
|
||||
'Utilities': 'Коммунальные',
|
||||
'Clothing': 'Одежда',
|
||||
@@ -166,7 +168,7 @@ class AppStrings {
|
||||
}
|
||||
|
||||
String get colorPrimary => _ru ? 'Основной' : 'Primary';
|
||||
String get colorSecondary => _ru ? 'Второй' : 'Secondary';
|
||||
String get colorSecondary => _ru ? 'Второй' : 'Second';
|
||||
String get colorSecond => _ru ? 'Второй' : 'Second';
|
||||
String get colorSolid => _ru ? 'Однотон' : 'Solid';
|
||||
String get gradientLinear => _ru ? 'Линейный' : 'Linear';
|
||||
@@ -204,5 +206,180 @@ class AppStrings {
|
||||
String get accountPlaceholder => _ru ? 'Счёт' : 'Account';
|
||||
String get saveError => _ru ? 'Ошибка сохранения' : 'Save error';
|
||||
|
||||
String get manageCategories => _ru ? 'Категории' : 'Categories';
|
||||
String get manageCategoriesSubtitle => _ru
|
||||
? 'Создавайте и редактируйте свои категории'
|
||||
: 'Create and edit your own categories';
|
||||
String get customCategories => _ru ? 'Свои категории' : 'Custom categories';
|
||||
String get defaultCategories =>
|
||||
_ru ? 'Стандартные категории' : 'Default categories';
|
||||
String get newCategory => _ru ? 'Новая категория' : 'New category';
|
||||
String get nameEn => _ru ? 'Название (EN)' : 'Name (EN)';
|
||||
String get nameRu => _ru ? 'Название (RU)' : 'Name (RU)';
|
||||
String get nameEnHint => _ru ? 'Например, Coffee' : 'e.g. Coffee';
|
||||
String get nameRuHint => _ru ? 'Например, Кофе' : 'e.g. Кофе';
|
||||
String get autoTranslate => _ru ? 'Автоперевод' : 'Auto-translate';
|
||||
String get applyTranslation => _ru ? 'Применить' : 'Apply';
|
||||
String get translating => _ru ? 'Перевод...' : 'Translating...';
|
||||
String get translationFailed =>
|
||||
_ru ? 'Не удалось перевести' : 'Translation failed';
|
||||
String get categoryNameRequired =>
|
||||
_ru ? 'Введите название' : 'Enter a name';
|
||||
String get deleteCategoryConfirm =>
|
||||
_ru ? 'Удалить эту категорию?' : 'Delete this category?';
|
||||
String get deleteCategoryWarning => _ru
|
||||
? 'Категория будет удалена. Прошлые транзакции сохранятся.'
|
||||
: 'The category will be removed. Past transactions are kept.';
|
||||
String get noCustomCategories =>
|
||||
_ru ? 'Вы ещё не добавили категории' : 'No custom categories yet';
|
||||
String get noCustomCategoriesHint => _ru
|
||||
? 'Нажмите +, чтобы создать свою категорию'
|
||||
: 'Tap + to create your own category';
|
||||
String get categoryType => _ru ? 'Тип' : 'Type';
|
||||
String get categorySaved => _ru ? 'Категория сохранена' : 'Category saved';
|
||||
|
||||
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';
|
||||
|
||||
String get onboardingWelcome => _ru ? 'Добро пожаловать в' : 'Welcome to';
|
||||
String get onboardingMultiCurrencyTitle =>
|
||||
_ru ? 'Все деньги\nна одном экране' : 'All Your Money,\nOne View';
|
||||
String get onboardingMultiCurrencyBody => _ru
|
||||
? 'Счета в разных валютах с автоматической конвертацией по актуальным курсам'
|
||||
: 'Accounts in different currencies, automatically converted at live exchange rates';
|
||||
String get onboardingCardsTitle =>
|
||||
_ru ? 'Живые карточки' : 'Cards That Come Alive';
|
||||
String get onboardingCardsBody => _ru
|
||||
? 'Наклоните телефон — и карточка оживает. Градиенты, цвета и высота — всё настраивается под вас'
|
||||
: 'Tilt your phone and watch them respond. Customize gradients, colors and height to make them yours';
|
||||
String get onboardingReadyTitle => _ru ? 'Всё готово' : "You're All Set";
|
||||
String get onboardingReadyBody => _ru
|
||||
? 'Если готовы — свайпните вправо, чтобы открыть приложение'
|
||||
: "If you're ready — swipe right to open the app";
|
||||
String get onboardingSwipeRight => _ru ? 'Свайп вправо' : 'Swipe Right';
|
||||
|
||||
String get proTitle => _ru ? 'Casha Pro' : 'Casha Pro';
|
||||
String get proAboutPro => _ru ? 'Подробнее' : 'About Pro';
|
||||
String get proSubtitle => _ru
|
||||
? 'Раскройте весь потенциал Casha'
|
||||
: 'Unlock the full power of Casha';
|
||||
String get proBuy => _ru ? 'Купить Pro' : 'Buy Pro';
|
||||
String get proFeatureCloudSync =>
|
||||
_ru ? 'Облачная синхронизация' : 'Cloud Sync';
|
||||
String get proFeatureCloudSyncDesc => _ru
|
||||
? 'Синхронизация между всеми вашими устройствами'
|
||||
: 'Sync across all your devices';
|
||||
String get proFeatureBiometric =>
|
||||
_ru ? 'Биометрическая защита' : 'Biometric Protection';
|
||||
String get proFeatureBiometricDesc => _ru
|
||||
? 'Защитите свои данные отпечатком пальца или Face ID'
|
||||
: 'Secure your data with fingerprint or Face ID';
|
||||
String get proFeatureAnalytics =>
|
||||
_ru ? 'Детальная аналитика' : 'Detailed Analytics';
|
||||
String get proFeatureAnalyticsDesc => _ru
|
||||
? 'Графики и статистика по расходам и доходам'
|
||||
: 'Charts and stats for income and spending';
|
||||
String get proFeatureCustomization =>
|
||||
_ru ? 'Кастомизация карточек' : 'Card Customization';
|
||||
String get proFeatureCustomizationDesc => _ru
|
||||
? 'Цвета, градиенты, высота — всё под вашим контролем'
|
||||
: 'Colors, gradients, height — all under your control';
|
||||
String get proFeatureAccounts =>
|
||||
_ru ? 'До 8 счетов' : 'Up to 8 Accounts';
|
||||
String get proFeatureAccountsDesc => _ru
|
||||
? 'Создавайте больше счетов для разных целей'
|
||||
: 'Create more accounts for different goals';
|
||||
String get proTryPro => _ru ? 'Попробовать Pro' : 'Try Pro';
|
||||
String get proRestorePurchases =>
|
||||
_ru ? 'Восстановить покупки' : 'Restore Purchases';
|
||||
String get proActive => _ru ? 'Pro активна' : 'Pro Active';
|
||||
String get proSignInForSync =>
|
||||
_ru ? 'Войдите, чтобы включить синхронизацию' : 'Sign in to enable sync';
|
||||
String get proSignInGoogle =>
|
||||
_ru ? 'Войти через Google' : 'Sign in with Google';
|
||||
String get proSyncEnabled =>
|
||||
_ru ? 'Синхронизация включена' : 'Sync enabled';
|
||||
String get proLastBackup => _ru ? 'Последняя резервная копия' : 'Last backup';
|
||||
String get proSignOut => _ru ? 'Выйти' : 'Sign Out';
|
||||
String get proPurchaseSuccess =>
|
||||
_ru ? 'Pro успешно активирована!' : 'Pro successfully activated!';
|
||||
String get proPurchaseFailed =>
|
||||
_ru ? 'Не удалось оформить подписку' : 'Purchase failed';
|
||||
String get proRestoreSuccess =>
|
||||
_ru ? 'Покупки восстановлены!' : 'Purchases restored!';
|
||||
String get proRestoreNotFound =>
|
||||
_ru ? 'Предыдущие покупки не найдены' : 'No previous purchases found';
|
||||
String get proTapToClose =>
|
||||
_ru ? 'Нажмите чтобы закрыть' : 'Tap anywhere to close';
|
||||
String get proResetData =>
|
||||
_ru ? 'Сбросить тестовые данные' : 'Reset Test Data';
|
||||
String get proResetDataDesc => _ru
|
||||
? 'Локально отменить подписку для тестирования'
|
||||
: 'Locally cancel subscription for testing';
|
||||
String get proResetDataConfirm => _ru
|
||||
? 'Сбросить подписку? Это локально очистит ваш премиум статус.'
|
||||
: 'Reset subscription? This will locally clear your premium status.';
|
||||
String get proResetDataSuccess => _ru
|
||||
? 'Премиум статус сброшен'
|
||||
: 'Premium status reset';
|
||||
String get proRestoreSuccessTitle =>
|
||||
_ru ? 'Покупки восстановлены!' : 'Purchases Restored!';
|
||||
String get backupTitle => _ru ? 'Резервная копия' : 'Backup';
|
||||
String get backupCreate => _ru ? 'Создать резервную копию' : 'Create Backup';
|
||||
String get backupRestore => _ru ? 'Восстановить из копии' : 'Restore Backup';
|
||||
String get backupCreating => _ru ? 'Создание копии...' : 'Creating backup...';
|
||||
String get backupRestoring => _ru ? 'Восстановление...' : 'Restoring...';
|
||||
String get backupSuccess =>
|
||||
_ru ? 'Резервная копия успешно создана!' : 'Backup created successfully!';
|
||||
String get backupRestoreSuccess =>
|
||||
_ru ? 'Данные успешно восстановлены!' : 'Data restored successfully!';
|
||||
String get backupRestoreFailed =>
|
||||
_ru ? 'Не удалось восстановить данные' : 'Failed to restore data';
|
||||
String get backupNoFileFound =>
|
||||
_ru ? 'Резервная копия не найдена' : 'No backup file found';
|
||||
String get backupTokenMismatch =>
|
||||
_ru
|
||||
? 'Этот файл резервной копии принадлежит другому покупателю Premium'
|
||||
: 'This backup file belongs to another Premium purchaser';
|
||||
String get backupInvalidFormat =>
|
||||
_ru ? 'Неверный формат файла резервной копии' : 'Invalid backup file format';
|
||||
String get backupNoToken =>
|
||||
_ru
|
||||
? 'Файл резервной копии не содержит токен покупки'
|
||||
: 'Backup file does not contain a purchase token';
|
||||
String get backupRequiresPremium =>
|
||||
_ru ? 'Резервная копия доступна только для Pro' : 'Backup is a Pro-only feature';
|
||||
String get backupRequiresSignIn =>
|
||||
_ru
|
||||
? 'Войдите в Google аккаунт для работы с резервными копиями'
|
||||
: 'Sign in to Google to manage backups';
|
||||
String get backupLastBackup => _ru ? 'Последняя копия' : 'Last backup';
|
||||
String get backupNever => _ru ? 'Никогда' : 'Never';
|
||||
String get backupSyncWithDrive =>
|
||||
_ru ? 'Синхронизация с Google Диском' : 'Google Drive Sync';
|
||||
String get backupSyncDesc =>
|
||||
_ru
|
||||
? 'Резервное копирование данных на ваш Google Диск'
|
||||
: 'Back up your data to your Google Drive';
|
||||
}
|
||||
|
||||
@@ -10,14 +10,14 @@ class CardColorService {
|
||||
static const _keyGradientLight = 'gradient_type_light';
|
||||
static const _keyGradientDark = 'gradient_type_dark';
|
||||
|
||||
static const defaultPrimary = Color(0xFFBEF264);
|
||||
static const defaultSecondary = Color(0xFF4D7C0F);
|
||||
static const defaultPrimary = Color(0xFF4CAF8C);
|
||||
static const defaultSecondary = Color(0xFF4CAF8C);
|
||||
|
||||
static const defaultPrimaryLight = Color(0xFF6A6482);
|
||||
static const defaultSecondaryLight = Color(0xFF000000);
|
||||
static const defaultPrimaryLight = Color(0xFF4CAF8C);
|
||||
static const defaultSecondaryLight = Color(0xFF4CAF8C);
|
||||
|
||||
static const defaultGradientLight = GradientType.sweep;
|
||||
static const defaultGradientDark = GradientType.radial;
|
||||
static const defaultGradientLight = GradientType.solid;
|
||||
static const defaultGradientDark = GradientType.solid;
|
||||
|
||||
static Future<(Color, Color, GradientType, GradientType)> load({
|
||||
int? accountId,
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
const kBalanceCardHeight = 200.0;
|
||||
const kBalanceCardCarouselHeight = 210.0;
|
||||
const kAddAccountCardHeight = 200.0;
|
||||
|
||||
class CardOverlayLayout {
|
||||
final bool compact;
|
||||
final double cardHeight;
|
||||
final double cardTop;
|
||||
final double cardPreviewGap;
|
||||
final double editorPanelHeight;
|
||||
final double sectionGap;
|
||||
final double panelPaddingTop;
|
||||
final double panelPaddingBottom;
|
||||
final double reservedBelowControls;
|
||||
final double hueSliderHeight;
|
||||
final double hexRowHeight;
|
||||
final double tabSpacing;
|
||||
final double controlSpacing;
|
||||
final double buttonVerticalPadding;
|
||||
|
||||
const CardOverlayLayout._({
|
||||
required this.compact,
|
||||
required this.cardHeight,
|
||||
required this.cardTop,
|
||||
required this.cardPreviewGap,
|
||||
required this.editorPanelHeight,
|
||||
required this.sectionGap,
|
||||
required this.panelPaddingTop,
|
||||
required this.panelPaddingBottom,
|
||||
required this.reservedBelowControls,
|
||||
required this.hueSliderHeight,
|
||||
required this.hexRowHeight,
|
||||
required this.tabSpacing,
|
||||
required this.controlSpacing,
|
||||
required this.buttonVerticalPadding,
|
||||
});
|
||||
|
||||
factory CardOverlayLayout.fromMediaQuery(MediaQueryData mq) {
|
||||
final compact = mq.size.height < 780;
|
||||
return CardOverlayLayout._(
|
||||
compact: compact,
|
||||
cardHeight: kBalanceCardHeight,
|
||||
cardTop: mq.padding.top + kToolbarHeight + (compact ? 8 : 16),
|
||||
cardPreviewGap: compact ? 12 : 32,
|
||||
editorPanelHeight: compact ? 88 : 96,
|
||||
sectionGap: compact ? 8 : 12,
|
||||
panelPaddingTop: compact ? 10 : 14,
|
||||
panelPaddingBottom: compact ? 14 : 22,
|
||||
reservedBelowControls: compact ? 62 : 78,
|
||||
hueSliderHeight: compact ? 28 : 36,
|
||||
hexRowHeight: compact ? 22 : 26,
|
||||
tabSpacing: compact ? 6 : 10,
|
||||
controlSpacing: compact ? 5 : 8,
|
||||
buttonVerticalPadding: compact ? 8 : 10,
|
||||
);
|
||||
}
|
||||
|
||||
double colorPanelHeight(MediaQueryData mq, double panelTop) {
|
||||
final available = mq.size.height - panelTop - mq.padding.bottom - 8;
|
||||
return available.clamp(compact ? 250 : 320, 410);
|
||||
}
|
||||
}
|
||||
@@ -8,12 +8,12 @@ import 'tables.dart';
|
||||
|
||||
part 'app_database.g.dart';
|
||||
|
||||
@DriftDatabase(tables: [Transactions, Categories, Budgets, ExchangeRates, Accounts])
|
||||
@DriftDatabase(tables: [Transactions, Categories, ExchangeRates, Accounts])
|
||||
class AppDatabase extends _$AppDatabase {
|
||||
AppDatabase() : super(_openConnection());
|
||||
|
||||
@override
|
||||
int get schemaVersion => 5;
|
||||
int get schemaVersion => 6;
|
||||
|
||||
@override
|
||||
MigrationStrategy get migration => MigrationStrategy(
|
||||
@@ -50,6 +50,28 @@ class AppDatabase extends _$AppDatabase {
|
||||
print('Migration: Error adding account_id column: $e');
|
||||
}
|
||||
}
|
||||
|
||||
if (from < 6) {
|
||||
await customStatement('DROP TABLE IF EXISTS budgets');
|
||||
try {
|
||||
final columns = await customSelect(
|
||||
'PRAGMA table_info(categories)',
|
||||
).get();
|
||||
final names = columns.map((row) => row.data['name']).toSet();
|
||||
if (!names.contains('label_en')) {
|
||||
await customStatement(
|
||||
'ALTER TABLE categories ADD COLUMN label_en TEXT',
|
||||
);
|
||||
}
|
||||
if (!names.contains('label_ru')) {
|
||||
await customStatement(
|
||||
'ALTER TABLE categories ADD COLUMN label_ru TEXT',
|
||||
);
|
||||
}
|
||||
} catch (e) {
|
||||
print('Migration: Error updating categories table: $e');
|
||||
}
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
@@ -149,6 +171,12 @@ class AppDatabase extends _$AppDatabase {
|
||||
return select(categories).get();
|
||||
}
|
||||
|
||||
Stream<List<Category>> watchAllCategories() {
|
||||
return (select(categories)
|
||||
..orderBy([(c) => OrderingTerm.asc(c.createdAt)]))
|
||||
.watch();
|
||||
}
|
||||
|
||||
Future<List<Category>> getCategoriesByType(String type) {
|
||||
return (select(categories)..where((c) => c.type.equals(type))).get();
|
||||
}
|
||||
@@ -165,20 +193,6 @@ class AppDatabase extends _$AppDatabase {
|
||||
return (delete(categories)..where((c) => c.id.equals(id))).go();
|
||||
}
|
||||
|
||||
Future<Budget?> getBudget(int month, int year) {
|
||||
return (select(budgets)
|
||||
..where((b) => b.month.equals(month) & b.year.equals(year)))
|
||||
.getSingleOrNull();
|
||||
}
|
||||
|
||||
Future<void> upsertBudget(BudgetsCompanion budget) {
|
||||
return into(budgets).insertOnConflictUpdate(budget);
|
||||
}
|
||||
|
||||
Future<int> deleteBudget(int id) {
|
||||
return (delete(budgets)..where((b) => b.id.equals(id))).go();
|
||||
}
|
||||
|
||||
Future<ExchangeRate?> getExchangeRate(String from, String to) {
|
||||
return (select(exchangeRates)
|
||||
..where((r) => r.fromCurrency.equals(from) & r.toCurrency.equals(to)))
|
||||
|
||||
@@ -745,6 +745,28 @@ class $CategoriesTable extends Categories
|
||||
type: DriftSqlType.string,
|
||||
requiredDuringInsert: true,
|
||||
);
|
||||
static const VerificationMeta _labelEnMeta = const VerificationMeta(
|
||||
'labelEn',
|
||||
);
|
||||
@override
|
||||
late final GeneratedColumn<String> labelEn = GeneratedColumn<String>(
|
||||
'label_en',
|
||||
aliasedName,
|
||||
true,
|
||||
type: DriftSqlType.string,
|
||||
requiredDuringInsert: false,
|
||||
);
|
||||
static const VerificationMeta _labelRuMeta = const VerificationMeta(
|
||||
'labelRu',
|
||||
);
|
||||
@override
|
||||
late final GeneratedColumn<String> labelRu = GeneratedColumn<String>(
|
||||
'label_ru',
|
||||
aliasedName,
|
||||
true,
|
||||
type: DriftSqlType.string,
|
||||
requiredDuringInsert: false,
|
||||
);
|
||||
static const VerificationMeta _iconMeta = const VerificationMeta('icon');
|
||||
@override
|
||||
late final GeneratedColumn<String> icon = GeneratedColumn<String>(
|
||||
@@ -795,6 +817,8 @@ class $CategoriesTable extends Categories
|
||||
id,
|
||||
name,
|
||||
type,
|
||||
labelEn,
|
||||
labelRu,
|
||||
icon,
|
||||
color,
|
||||
isDefault,
|
||||
@@ -831,6 +855,18 @@ class $CategoriesTable extends Categories
|
||||
} else if (isInserting) {
|
||||
context.missing(_typeMeta);
|
||||
}
|
||||
if (data.containsKey('label_en')) {
|
||||
context.handle(
|
||||
_labelEnMeta,
|
||||
labelEn.isAcceptableOrUnknown(data['label_en']!, _labelEnMeta),
|
||||
);
|
||||
}
|
||||
if (data.containsKey('label_ru')) {
|
||||
context.handle(
|
||||
_labelRuMeta,
|
||||
labelRu.isAcceptableOrUnknown(data['label_ru']!, _labelRuMeta),
|
||||
);
|
||||
}
|
||||
if (data.containsKey('icon')) {
|
||||
context.handle(
|
||||
_iconMeta,
|
||||
@@ -876,6 +912,14 @@ class $CategoriesTable extends Categories
|
||||
DriftSqlType.string,
|
||||
data['${effectivePrefix}type'],
|
||||
)!,
|
||||
labelEn: attachedDatabase.typeMapping.read(
|
||||
DriftSqlType.string,
|
||||
data['${effectivePrefix}label_en'],
|
||||
),
|
||||
labelRu: attachedDatabase.typeMapping.read(
|
||||
DriftSqlType.string,
|
||||
data['${effectivePrefix}label_ru'],
|
||||
),
|
||||
icon: attachedDatabase.typeMapping.read(
|
||||
DriftSqlType.string,
|
||||
data['${effectivePrefix}icon'],
|
||||
@@ -905,6 +949,8 @@ class Category extends DataClass implements Insertable<Category> {
|
||||
final int id;
|
||||
final String name;
|
||||
final String type;
|
||||
final String? labelEn;
|
||||
final String? labelRu;
|
||||
final String? icon;
|
||||
final String? color;
|
||||
final bool isDefault;
|
||||
@@ -913,6 +959,8 @@ class Category extends DataClass implements Insertable<Category> {
|
||||
required this.id,
|
||||
required this.name,
|
||||
required this.type,
|
||||
this.labelEn,
|
||||
this.labelRu,
|
||||
this.icon,
|
||||
this.color,
|
||||
required this.isDefault,
|
||||
@@ -924,6 +972,12 @@ class Category extends DataClass implements Insertable<Category> {
|
||||
map['id'] = Variable<int>(id);
|
||||
map['name'] = Variable<String>(name);
|
||||
map['type'] = Variable<String>(type);
|
||||
if (!nullToAbsent || labelEn != null) {
|
||||
map['label_en'] = Variable<String>(labelEn);
|
||||
}
|
||||
if (!nullToAbsent || labelRu != null) {
|
||||
map['label_ru'] = Variable<String>(labelRu);
|
||||
}
|
||||
if (!nullToAbsent || icon != null) {
|
||||
map['icon'] = Variable<String>(icon);
|
||||
}
|
||||
@@ -940,6 +994,12 @@ class Category extends DataClass implements Insertable<Category> {
|
||||
id: Value(id),
|
||||
name: Value(name),
|
||||
type: Value(type),
|
||||
labelEn: labelEn == null && nullToAbsent
|
||||
? const Value.absent()
|
||||
: Value(labelEn),
|
||||
labelRu: labelRu == null && nullToAbsent
|
||||
? const Value.absent()
|
||||
: Value(labelRu),
|
||||
icon: icon == null && nullToAbsent ? const Value.absent() : Value(icon),
|
||||
color: color == null && nullToAbsent
|
||||
? const Value.absent()
|
||||
@@ -958,6 +1018,8 @@ class Category extends DataClass implements Insertable<Category> {
|
||||
id: serializer.fromJson<int>(json['id']),
|
||||
name: serializer.fromJson<String>(json['name']),
|
||||
type: serializer.fromJson<String>(json['type']),
|
||||
labelEn: serializer.fromJson<String?>(json['labelEn']),
|
||||
labelRu: serializer.fromJson<String?>(json['labelRu']),
|
||||
icon: serializer.fromJson<String?>(json['icon']),
|
||||
color: serializer.fromJson<String?>(json['color']),
|
||||
isDefault: serializer.fromJson<bool>(json['isDefault']),
|
||||
@@ -971,6 +1033,8 @@ class Category extends DataClass implements Insertable<Category> {
|
||||
'id': serializer.toJson<int>(id),
|
||||
'name': serializer.toJson<String>(name),
|
||||
'type': serializer.toJson<String>(type),
|
||||
'labelEn': serializer.toJson<String?>(labelEn),
|
||||
'labelRu': serializer.toJson<String?>(labelRu),
|
||||
'icon': serializer.toJson<String?>(icon),
|
||||
'color': serializer.toJson<String?>(color),
|
||||
'isDefault': serializer.toJson<bool>(isDefault),
|
||||
@@ -982,6 +1046,8 @@ class Category extends DataClass implements Insertable<Category> {
|
||||
int? id,
|
||||
String? name,
|
||||
String? type,
|
||||
Value<String?> labelEn = const Value.absent(),
|
||||
Value<String?> labelRu = const Value.absent(),
|
||||
Value<String?> icon = const Value.absent(),
|
||||
Value<String?> color = const Value.absent(),
|
||||
bool? isDefault,
|
||||
@@ -990,6 +1056,8 @@ class Category extends DataClass implements Insertable<Category> {
|
||||
id: id ?? this.id,
|
||||
name: name ?? this.name,
|
||||
type: type ?? this.type,
|
||||
labelEn: labelEn.present ? labelEn.value : this.labelEn,
|
||||
labelRu: labelRu.present ? labelRu.value : this.labelRu,
|
||||
icon: icon.present ? icon.value : this.icon,
|
||||
color: color.present ? color.value : this.color,
|
||||
isDefault: isDefault ?? this.isDefault,
|
||||
@@ -1000,6 +1068,8 @@ class Category extends DataClass implements Insertable<Category> {
|
||||
id: data.id.present ? data.id.value : this.id,
|
||||
name: data.name.present ? data.name.value : this.name,
|
||||
type: data.type.present ? data.type.value : this.type,
|
||||
labelEn: data.labelEn.present ? data.labelEn.value : this.labelEn,
|
||||
labelRu: data.labelRu.present ? data.labelRu.value : this.labelRu,
|
||||
icon: data.icon.present ? data.icon.value : this.icon,
|
||||
color: data.color.present ? data.color.value : this.color,
|
||||
isDefault: data.isDefault.present ? data.isDefault.value : this.isDefault,
|
||||
@@ -1013,6 +1083,8 @@ class Category extends DataClass implements Insertable<Category> {
|
||||
..write('id: $id, ')
|
||||
..write('name: $name, ')
|
||||
..write('type: $type, ')
|
||||
..write('labelEn: $labelEn, ')
|
||||
..write('labelRu: $labelRu, ')
|
||||
..write('icon: $icon, ')
|
||||
..write('color: $color, ')
|
||||
..write('isDefault: $isDefault, ')
|
||||
@@ -1022,8 +1094,17 @@ class Category extends DataClass implements Insertable<Category> {
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode =>
|
||||
Object.hash(id, name, type, icon, color, isDefault, createdAt);
|
||||
int get hashCode => Object.hash(
|
||||
id,
|
||||
name,
|
||||
type,
|
||||
labelEn,
|
||||
labelRu,
|
||||
icon,
|
||||
color,
|
||||
isDefault,
|
||||
createdAt,
|
||||
);
|
||||
@override
|
||||
bool operator ==(Object other) =>
|
||||
identical(this, other) ||
|
||||
@@ -1031,6 +1112,8 @@ class Category extends DataClass implements Insertable<Category> {
|
||||
other.id == this.id &&
|
||||
other.name == this.name &&
|
||||
other.type == this.type &&
|
||||
other.labelEn == this.labelEn &&
|
||||
other.labelRu == this.labelRu &&
|
||||
other.icon == this.icon &&
|
||||
other.color == this.color &&
|
||||
other.isDefault == this.isDefault &&
|
||||
@@ -1041,6 +1124,8 @@ class CategoriesCompanion extends UpdateCompanion<Category> {
|
||||
final Value<int> id;
|
||||
final Value<String> name;
|
||||
final Value<String> type;
|
||||
final Value<String?> labelEn;
|
||||
final Value<String?> labelRu;
|
||||
final Value<String?> icon;
|
||||
final Value<String?> color;
|
||||
final Value<bool> isDefault;
|
||||
@@ -1049,6 +1134,8 @@ class CategoriesCompanion extends UpdateCompanion<Category> {
|
||||
this.id = const Value.absent(),
|
||||
this.name = const Value.absent(),
|
||||
this.type = const Value.absent(),
|
||||
this.labelEn = const Value.absent(),
|
||||
this.labelRu = const Value.absent(),
|
||||
this.icon = const Value.absent(),
|
||||
this.color = const Value.absent(),
|
||||
this.isDefault = const Value.absent(),
|
||||
@@ -1058,6 +1145,8 @@ class CategoriesCompanion extends UpdateCompanion<Category> {
|
||||
this.id = const Value.absent(),
|
||||
required String name,
|
||||
required String type,
|
||||
this.labelEn = const Value.absent(),
|
||||
this.labelRu = const Value.absent(),
|
||||
this.icon = const Value.absent(),
|
||||
this.color = const Value.absent(),
|
||||
this.isDefault = const Value.absent(),
|
||||
@@ -1068,6 +1157,8 @@ class CategoriesCompanion extends UpdateCompanion<Category> {
|
||||
Expression<int>? id,
|
||||
Expression<String>? name,
|
||||
Expression<String>? type,
|
||||
Expression<String>? labelEn,
|
||||
Expression<String>? labelRu,
|
||||
Expression<String>? icon,
|
||||
Expression<String>? color,
|
||||
Expression<bool>? isDefault,
|
||||
@@ -1077,6 +1168,8 @@ class CategoriesCompanion extends UpdateCompanion<Category> {
|
||||
if (id != null) 'id': id,
|
||||
if (name != null) 'name': name,
|
||||
if (type != null) 'type': type,
|
||||
if (labelEn != null) 'label_en': labelEn,
|
||||
if (labelRu != null) 'label_ru': labelRu,
|
||||
if (icon != null) 'icon': icon,
|
||||
if (color != null) 'color': color,
|
||||
if (isDefault != null) 'is_default': isDefault,
|
||||
@@ -1088,6 +1181,8 @@ class CategoriesCompanion extends UpdateCompanion<Category> {
|
||||
Value<int>? id,
|
||||
Value<String>? name,
|
||||
Value<String>? type,
|
||||
Value<String?>? labelEn,
|
||||
Value<String?>? labelRu,
|
||||
Value<String?>? icon,
|
||||
Value<String?>? color,
|
||||
Value<bool>? isDefault,
|
||||
@@ -1097,6 +1192,8 @@ class CategoriesCompanion extends UpdateCompanion<Category> {
|
||||
id: id ?? this.id,
|
||||
name: name ?? this.name,
|
||||
type: type ?? this.type,
|
||||
labelEn: labelEn ?? this.labelEn,
|
||||
labelRu: labelRu ?? this.labelRu,
|
||||
icon: icon ?? this.icon,
|
||||
color: color ?? this.color,
|
||||
isDefault: isDefault ?? this.isDefault,
|
||||
@@ -1116,6 +1213,12 @@ class CategoriesCompanion extends UpdateCompanion<Category> {
|
||||
if (type.present) {
|
||||
map['type'] = Variable<String>(type.value);
|
||||
}
|
||||
if (labelEn.present) {
|
||||
map['label_en'] = Variable<String>(labelEn.value);
|
||||
}
|
||||
if (labelRu.present) {
|
||||
map['label_ru'] = Variable<String>(labelRu.value);
|
||||
}
|
||||
if (icon.present) {
|
||||
map['icon'] = Variable<String>(icon.value);
|
||||
}
|
||||
@@ -1137,6 +1240,8 @@ class CategoriesCompanion extends UpdateCompanion<Category> {
|
||||
..write('id: $id, ')
|
||||
..write('name: $name, ')
|
||||
..write('type: $type, ')
|
||||
..write('labelEn: $labelEn, ')
|
||||
..write('labelRu: $labelRu, ')
|
||||
..write('icon: $icon, ')
|
||||
..write('color: $color, ')
|
||||
..write('isDefault: $isDefault, ')
|
||||
@@ -1146,400 +1251,6 @@ class CategoriesCompanion extends UpdateCompanion<Category> {
|
||||
}
|
||||
}
|
||||
|
||||
class $BudgetsTable extends Budgets with TableInfo<$BudgetsTable, Budget> {
|
||||
@override
|
||||
final GeneratedDatabase attachedDatabase;
|
||||
final String? _alias;
|
||||
$BudgetsTable(this.attachedDatabase, [this._alias]);
|
||||
static const VerificationMeta _idMeta = const VerificationMeta('id');
|
||||
@override
|
||||
late final GeneratedColumn<int> id = GeneratedColumn<int>(
|
||||
'id',
|
||||
aliasedName,
|
||||
false,
|
||||
hasAutoIncrement: true,
|
||||
type: DriftSqlType.int,
|
||||
requiredDuringInsert: false,
|
||||
defaultConstraints: GeneratedColumn.constraintIsAlways(
|
||||
'PRIMARY KEY AUTOINCREMENT',
|
||||
),
|
||||
);
|
||||
static const VerificationMeta _amountMeta = const VerificationMeta('amount');
|
||||
@override
|
||||
late final GeneratedColumn<double> amount = GeneratedColumn<double>(
|
||||
'amount',
|
||||
aliasedName,
|
||||
false,
|
||||
type: DriftSqlType.double,
|
||||
requiredDuringInsert: true,
|
||||
);
|
||||
static const VerificationMeta _categoryIdMeta = const VerificationMeta(
|
||||
'categoryId',
|
||||
);
|
||||
@override
|
||||
late final GeneratedColumn<String> categoryId = GeneratedColumn<String>(
|
||||
'category_id',
|
||||
aliasedName,
|
||||
true,
|
||||
type: DriftSqlType.string,
|
||||
requiredDuringInsert: false,
|
||||
);
|
||||
static const VerificationMeta _monthMeta = const VerificationMeta('month');
|
||||
@override
|
||||
late final GeneratedColumn<int> month = GeneratedColumn<int>(
|
||||
'month',
|
||||
aliasedName,
|
||||
false,
|
||||
type: DriftSqlType.int,
|
||||
requiredDuringInsert: true,
|
||||
);
|
||||
static const VerificationMeta _yearMeta = const VerificationMeta('year');
|
||||
@override
|
||||
late final GeneratedColumn<int> year = GeneratedColumn<int>(
|
||||
'year',
|
||||
aliasedName,
|
||||
false,
|
||||
type: DriftSqlType.int,
|
||||
requiredDuringInsert: true,
|
||||
);
|
||||
static const VerificationMeta _createdAtMeta = const VerificationMeta(
|
||||
'createdAt',
|
||||
);
|
||||
@override
|
||||
late final GeneratedColumn<DateTime> createdAt = GeneratedColumn<DateTime>(
|
||||
'created_at',
|
||||
aliasedName,
|
||||
false,
|
||||
type: DriftSqlType.dateTime,
|
||||
requiredDuringInsert: false,
|
||||
defaultValue: currentDateAndTime,
|
||||
);
|
||||
@override
|
||||
List<GeneratedColumn> get $columns => [
|
||||
id,
|
||||
amount,
|
||||
categoryId,
|
||||
month,
|
||||
year,
|
||||
createdAt,
|
||||
];
|
||||
@override
|
||||
String get aliasedName => _alias ?? actualTableName;
|
||||
@override
|
||||
String get actualTableName => $name;
|
||||
static const String $name = 'budgets';
|
||||
@override
|
||||
VerificationContext validateIntegrity(
|
||||
Insertable<Budget> instance, {
|
||||
bool isInserting = false,
|
||||
}) {
|
||||
final context = VerificationContext();
|
||||
final data = instance.toColumns(true);
|
||||
if (data.containsKey('id')) {
|
||||
context.handle(_idMeta, id.isAcceptableOrUnknown(data['id']!, _idMeta));
|
||||
}
|
||||
if (data.containsKey('amount')) {
|
||||
context.handle(
|
||||
_amountMeta,
|
||||
amount.isAcceptableOrUnknown(data['amount']!, _amountMeta),
|
||||
);
|
||||
} else if (isInserting) {
|
||||
context.missing(_amountMeta);
|
||||
}
|
||||
if (data.containsKey('category_id')) {
|
||||
context.handle(
|
||||
_categoryIdMeta,
|
||||
categoryId.isAcceptableOrUnknown(data['category_id']!, _categoryIdMeta),
|
||||
);
|
||||
}
|
||||
if (data.containsKey('month')) {
|
||||
context.handle(
|
||||
_monthMeta,
|
||||
month.isAcceptableOrUnknown(data['month']!, _monthMeta),
|
||||
);
|
||||
} else if (isInserting) {
|
||||
context.missing(_monthMeta);
|
||||
}
|
||||
if (data.containsKey('year')) {
|
||||
context.handle(
|
||||
_yearMeta,
|
||||
year.isAcceptableOrUnknown(data['year']!, _yearMeta),
|
||||
);
|
||||
} else if (isInserting) {
|
||||
context.missing(_yearMeta);
|
||||
}
|
||||
if (data.containsKey('created_at')) {
|
||||
context.handle(
|
||||
_createdAtMeta,
|
||||
createdAt.isAcceptableOrUnknown(data['created_at']!, _createdAtMeta),
|
||||
);
|
||||
}
|
||||
return context;
|
||||
}
|
||||
|
||||
@override
|
||||
Set<GeneratedColumn> get $primaryKey => {id};
|
||||
@override
|
||||
Budget map(Map<String, dynamic> data, {String? tablePrefix}) {
|
||||
final effectivePrefix = tablePrefix != null ? '$tablePrefix.' : '';
|
||||
return Budget(
|
||||
id: attachedDatabase.typeMapping.read(
|
||||
DriftSqlType.int,
|
||||
data['${effectivePrefix}id'],
|
||||
)!,
|
||||
amount: attachedDatabase.typeMapping.read(
|
||||
DriftSqlType.double,
|
||||
data['${effectivePrefix}amount'],
|
||||
)!,
|
||||
categoryId: attachedDatabase.typeMapping.read(
|
||||
DriftSqlType.string,
|
||||
data['${effectivePrefix}category_id'],
|
||||
),
|
||||
month: attachedDatabase.typeMapping.read(
|
||||
DriftSqlType.int,
|
||||
data['${effectivePrefix}month'],
|
||||
)!,
|
||||
year: attachedDatabase.typeMapping.read(
|
||||
DriftSqlType.int,
|
||||
data['${effectivePrefix}year'],
|
||||
)!,
|
||||
createdAt: attachedDatabase.typeMapping.read(
|
||||
DriftSqlType.dateTime,
|
||||
data['${effectivePrefix}created_at'],
|
||||
)!,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
$BudgetsTable createAlias(String alias) {
|
||||
return $BudgetsTable(attachedDatabase, alias);
|
||||
}
|
||||
}
|
||||
|
||||
class Budget extends DataClass implements Insertable<Budget> {
|
||||
final int id;
|
||||
final double amount;
|
||||
final String? categoryId;
|
||||
final int month;
|
||||
final int year;
|
||||
final DateTime createdAt;
|
||||
const Budget({
|
||||
required this.id,
|
||||
required this.amount,
|
||||
this.categoryId,
|
||||
required this.month,
|
||||
required this.year,
|
||||
required this.createdAt,
|
||||
});
|
||||
@override
|
||||
Map<String, Expression> toColumns(bool nullToAbsent) {
|
||||
final map = <String, Expression>{};
|
||||
map['id'] = Variable<int>(id);
|
||||
map['amount'] = Variable<double>(amount);
|
||||
if (!nullToAbsent || categoryId != null) {
|
||||
map['category_id'] = Variable<String>(categoryId);
|
||||
}
|
||||
map['month'] = Variable<int>(month);
|
||||
map['year'] = Variable<int>(year);
|
||||
map['created_at'] = Variable<DateTime>(createdAt);
|
||||
return map;
|
||||
}
|
||||
|
||||
BudgetsCompanion toCompanion(bool nullToAbsent) {
|
||||
return BudgetsCompanion(
|
||||
id: Value(id),
|
||||
amount: Value(amount),
|
||||
categoryId: categoryId == null && nullToAbsent
|
||||
? const Value.absent()
|
||||
: Value(categoryId),
|
||||
month: Value(month),
|
||||
year: Value(year),
|
||||
createdAt: Value(createdAt),
|
||||
);
|
||||
}
|
||||
|
||||
factory Budget.fromJson(
|
||||
Map<String, dynamic> json, {
|
||||
ValueSerializer? serializer,
|
||||
}) {
|
||||
serializer ??= driftRuntimeOptions.defaultSerializer;
|
||||
return Budget(
|
||||
id: serializer.fromJson<int>(json['id']),
|
||||
amount: serializer.fromJson<double>(json['amount']),
|
||||
categoryId: serializer.fromJson<String?>(json['categoryId']),
|
||||
month: serializer.fromJson<int>(json['month']),
|
||||
year: serializer.fromJson<int>(json['year']),
|
||||
createdAt: serializer.fromJson<DateTime>(json['createdAt']),
|
||||
);
|
||||
}
|
||||
@override
|
||||
Map<String, dynamic> toJson({ValueSerializer? serializer}) {
|
||||
serializer ??= driftRuntimeOptions.defaultSerializer;
|
||||
return <String, dynamic>{
|
||||
'id': serializer.toJson<int>(id),
|
||||
'amount': serializer.toJson<double>(amount),
|
||||
'categoryId': serializer.toJson<String?>(categoryId),
|
||||
'month': serializer.toJson<int>(month),
|
||||
'year': serializer.toJson<int>(year),
|
||||
'createdAt': serializer.toJson<DateTime>(createdAt),
|
||||
};
|
||||
}
|
||||
|
||||
Budget copyWith({
|
||||
int? id,
|
||||
double? amount,
|
||||
Value<String?> categoryId = const Value.absent(),
|
||||
int? month,
|
||||
int? year,
|
||||
DateTime? createdAt,
|
||||
}) => Budget(
|
||||
id: id ?? this.id,
|
||||
amount: amount ?? this.amount,
|
||||
categoryId: categoryId.present ? categoryId.value : this.categoryId,
|
||||
month: month ?? this.month,
|
||||
year: year ?? this.year,
|
||||
createdAt: createdAt ?? this.createdAt,
|
||||
);
|
||||
Budget copyWithCompanion(BudgetsCompanion data) {
|
||||
return Budget(
|
||||
id: data.id.present ? data.id.value : this.id,
|
||||
amount: data.amount.present ? data.amount.value : this.amount,
|
||||
categoryId: data.categoryId.present
|
||||
? data.categoryId.value
|
||||
: this.categoryId,
|
||||
month: data.month.present ? data.month.value : this.month,
|
||||
year: data.year.present ? data.year.value : this.year,
|
||||
createdAt: data.createdAt.present ? data.createdAt.value : this.createdAt,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return (StringBuffer('Budget(')
|
||||
..write('id: $id, ')
|
||||
..write('amount: $amount, ')
|
||||
..write('categoryId: $categoryId, ')
|
||||
..write('month: $month, ')
|
||||
..write('year: $year, ')
|
||||
..write('createdAt: $createdAt')
|
||||
..write(')'))
|
||||
.toString();
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode =>
|
||||
Object.hash(id, amount, categoryId, month, year, createdAt);
|
||||
@override
|
||||
bool operator ==(Object other) =>
|
||||
identical(this, other) ||
|
||||
(other is Budget &&
|
||||
other.id == this.id &&
|
||||
other.amount == this.amount &&
|
||||
other.categoryId == this.categoryId &&
|
||||
other.month == this.month &&
|
||||
other.year == this.year &&
|
||||
other.createdAt == this.createdAt);
|
||||
}
|
||||
|
||||
class BudgetsCompanion extends UpdateCompanion<Budget> {
|
||||
final Value<int> id;
|
||||
final Value<double> amount;
|
||||
final Value<String?> categoryId;
|
||||
final Value<int> month;
|
||||
final Value<int> year;
|
||||
final Value<DateTime> createdAt;
|
||||
const BudgetsCompanion({
|
||||
this.id = const Value.absent(),
|
||||
this.amount = const Value.absent(),
|
||||
this.categoryId = const Value.absent(),
|
||||
this.month = const Value.absent(),
|
||||
this.year = const Value.absent(),
|
||||
this.createdAt = const Value.absent(),
|
||||
});
|
||||
BudgetsCompanion.insert({
|
||||
this.id = const Value.absent(),
|
||||
required double amount,
|
||||
this.categoryId = const Value.absent(),
|
||||
required int month,
|
||||
required int year,
|
||||
this.createdAt = const Value.absent(),
|
||||
}) : amount = Value(amount),
|
||||
month = Value(month),
|
||||
year = Value(year);
|
||||
static Insertable<Budget> custom({
|
||||
Expression<int>? id,
|
||||
Expression<double>? amount,
|
||||
Expression<String>? categoryId,
|
||||
Expression<int>? month,
|
||||
Expression<int>? year,
|
||||
Expression<DateTime>? createdAt,
|
||||
}) {
|
||||
return RawValuesInsertable({
|
||||
if (id != null) 'id': id,
|
||||
if (amount != null) 'amount': amount,
|
||||
if (categoryId != null) 'category_id': categoryId,
|
||||
if (month != null) 'month': month,
|
||||
if (year != null) 'year': year,
|
||||
if (createdAt != null) 'created_at': createdAt,
|
||||
});
|
||||
}
|
||||
|
||||
BudgetsCompanion copyWith({
|
||||
Value<int>? id,
|
||||
Value<double>? amount,
|
||||
Value<String?>? categoryId,
|
||||
Value<int>? month,
|
||||
Value<int>? year,
|
||||
Value<DateTime>? createdAt,
|
||||
}) {
|
||||
return BudgetsCompanion(
|
||||
id: id ?? this.id,
|
||||
amount: amount ?? this.amount,
|
||||
categoryId: categoryId ?? this.categoryId,
|
||||
month: month ?? this.month,
|
||||
year: year ?? this.year,
|
||||
createdAt: createdAt ?? this.createdAt,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Map<String, Expression> toColumns(bool nullToAbsent) {
|
||||
final map = <String, Expression>{};
|
||||
if (id.present) {
|
||||
map['id'] = Variable<int>(id.value);
|
||||
}
|
||||
if (amount.present) {
|
||||
map['amount'] = Variable<double>(amount.value);
|
||||
}
|
||||
if (categoryId.present) {
|
||||
map['category_id'] = Variable<String>(categoryId.value);
|
||||
}
|
||||
if (month.present) {
|
||||
map['month'] = Variable<int>(month.value);
|
||||
}
|
||||
if (year.present) {
|
||||
map['year'] = Variable<int>(year.value);
|
||||
}
|
||||
if (createdAt.present) {
|
||||
map['created_at'] = Variable<DateTime>(createdAt.value);
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return (StringBuffer('BudgetsCompanion(')
|
||||
..write('id: $id, ')
|
||||
..write('amount: $amount, ')
|
||||
..write('categoryId: $categoryId, ')
|
||||
..write('month: $month, ')
|
||||
..write('year: $year, ')
|
||||
..write('createdAt: $createdAt')
|
||||
..write(')'))
|
||||
.toString();
|
||||
}
|
||||
}
|
||||
|
||||
class $ExchangeRatesTable extends ExchangeRates
|
||||
with TableInfo<$ExchangeRatesTable, ExchangeRate> {
|
||||
@override
|
||||
@@ -2291,7 +2002,6 @@ abstract class _$AppDatabase extends GeneratedDatabase {
|
||||
$AppDatabaseManager get managers => $AppDatabaseManager(this);
|
||||
late final $TransactionsTable transactions = $TransactionsTable(this);
|
||||
late final $CategoriesTable categories = $CategoriesTable(this);
|
||||
late final $BudgetsTable budgets = $BudgetsTable(this);
|
||||
late final $ExchangeRatesTable exchangeRates = $ExchangeRatesTable(this);
|
||||
late final $AccountsTable accounts = $AccountsTable(this);
|
||||
@override
|
||||
@@ -2301,7 +2011,6 @@ abstract class _$AppDatabase extends GeneratedDatabase {
|
||||
List<DatabaseSchemaEntity> get allSchemaEntities => [
|
||||
transactions,
|
||||
categories,
|
||||
budgets,
|
||||
exchangeRates,
|
||||
accounts,
|
||||
];
|
||||
@@ -2654,6 +2363,8 @@ typedef $$CategoriesTableCreateCompanionBuilder =
|
||||
Value<int> id,
|
||||
required String name,
|
||||
required String type,
|
||||
Value<String?> labelEn,
|
||||
Value<String?> labelRu,
|
||||
Value<String?> icon,
|
||||
Value<String?> color,
|
||||
Value<bool> isDefault,
|
||||
@@ -2664,6 +2375,8 @@ typedef $$CategoriesTableUpdateCompanionBuilder =
|
||||
Value<int> id,
|
||||
Value<String> name,
|
||||
Value<String> type,
|
||||
Value<String?> labelEn,
|
||||
Value<String?> labelRu,
|
||||
Value<String?> icon,
|
||||
Value<String?> color,
|
||||
Value<bool> isDefault,
|
||||
@@ -2694,6 +2407,16 @@ class $$CategoriesTableFilterComposer
|
||||
builder: (column) => ColumnFilters(column),
|
||||
);
|
||||
|
||||
ColumnFilters<String> get labelEn => $composableBuilder(
|
||||
column: $table.labelEn,
|
||||
builder: (column) => ColumnFilters(column),
|
||||
);
|
||||
|
||||
ColumnFilters<String> get labelRu => $composableBuilder(
|
||||
column: $table.labelRu,
|
||||
builder: (column) => ColumnFilters(column),
|
||||
);
|
||||
|
||||
ColumnFilters<String> get icon => $composableBuilder(
|
||||
column: $table.icon,
|
||||
builder: (column) => ColumnFilters(column),
|
||||
@@ -2739,6 +2462,16 @@ class $$CategoriesTableOrderingComposer
|
||||
builder: (column) => ColumnOrderings(column),
|
||||
);
|
||||
|
||||
ColumnOrderings<String> get labelEn => $composableBuilder(
|
||||
column: $table.labelEn,
|
||||
builder: (column) => ColumnOrderings(column),
|
||||
);
|
||||
|
||||
ColumnOrderings<String> get labelRu => $composableBuilder(
|
||||
column: $table.labelRu,
|
||||
builder: (column) => ColumnOrderings(column),
|
||||
);
|
||||
|
||||
ColumnOrderings<String> get icon => $composableBuilder(
|
||||
column: $table.icon,
|
||||
builder: (column) => ColumnOrderings(column),
|
||||
@@ -2778,6 +2511,12 @@ class $$CategoriesTableAnnotationComposer
|
||||
GeneratedColumn<String> get type =>
|
||||
$composableBuilder(column: $table.type, builder: (column) => column);
|
||||
|
||||
GeneratedColumn<String> get labelEn =>
|
||||
$composableBuilder(column: $table.labelEn, builder: (column) => column);
|
||||
|
||||
GeneratedColumn<String> get labelRu =>
|
||||
$composableBuilder(column: $table.labelRu, builder: (column) => column);
|
||||
|
||||
GeneratedColumn<String> get icon =>
|
||||
$composableBuilder(column: $table.icon, builder: (column) => column);
|
||||
|
||||
@@ -2822,6 +2561,8 @@ class $$CategoriesTableTableManager
|
||||
Value<int> id = const Value.absent(),
|
||||
Value<String> name = const Value.absent(),
|
||||
Value<String> type = const Value.absent(),
|
||||
Value<String?> labelEn = const Value.absent(),
|
||||
Value<String?> labelRu = const Value.absent(),
|
||||
Value<String?> icon = const Value.absent(),
|
||||
Value<String?> color = const Value.absent(),
|
||||
Value<bool> isDefault = const Value.absent(),
|
||||
@@ -2830,6 +2571,8 @@ class $$CategoriesTableTableManager
|
||||
id: id,
|
||||
name: name,
|
||||
type: type,
|
||||
labelEn: labelEn,
|
||||
labelRu: labelRu,
|
||||
icon: icon,
|
||||
color: color,
|
||||
isDefault: isDefault,
|
||||
@@ -2840,6 +2583,8 @@ class $$CategoriesTableTableManager
|
||||
Value<int> id = const Value.absent(),
|
||||
required String name,
|
||||
required String type,
|
||||
Value<String?> labelEn = const Value.absent(),
|
||||
Value<String?> labelRu = const Value.absent(),
|
||||
Value<String?> icon = const Value.absent(),
|
||||
Value<String?> color = const Value.absent(),
|
||||
Value<bool> isDefault = const Value.absent(),
|
||||
@@ -2848,6 +2593,8 @@ class $$CategoriesTableTableManager
|
||||
id: id,
|
||||
name: name,
|
||||
type: type,
|
||||
labelEn: labelEn,
|
||||
labelRu: labelRu,
|
||||
icon: icon,
|
||||
color: color,
|
||||
isDefault: isDefault,
|
||||
@@ -2875,215 +2622,6 @@ typedef $$CategoriesTableProcessedTableManager =
|
||||
Category,
|
||||
PrefetchHooks Function()
|
||||
>;
|
||||
typedef $$BudgetsTableCreateCompanionBuilder =
|
||||
BudgetsCompanion Function({
|
||||
Value<int> id,
|
||||
required double amount,
|
||||
Value<String?> categoryId,
|
||||
required int month,
|
||||
required int year,
|
||||
Value<DateTime> createdAt,
|
||||
});
|
||||
typedef $$BudgetsTableUpdateCompanionBuilder =
|
||||
BudgetsCompanion Function({
|
||||
Value<int> id,
|
||||
Value<double> amount,
|
||||
Value<String?> categoryId,
|
||||
Value<int> month,
|
||||
Value<int> year,
|
||||
Value<DateTime> createdAt,
|
||||
});
|
||||
|
||||
class $$BudgetsTableFilterComposer
|
||||
extends Composer<_$AppDatabase, $BudgetsTable> {
|
||||
$$BudgetsTableFilterComposer({
|
||||
required super.$db,
|
||||
required super.$table,
|
||||
super.joinBuilder,
|
||||
super.$addJoinBuilderToRootComposer,
|
||||
super.$removeJoinBuilderFromRootComposer,
|
||||
});
|
||||
ColumnFilters<int> get id => $composableBuilder(
|
||||
column: $table.id,
|
||||
builder: (column) => ColumnFilters(column),
|
||||
);
|
||||
|
||||
ColumnFilters<double> get amount => $composableBuilder(
|
||||
column: $table.amount,
|
||||
builder: (column) => ColumnFilters(column),
|
||||
);
|
||||
|
||||
ColumnFilters<String> get categoryId => $composableBuilder(
|
||||
column: $table.categoryId,
|
||||
builder: (column) => ColumnFilters(column),
|
||||
);
|
||||
|
||||
ColumnFilters<int> get month => $composableBuilder(
|
||||
column: $table.month,
|
||||
builder: (column) => ColumnFilters(column),
|
||||
);
|
||||
|
||||
ColumnFilters<int> get year => $composableBuilder(
|
||||
column: $table.year,
|
||||
builder: (column) => ColumnFilters(column),
|
||||
);
|
||||
|
||||
ColumnFilters<DateTime> get createdAt => $composableBuilder(
|
||||
column: $table.createdAt,
|
||||
builder: (column) => ColumnFilters(column),
|
||||
);
|
||||
}
|
||||
|
||||
class $$BudgetsTableOrderingComposer
|
||||
extends Composer<_$AppDatabase, $BudgetsTable> {
|
||||
$$BudgetsTableOrderingComposer({
|
||||
required super.$db,
|
||||
required super.$table,
|
||||
super.joinBuilder,
|
||||
super.$addJoinBuilderToRootComposer,
|
||||
super.$removeJoinBuilderFromRootComposer,
|
||||
});
|
||||
ColumnOrderings<int> get id => $composableBuilder(
|
||||
column: $table.id,
|
||||
builder: (column) => ColumnOrderings(column),
|
||||
);
|
||||
|
||||
ColumnOrderings<double> get amount => $composableBuilder(
|
||||
column: $table.amount,
|
||||
builder: (column) => ColumnOrderings(column),
|
||||
);
|
||||
|
||||
ColumnOrderings<String> get categoryId => $composableBuilder(
|
||||
column: $table.categoryId,
|
||||
builder: (column) => ColumnOrderings(column),
|
||||
);
|
||||
|
||||
ColumnOrderings<int> get month => $composableBuilder(
|
||||
column: $table.month,
|
||||
builder: (column) => ColumnOrderings(column),
|
||||
);
|
||||
|
||||
ColumnOrderings<int> get year => $composableBuilder(
|
||||
column: $table.year,
|
||||
builder: (column) => ColumnOrderings(column),
|
||||
);
|
||||
|
||||
ColumnOrderings<DateTime> get createdAt => $composableBuilder(
|
||||
column: $table.createdAt,
|
||||
builder: (column) => ColumnOrderings(column),
|
||||
);
|
||||
}
|
||||
|
||||
class $$BudgetsTableAnnotationComposer
|
||||
extends Composer<_$AppDatabase, $BudgetsTable> {
|
||||
$$BudgetsTableAnnotationComposer({
|
||||
required super.$db,
|
||||
required super.$table,
|
||||
super.joinBuilder,
|
||||
super.$addJoinBuilderToRootComposer,
|
||||
super.$removeJoinBuilderFromRootComposer,
|
||||
});
|
||||
GeneratedColumn<int> get id =>
|
||||
$composableBuilder(column: $table.id, builder: (column) => column);
|
||||
|
||||
GeneratedColumn<double> get amount =>
|
||||
$composableBuilder(column: $table.amount, builder: (column) => column);
|
||||
|
||||
GeneratedColumn<String> get categoryId => $composableBuilder(
|
||||
column: $table.categoryId,
|
||||
builder: (column) => column,
|
||||
);
|
||||
|
||||
GeneratedColumn<int> get month =>
|
||||
$composableBuilder(column: $table.month, builder: (column) => column);
|
||||
|
||||
GeneratedColumn<int> get year =>
|
||||
$composableBuilder(column: $table.year, builder: (column) => column);
|
||||
|
||||
GeneratedColumn<DateTime> get createdAt =>
|
||||
$composableBuilder(column: $table.createdAt, builder: (column) => column);
|
||||
}
|
||||
|
||||
class $$BudgetsTableTableManager
|
||||
extends
|
||||
RootTableManager<
|
||||
_$AppDatabase,
|
||||
$BudgetsTable,
|
||||
Budget,
|
||||
$$BudgetsTableFilterComposer,
|
||||
$$BudgetsTableOrderingComposer,
|
||||
$$BudgetsTableAnnotationComposer,
|
||||
$$BudgetsTableCreateCompanionBuilder,
|
||||
$$BudgetsTableUpdateCompanionBuilder,
|
||||
(Budget, BaseReferences<_$AppDatabase, $BudgetsTable, Budget>),
|
||||
Budget,
|
||||
PrefetchHooks Function()
|
||||
> {
|
||||
$$BudgetsTableTableManager(_$AppDatabase db, $BudgetsTable table)
|
||||
: super(
|
||||
TableManagerState(
|
||||
db: db,
|
||||
table: table,
|
||||
createFilteringComposer: () =>
|
||||
$$BudgetsTableFilterComposer($db: db, $table: table),
|
||||
createOrderingComposer: () =>
|
||||
$$BudgetsTableOrderingComposer($db: db, $table: table),
|
||||
createComputedFieldComposer: () =>
|
||||
$$BudgetsTableAnnotationComposer($db: db, $table: table),
|
||||
updateCompanionCallback:
|
||||
({
|
||||
Value<int> id = const Value.absent(),
|
||||
Value<double> amount = const Value.absent(),
|
||||
Value<String?> categoryId = const Value.absent(),
|
||||
Value<int> month = const Value.absent(),
|
||||
Value<int> year = const Value.absent(),
|
||||
Value<DateTime> createdAt = const Value.absent(),
|
||||
}) => BudgetsCompanion(
|
||||
id: id,
|
||||
amount: amount,
|
||||
categoryId: categoryId,
|
||||
month: month,
|
||||
year: year,
|
||||
createdAt: createdAt,
|
||||
),
|
||||
createCompanionCallback:
|
||||
({
|
||||
Value<int> id = const Value.absent(),
|
||||
required double amount,
|
||||
Value<String?> categoryId = const Value.absent(),
|
||||
required int month,
|
||||
required int year,
|
||||
Value<DateTime> createdAt = const Value.absent(),
|
||||
}) => BudgetsCompanion.insert(
|
||||
id: id,
|
||||
amount: amount,
|
||||
categoryId: categoryId,
|
||||
month: month,
|
||||
year: year,
|
||||
createdAt: createdAt,
|
||||
),
|
||||
withReferenceMapper: (p0) => p0
|
||||
.map((e) => (e.readTable(table), BaseReferences(db, table, e)))
|
||||
.toList(),
|
||||
prefetchHooksCallback: null,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
typedef $$BudgetsTableProcessedTableManager =
|
||||
ProcessedTableManager<
|
||||
_$AppDatabase,
|
||||
$BudgetsTable,
|
||||
Budget,
|
||||
$$BudgetsTableFilterComposer,
|
||||
$$BudgetsTableOrderingComposer,
|
||||
$$BudgetsTableAnnotationComposer,
|
||||
$$BudgetsTableCreateCompanionBuilder,
|
||||
$$BudgetsTableUpdateCompanionBuilder,
|
||||
(Budget, BaseReferences<_$AppDatabase, $BudgetsTable, Budget>),
|
||||
Budget,
|
||||
PrefetchHooks Function()
|
||||
>;
|
||||
typedef $$ExchangeRatesTableCreateCompanionBuilder =
|
||||
ExchangeRatesCompanion Function({
|
||||
Value<int> id,
|
||||
@@ -3497,8 +3035,6 @@ class $AppDatabaseManager {
|
||||
$$TransactionsTableTableManager(_db, _db.transactions);
|
||||
$$CategoriesTableTableManager get categories =>
|
||||
$$CategoriesTableTableManager(_db, _db.categories);
|
||||
$$BudgetsTableTableManager get budgets =>
|
||||
$$BudgetsTableTableManager(_db, _db.budgets);
|
||||
$$ExchangeRatesTableTableManager get exchangeRates =>
|
||||
$$ExchangeRatesTableTableManager(_db, _db.exchangeRates);
|
||||
$$AccountsTableTableManager get accounts =>
|
||||
|
||||
@@ -21,22 +21,15 @@ class Transactions extends Table {
|
||||
class Categories extends Table {
|
||||
IntColumn get id => integer().autoIncrement()();
|
||||
TextColumn get name => text().withLength(min: 1, max: 50)();
|
||||
TextColumn get type => text()();
|
||||
TextColumn get type => text()();
|
||||
TextColumn get labelEn => text().nullable()();
|
||||
TextColumn get labelRu => text().nullable()();
|
||||
TextColumn get icon => text().nullable()();
|
||||
TextColumn get color => text().nullable()();
|
||||
BoolColumn get isDefault => boolean().withDefault(const Constant(false))();
|
||||
DateTimeColumn get createdAt => dateTime().withDefault(currentDateAndTime)();
|
||||
}
|
||||
|
||||
class Budgets extends Table {
|
||||
IntColumn get id => integer().autoIncrement()();
|
||||
RealColumn get amount => real()();
|
||||
TextColumn get categoryId => text().nullable()();
|
||||
IntColumn get month => integer()();
|
||||
IntColumn get year => integer()();
|
||||
DateTimeColumn get createdAt => dateTime().withDefault(currentDateAndTime)();
|
||||
}
|
||||
|
||||
class ExchangeRates extends Table {
|
||||
IntColumn get id => integer().autoIncrement()();
|
||||
TextColumn get fromCurrency => text()();
|
||||
|
||||
@@ -1,19 +1,21 @@
|
||||
import 'package:drift/drift.dart';
|
||||
import '../database/app_database.dart';
|
||||
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;
|
||||
AccountLimitException(this.message);
|
||||
FeatureLimitException(this.message);
|
||||
|
||||
@override
|
||||
String toString() => 'AccountLimitException: $message';
|
||||
String toString() => 'FeatureLimitException: $message';
|
||||
}
|
||||
|
||||
class AccountRepository {
|
||||
final AppDatabase _db;
|
||||
final FeatureFlags Function() _getFeatureFlags;
|
||||
|
||||
AccountRepository(this._db);
|
||||
AccountRepository(this._db, this._getFeatureFlags);
|
||||
|
||||
Stream<List<model.Account>> watchAll() {
|
||||
return (_db.select(_db.accounts)
|
||||
@@ -163,6 +165,12 @@ class AccountRepository {
|
||||
}
|
||||
|
||||
Future<int> add(model.Account account) async {
|
||||
final existing = await getAll();
|
||||
final nonMainCount = existing.where((a) => !a.isMain).length;
|
||||
final flags = _getFeatureFlags();
|
||||
if (flags.maxAccounts != -1 && nonMainCount >= flags.maxAccounts) {
|
||||
throw FeatureLimitException('Account limit reached (${flags.maxAccounts})');
|
||||
}
|
||||
return await _db.into(_db.accounts).insert(
|
||||
AccountsCompanion.insert(
|
||||
name: account.name,
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
import 'package:drift/drift.dart';
|
||||
import '../database/app_database.dart';
|
||||
|
||||
class CategoryRepository {
|
||||
final AppDatabase _db;
|
||||
|
||||
CategoryRepository(this._db);
|
||||
|
||||
Stream<List<Category>> watchAll() {
|
||||
return _db.watchAllCategories();
|
||||
}
|
||||
|
||||
Future<List<Category>> getAll() {
|
||||
return _db.getAllCategories();
|
||||
}
|
||||
|
||||
Future<int> add({
|
||||
required String name,
|
||||
required String type,
|
||||
required String labelEn,
|
||||
required String labelRu,
|
||||
required String iconName,
|
||||
required int colorValue,
|
||||
}) {
|
||||
return _db.insertCategory(
|
||||
CategoriesCompanion.insert(
|
||||
name: name,
|
||||
type: type,
|
||||
labelEn: Value(labelEn),
|
||||
labelRu: Value(labelRu),
|
||||
icon: Value(iconName),
|
||||
color: Value(colorValue.toString()),
|
||||
isDefault: const Value(false),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> updateFields(
|
||||
int id, {
|
||||
required String type,
|
||||
required String labelEn,
|
||||
required String labelRu,
|
||||
required String iconName,
|
||||
required int colorValue,
|
||||
}) {
|
||||
return (_db.update(_db.categories)..where((c) => c.id.equals(id))).write(
|
||||
CategoriesCompanion(
|
||||
type: Value(type),
|
||||
labelEn: Value(labelEn),
|
||||
labelRu: Value(labelRu),
|
||||
icon: Value(iconName),
|
||||
color: Value(colorValue.toString()),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<int> delete(int id) {
|
||||
return _db.deleteCategory(id);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import '../../core/constants.dart';
|
||||
import '../../shared/models/app_category.dart';
|
||||
import '../../shared/models/transaction.dart';
|
||||
import '../../shared/providers/category_provider.dart';
|
||||
|
||||
class AddTransactionState {
|
||||
final double? amount;
|
||||
@@ -133,10 +135,11 @@ class AddTransactionNotifier extends Notifier<AddTransactionState> {
|
||||
}
|
||||
|
||||
final availableCategoriesProvider = Provider.autoDispose
|
||||
.family<List<String>, Transaction?>((ref, initial) {
|
||||
.family<List<AppCategory>, Transaction?>((ref, initial) {
|
||||
final type = ref.watch(
|
||||
addTransactionProvider(initial).select((s) => s.type),
|
||||
);
|
||||
return AppCategories.forType(type);
|
||||
if (type == TransactionType.transfer) return const [];
|
||||
return ref.watch(categoryCatalogProvider).forType(type);
|
||||
});
|
||||
|
||||
|
||||
@@ -391,12 +391,12 @@ class _AddTransactionScreenState extends ConsumerState<AddTransactionScreen>
|
||||
data: Theme.of(context).copyWith(
|
||||
colorScheme: Theme.of(
|
||||
context,
|
||||
).colorScheme.copyWith(primary: AppColors.accent),
|
||||
).colorScheme.copyWith(primary: const Color(0xFF7C6DED)),
|
||||
),
|
||||
child: child!,
|
||||
),
|
||||
);
|
||||
if (picked != null) {
|
||||
if (picked != null && mounted) {
|
||||
setState(() => _selectedDate = picked);
|
||||
}
|
||||
}
|
||||
@@ -423,7 +423,7 @@ class _AddTransactionScreenState extends ConsumerState<AddTransactionScreen>
|
||||
child: child!,
|
||||
),
|
||||
);
|
||||
if (picked != null) {
|
||||
if (picked != null && mounted) {
|
||||
setState(() => _selectedTime = picked);
|
||||
}
|
||||
}
|
||||
@@ -995,7 +995,7 @@ class _ToAccountDropdownOverlay extends ConsumerWidget {
|
||||
const Icon(
|
||||
Icons.check_rounded,
|
||||
size: 16,
|
||||
color: Color(0xFF7C6DED),
|
||||
color: const Color(0xFF7C6DED),
|
||||
),
|
||||
],
|
||||
],
|
||||
|
||||
@@ -27,6 +27,9 @@ class AccountSelector extends ConsumerWidget {
|
||||
|
||||
return accountsAsync.when(
|
||||
data: (accounts) {
|
||||
if (accounts.isEmpty) {
|
||||
return const SizedBox.shrink();
|
||||
}
|
||||
final txAccountId = ref
|
||||
.read(addTransactionProvider(initial))
|
||||
.selectedAccountId;
|
||||
@@ -70,7 +73,7 @@ class AccountSelector extends ConsumerWidget {
|
||||
const Icon(
|
||||
Icons.account_balance_wallet_rounded,
|
||||
size: 18,
|
||||
color: Color(0xFF7C6DED),
|
||||
color: const Color(0xFF7C6DED),
|
||||
),
|
||||
const SizedBox(width: 10),
|
||||
Flexible(
|
||||
@@ -241,7 +244,7 @@ class AccountDropdownOverlay extends ConsumerWidget {
|
||||
const Icon(
|
||||
Icons.check_rounded,
|
||||
size: 16,
|
||||
color: Color(0xFF7C6DED),
|
||||
color: const Color(0xFF7C6DED),
|
||||
),
|
||||
],
|
||||
],
|
||||
|
||||
@@ -1,10 +1,14 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import '../../../core/constants.dart';
|
||||
import '../../../core/l10n/app_strings.dart';
|
||||
import '../../../core/l10n/locale_provider.dart';
|
||||
import '../../../core/services/haptic_service.dart';
|
||||
import '../../../shared/models/app_category.dart';
|
||||
|
||||
class CategoryPicker extends ConsumerWidget {
|
||||
final List<String> categories;
|
||||
final List<AppCategory> categories;
|
||||
final String selected;
|
||||
final ValueChanged<String> onChanged;
|
||||
|
||||
@@ -18,61 +22,111 @@ class CategoryPicker extends ConsumerWidget {
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final s = ref.watch(stringsProvider);
|
||||
final isRu = s.locale == AppLocale.ru;
|
||||
final isDark = Theme.of(context).brightness == Brightness.dark;
|
||||
return Wrap(
|
||||
spacing: 8,
|
||||
runSpacing: 8,
|
||||
children: categories.map((cat) {
|
||||
final isSelected = cat == selected;
|
||||
final color = AppCategories.colors[cat] ?? AppColors.accent;
|
||||
final icon = AppCategories.icons[cat] ?? Icons.category_rounded;
|
||||
return GestureDetector(
|
||||
onTap: () => onChanged(cat),
|
||||
child: AnimatedContainer(
|
||||
duration: const Duration(milliseconds: 200),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 10),
|
||||
decoration: BoxDecoration(
|
||||
color: isSelected
|
||||
? color.withOpacity(0.2)
|
||||
: Theme.of(context).colorScheme.surface,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
border: isSelected
|
||||
? Border.all(color: color, width: 1.5)
|
||||
: (isDark
|
||||
? null
|
||||
: Border.all(color: const Color(0xFFDDDDEE), width: 1)),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(
|
||||
icon,
|
||||
color: isSelected
|
||||
? color
|
||||
: Theme.of(
|
||||
context,
|
||||
).colorScheme.onSurface.withOpacity(0.6),
|
||||
size: 16,
|
||||
),
|
||||
const SizedBox(width: 6),
|
||||
Text(
|
||||
s.categoryLabel(cat),
|
||||
style: Theme.of(context).textTheme.bodySmall?.copyWith(
|
||||
children: [
|
||||
...categories.map((cat) {
|
||||
final isSelected = cat.key == selected;
|
||||
final color = cat.color;
|
||||
return GestureDetector(
|
||||
onTap: () {
|
||||
HapticService.light();
|
||||
onChanged(cat.key);
|
||||
},
|
||||
child: AnimatedContainer(
|
||||
duration: const Duration(milliseconds: 200),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 10),
|
||||
decoration: BoxDecoration(
|
||||
color: isSelected
|
||||
? color.withOpacity(0.2)
|
||||
: Theme.of(context).colorScheme.surface,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
border: isSelected
|
||||
? Border.all(color: color, width: 1.5)
|
||||
: (isDark
|
||||
? null
|
||||
: Border.all(
|
||||
color: const Color(0xFFDDDDEE), width: 1)),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(
|
||||
cat.icon,
|
||||
color: isSelected
|
||||
? color
|
||||
: Theme.of(
|
||||
context,
|
||||
).colorScheme.onSurface.withOpacity(0.6),
|
||||
fontWeight: isSelected
|
||||
? FontWeight.w600
|
||||
: FontWeight.normal,
|
||||
size: 16,
|
||||
),
|
||||
),
|
||||
],
|
||||
const SizedBox(width: 6),
|
||||
Flexible(
|
||||
child: Text(
|
||||
cat.label(isRu),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: Theme.of(context).textTheme.bodySmall?.copyWith(
|
||||
color: isSelected
|
||||
? color
|
||||
: Theme.of(context).colorScheme.onSurface.withOpacity(0.6),
|
||||
fontWeight: isSelected
|
||||
? FontWeight.w600
|
||||
: FontWeight.normal,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}).toList(),
|
||||
);
|
||||
}),
|
||||
_AddCategoryChip(label: s.addCategory),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _AddCategoryChip extends StatelessWidget {
|
||||
final String label;
|
||||
|
||||
const _AddCategoryChip({required this.label});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return GestureDetector(
|
||||
onTap: () {
|
||||
HapticService.light();
|
||||
context.push('/settings/categories');
|
||||
},
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 10),
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0xFF7C6DED).withOpacity(0.12),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
border: Border.all(
|
||||
color: const Color(0xFF7C6DED).withOpacity(0.5),
|
||||
width: 1,
|
||||
),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
const Icon(Icons.add_rounded, color: const Color(0xFF7C6DED), size: 16),
|
||||
const SizedBox(width: 6),
|
||||
Text(
|
||||
label,
|
||||
style: Theme.of(context).textTheme.bodySmall?.copyWith(
|
||||
color: const Color(0xFF7C6DED),
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ class NoteField extends StatelessWidget {
|
||||
),
|
||||
focusedBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
borderSide: const BorderSide(color: Color(0xFF7C6DED), width: 1.5),
|
||||
borderSide: BorderSide(color: const Color(0xFF7C6DED), width: 1.5),
|
||||
),
|
||||
),
|
||||
onChanged: onChanged,
|
||||
|
||||
@@ -1,44 +1,227 @@
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import '../../shared/models/account.dart';
|
||||
import '../../shared/models/transaction.dart';
|
||||
import '../dashboard/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 {
|
||||
final double income;
|
||||
final double expense;
|
||||
final double balance;
|
||||
final int transactionCount;
|
||||
final double averageIncome;
|
||||
final double averageExpense;
|
||||
|
||||
const StatsSummary({
|
||||
required this.income,
|
||||
required this.expense,
|
||||
required this.balance,
|
||||
required this.transactionCount,
|
||||
required this.averageIncome,
|
||||
required this.averageExpense,
|
||||
});
|
||||
}
|
||||
|
||||
String _resolveTargetCurrency(
|
||||
int activeIndex,
|
||||
List<Account> accounts,
|
||||
String globalCurrency,
|
||||
) {
|
||||
if (activeIndex > 0 && activeIndex <= accounts.length) {
|
||||
return accounts[activeIndex - 1].currency;
|
||||
}
|
||||
return globalCurrency;
|
||||
}
|
||||
|
||||
List<Transaction> _filterScopedTransactions(
|
||||
List<Transaction> txs,
|
||||
StatsTimeFilter timeFilter,
|
||||
) {
|
||||
var filtered = txs.where((t) => t.category != 'Transfer');
|
||||
if (timeFilter == StatsTimeFilter.month) {
|
||||
final now = DateTime.now();
|
||||
filtered = filtered.where(
|
||||
(t) => t.date.year == now.year && t.date.month == now.month,
|
||||
);
|
||||
}
|
||||
return filtered.toList();
|
||||
}
|
||||
|
||||
final statsCurrencyProvider = Provider<CurrencyInfo>((ref) {
|
||||
final index = ref.watch(activeAccountIndexProvider);
|
||||
final accountsAsync = ref.watch(accountsProvider);
|
||||
final globalCurrency = ref.watch(currencyProvider).code;
|
||||
final accounts = accountsAsync.value ?? [];
|
||||
final code = _resolveTargetCurrency(index, accounts, globalCurrency);
|
||||
return CurrencyInfo(currencyMap[code]?.symbol ?? '\$', code);
|
||||
});
|
||||
|
||||
final statsScopedTransactionsProvider = Provider<List<Transaction>>((ref) {
|
||||
final txs = ref.watch(accountFilteredTransactionsProvider);
|
||||
final timeFilter = ref.watch(statsTimeFilterProvider);
|
||||
return _filterScopedTransactions(txs, timeFilter);
|
||||
});
|
||||
|
||||
final statsIncomeTotalProvider = Provider<double>((ref) {
|
||||
final exchange = ref.watch(exchangeRateServiceProvider);
|
||||
final index = ref.watch(activeAccountIndexProvider);
|
||||
final accountsAsync = ref.watch(accountsProvider);
|
||||
final globalCurrency = ref.watch(currencyProvider).code;
|
||||
final accounts = accountsAsync.value ?? [];
|
||||
final target = _resolveTargetCurrency(index, accounts, globalCurrency);
|
||||
return ref
|
||||
.watch(statsScopedTransactionsProvider)
|
||||
.where((t) => t.type == TransactionType.income)
|
||||
.fold(0.0, (sum, t) => sum + exchange.convert(t.amount, t.currencyCode, target));
|
||||
});
|
||||
|
||||
final statsExpenseTotalProvider = Provider<double>((ref) {
|
||||
final exchange = ref.watch(exchangeRateServiceProvider);
|
||||
final index = ref.watch(activeAccountIndexProvider);
|
||||
final accountsAsync = ref.watch(accountsProvider);
|
||||
final globalCurrency = ref.watch(currencyProvider).code;
|
||||
final accounts = accountsAsync.value ?? [];
|
||||
final target = _resolveTargetCurrency(index, accounts, globalCurrency);
|
||||
return ref
|
||||
.watch(statsScopedTransactionsProvider)
|
||||
.where((t) => t.type == TransactionType.expense)
|
||||
.fold(0.0, (sum, t) => sum + exchange.convert(t.amount, t.currencyCode, target));
|
||||
});
|
||||
|
||||
final statsSummaryProvider = Provider<StatsSummary>((ref) {
|
||||
final exchange = ref.watch(exchangeRateServiceProvider);
|
||||
final index = ref.watch(activeAccountIndexProvider);
|
||||
final accountsAsync = ref.watch(accountsProvider);
|
||||
final globalCurrency = ref.watch(currencyProvider).code;
|
||||
final accounts = accountsAsync.value ?? [];
|
||||
final target = _resolveTargetCurrency(index, accounts, globalCurrency);
|
||||
final transactions = ref.watch(statsScopedTransactionsProvider);
|
||||
|
||||
var income = 0.0;
|
||||
var expense = 0.0;
|
||||
var incomeCount = 0;
|
||||
var expenseCount = 0;
|
||||
|
||||
for (final transaction in transactions) {
|
||||
final amount = exchange.convert(transaction.amount, transaction.currencyCode, target);
|
||||
if (transaction.type == TransactionType.income) {
|
||||
income += amount;
|
||||
incomeCount++;
|
||||
}
|
||||
if (transaction.type == TransactionType.expense) {
|
||||
expense += amount;
|
||||
expenseCount++;
|
||||
}
|
||||
}
|
||||
|
||||
return StatsSummary(
|
||||
income: income,
|
||||
expense: expense,
|
||||
balance: income - expense,
|
||||
transactionCount: transactions.length,
|
||||
averageIncome: incomeCount == 0 ? 0 : income / incomeCount,
|
||||
averageExpense: expenseCount == 0 ? 0 : expense / expenseCount,
|
||||
);
|
||||
});
|
||||
|
||||
final categoryExpenseProvider = Provider<Map<String, double>>((ref) {
|
||||
final txsAsync = ref.watch(transactionsProvider);
|
||||
final txs = txsAsync.value ?? [];
|
||||
final filtered = txs.where((t) => t.type == TransactionType.expense);
|
||||
|
||||
final exchange = ref.watch(exchangeRateServiceProvider);
|
||||
final index = ref.watch(activeAccountIndexProvider);
|
||||
final accountsAsync = ref.watch(accountsProvider);
|
||||
final globalCurrency = ref.watch(currencyProvider).code;
|
||||
final accounts = accountsAsync.value ?? [];
|
||||
final target = _resolveTargetCurrency(index, accounts, globalCurrency);
|
||||
final map = <String, double>{};
|
||||
for (final t in filtered) {
|
||||
map[t.category] = (map[t.category] ?? 0) + t.amount;
|
||||
for (final t in ref.watch(statsScopedTransactionsProvider)) {
|
||||
if (t.type != TransactionType.expense) continue;
|
||||
map[t.category] = (map[t.category] ?? 0) + exchange.convert(t.amount, t.currencyCode, target);
|
||||
}
|
||||
return map;
|
||||
});
|
||||
|
||||
final categoryIncomeProvider = Provider<Map<String, double>>((ref) {
|
||||
final txsAsync = ref.watch(transactionsProvider);
|
||||
final txs = txsAsync.value ?? [];
|
||||
final filtered = txs.where((t) => t.type == TransactionType.income);
|
||||
|
||||
final exchange = ref.watch(exchangeRateServiceProvider);
|
||||
final index = ref.watch(activeAccountIndexProvider);
|
||||
final accountsAsync = ref.watch(accountsProvider);
|
||||
final globalCurrency = ref.watch(currencyProvider).code;
|
||||
final accounts = accountsAsync.value ?? [];
|
||||
final target = _resolveTargetCurrency(index, accounts, globalCurrency);
|
||||
final map = <String, double>{};
|
||||
for (final t in filtered) {
|
||||
map[t.category] = (map[t.category] ?? 0) + t.amount;
|
||||
for (final t in ref.watch(statsScopedTransactionsProvider)) {
|
||||
if (t.type != TransactionType.income) continue;
|
||||
map[t.category] = (map[t.category] ?? 0) + exchange.convert(t.amount, t.currencyCode, target);
|
||||
}
|
||||
return map;
|
||||
});
|
||||
|
||||
final monthlyBreakdownProvider = Provider<List<MonthlyData>>((ref) {
|
||||
final txsAsync = ref.watch(transactionsProvider);
|
||||
final txs = txsAsync.value ?? [];
|
||||
final filtered = txs.where((t) => t.type == TransactionType.expense);
|
||||
|
||||
final txs = ref.watch(accountFilteredTransactionsProvider);
|
||||
final exchange = ref.watch(exchangeRateServiceProvider);
|
||||
final index = ref.watch(activeAccountIndexProvider);
|
||||
final accountsAsync = ref.watch(accountsProvider);
|
||||
final globalCurrency = ref.watch(currencyProvider).code;
|
||||
final accounts = accountsAsync.value ?? [];
|
||||
final target = _resolveTargetCurrency(index, accounts, globalCurrency);
|
||||
final now = DateTime.now();
|
||||
final months = <MonthlyData>[];
|
||||
|
||||
for (var i = 5; i >= 0; i--) {
|
||||
final month = DateTime(now.year, now.month - i, 1);
|
||||
final total = filtered
|
||||
.where((t) => t.date.year == month.year && t.date.month == month.month)
|
||||
.fold(0.0, (sum, t) => sum + t.amount);
|
||||
final total = txs
|
||||
.where(
|
||||
(t) =>
|
||||
t.type == TransactionType.expense &&
|
||||
t.category != 'Transfer' &&
|
||||
t.date.year == month.year &&
|
||||
t.date.month == month.month,
|
||||
)
|
||||
.fold(0.0, (sum, t) {
|
||||
return sum + exchange.convert(t.amount, t.currencyCode, target);
|
||||
});
|
||||
months.add(MonthlyData(month: month, amount: total));
|
||||
}
|
||||
|
||||
return months;
|
||||
});
|
||||
|
||||
final monthlyIncomeBreakdownProvider = Provider<List<MonthlyData>>((ref) {
|
||||
final txs = ref.watch(accountFilteredTransactionsProvider);
|
||||
final exchange = ref.watch(exchangeRateServiceProvider);
|
||||
final index = ref.watch(activeAccountIndexProvider);
|
||||
final accountsAsync = ref.watch(accountsProvider);
|
||||
final globalCurrency = ref.watch(currencyProvider).code;
|
||||
final accounts = accountsAsync.value ?? [];
|
||||
final target = _resolveTargetCurrency(index, accounts, globalCurrency);
|
||||
final now = DateTime.now();
|
||||
final months = <MonthlyData>[];
|
||||
|
||||
for (var i = 5; i >= 0; i--) {
|
||||
final month = DateTime(now.year, now.month - i, 1);
|
||||
final total = txs
|
||||
.where(
|
||||
(t) =>
|
||||
t.type == TransactionType.income &&
|
||||
t.category != 'Transfer' &&
|
||||
t.date.year == month.year &&
|
||||
t.date.month == month.month,
|
||||
)
|
||||
.fold(0.0, (sum, t) {
|
||||
return sum + exchange.convert(t.amount, t.currencyCode, target);
|
||||
});
|
||||
months.add(MonthlyData(month: month, amount: total));
|
||||
}
|
||||
|
||||
|
||||
+912
-507
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,115 @@
|
||||
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 '../../dashboard/provider.dart';
|
||||
|
||||
class AccountScopeChips extends ConsumerWidget {
|
||||
const AccountScopeChips({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final s = ref.watch(stringsProvider);
|
||||
final accountsAsync = ref.watch(accountsProvider);
|
||||
final activeIndex = ref.watch(activeAccountIndexProvider);
|
||||
final isDark = Theme.of(context).brightness == Brightness.dark;
|
||||
|
||||
return accountsAsync.when(
|
||||
data: (accounts) {
|
||||
if (accounts.isEmpty) return const SizedBox.shrink();
|
||||
|
||||
return SingleChildScrollView(
|
||||
scrollDirection: Axis.horizontal,
|
||||
clipBehavior: Clip.none,
|
||||
child: Row(
|
||||
children: [
|
||||
_ScopeChip(
|
||||
label: s.allAccounts,
|
||||
isSelected: activeIndex == 0,
|
||||
isDark: isDark,
|
||||
onTap: () {
|
||||
ref.read(activeAccountIndexProvider.notifier).set(0);
|
||||
HapticService.selection();
|
||||
},
|
||||
),
|
||||
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) {
|
||||
final index = entry.key + 1;
|
||||
final account = entry.value;
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(right: 6),
|
||||
child: _ScopeChip(
|
||||
label: account.name,
|
||||
isSelected: activeIndex == index,
|
||||
isDark: isDark,
|
||||
onTap: () {
|
||||
ref.read(activeAccountIndexProvider.notifier).set(index);
|
||||
HapticService.selection();
|
||||
},
|
||||
),
|
||||
);
|
||||
}),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
loading: () => const SizedBox.shrink(),
|
||||
error: (_, __) => const SizedBox.shrink(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _ScopeChip extends StatelessWidget {
|
||||
final String label;
|
||||
final bool isSelected;
|
||||
final bool isDark;
|
||||
final VoidCallback onTap;
|
||||
|
||||
const _ScopeChip({
|
||||
required this.label,
|
||||
required this.isSelected,
|
||||
required this.isDark,
|
||||
required this.onTap,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return GestureDetector(
|
||||
onTap: onTap,
|
||||
child: AnimatedContainer(
|
||||
duration: const Duration(milliseconds: 200),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 6),
|
||||
decoration: BoxDecoration(
|
||||
color: isSelected
|
||||
? const Color(0xFF7C6DED).withOpacity(0.2)
|
||||
: Theme.of(context).colorScheme.surface,
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
border: isSelected
|
||||
? Border.all(color: const Color(0xFF7C6DED), width: 1.5)
|
||||
: isDark
|
||||
? null
|
||||
: Border.all(color: const Color(0xFFDDDDEE), width: 1),
|
||||
),
|
||||
child: Text(
|
||||
label,
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
fontWeight: isSelected ? FontWeight.w600 : FontWeight.normal,
|
||||
color: isSelected
|
||||
? const Color(0xFF7C6DED)
|
||||
: Theme.of(context).colorScheme.onSurface.withOpacity(0.6),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,7 @@ import '../../core/utils/result.dart';
|
||||
import '../../data/database/app_database.dart' as db;
|
||||
import '../../data/repositories/transaction_repository.dart';
|
||||
import '../../data/repositories/account_repository.dart';
|
||||
import '../../shared/feature_flags/feature_flags_provider.dart';
|
||||
import '../../shared/models/transaction.dart';
|
||||
import '../../shared/models/account.dart';
|
||||
import '../../shared/services/storage_service.dart';
|
||||
@@ -27,7 +28,7 @@ final transactionRepositoryProvider = Provider<TransactionRepository>((ref) {
|
||||
|
||||
final accountRepositoryProvider = Provider<AccountRepository>((ref) {
|
||||
final db = ref.watch(appDatabaseProvider);
|
||||
return AccountRepository(db);
|
||||
return AccountRepository(db, () => ref.read(featureFlagsProvider));
|
||||
});
|
||||
|
||||
final storageServiceProvider = Provider<StorageService>((ref) {
|
||||
@@ -103,7 +104,8 @@ class TransactionsNotifier extends AsyncNotifier<List<Transaction>> {
|
||||
}
|
||||
|
||||
final transferPairsProvider = Provider<Map<String, Transaction>>((ref) {
|
||||
final txs = ref.watch(transactionsProvider).value ?? [];
|
||||
final txsAsync = ref.watch(transactionsProvider);
|
||||
final txs = txsAsync.value ?? [];
|
||||
final transfers = txs.where((t) => t.category == 'Transfer').toList();
|
||||
final Map<String, Transaction> pairs = {};
|
||||
|
||||
@@ -167,9 +169,9 @@ class _TimeFilterNotifier extends Notifier<TimeFilter> {
|
||||
}
|
||||
|
||||
final accountFilteredTransactionsProvider = Provider<List<Transaction>>((ref) {
|
||||
final activeAccount = ref.watch(activeAccountProvider);
|
||||
final txsAsync = ref.watch(transactionsProvider);
|
||||
final txs = txsAsync.value ?? [];
|
||||
final activeAccount = ref.watch(activeAccountProvider);
|
||||
|
||||
if (activeAccount == null) {
|
||||
return txs;
|
||||
@@ -272,36 +274,6 @@ final totalExpenseProvider = Provider<double>((ref) {
|
||||
});
|
||||
});
|
||||
|
||||
final currentMonthExpenseProvider = Provider<double>((ref) {
|
||||
final now = DateTime.now();
|
||||
final txs = ref.watch(accountFilteredTransactionsProvider);
|
||||
final filtered = txs.where(
|
||||
(t) =>
|
||||
t.type == TransactionType.expense &&
|
||||
t.date.year == now.year &&
|
||||
t.date.month == now.month,
|
||||
);
|
||||
|
||||
final index = ref.watch(activeAccountIndexProvider);
|
||||
final accountsAsync = ref.watch(accountsProvider);
|
||||
final globalCurrency = ref.watch(currencyProvider).code;
|
||||
|
||||
String targetCurrency = globalCurrency;
|
||||
if (index > 0) {
|
||||
final accounts = accountsAsync.value ?? [];
|
||||
if (index <= accounts.length) {
|
||||
targetCurrency = accounts[index - 1].currency;
|
||||
}
|
||||
}
|
||||
|
||||
final exchangeService = ref.watch(exchangeRateServiceProvider);
|
||||
|
||||
return filtered.fold(0.0, (sum, t) {
|
||||
return sum +
|
||||
exchangeService.convert(t.amount, t.currencyCode, targetCurrency);
|
||||
});
|
||||
});
|
||||
|
||||
final filteredTransactionsProvider = Provider<List<Transaction>>((ref) {
|
||||
final txs = ref.watch(accountFilteredTransactionsProvider);
|
||||
final query = ref.watch(searchQueryProvider).toLowerCase();
|
||||
@@ -362,12 +334,9 @@ final recentTransactionsProvider = Provider<List<Transaction>>((ref) {
|
||||
return ref.watch(filteredTransactionsProvider).take(20).toList();
|
||||
});
|
||||
|
||||
final accountsProvider = StreamProvider<List<Account>>((ref) async* {
|
||||
final accountsProvider = StreamProvider<List<Account>>((ref) {
|
||||
final repository = ref.watch(accountRepositoryProvider);
|
||||
while (true) {
|
||||
yield await repository.getAll();
|
||||
await Future.delayed(const Duration(milliseconds: 100));
|
||||
}
|
||||
return repository.watchAll();
|
||||
});
|
||||
|
||||
final activeAccountIndexProvider = NotifierProvider<_ActiveAccountIndexNotifier, int>(
|
||||
|
||||
@@ -5,12 +5,13 @@ import 'package:intl/intl.dart';
|
||||
import '../../core/l10n/locale_provider.dart';
|
||||
import '../../core/services/card_color_service.dart';
|
||||
import '../../core/services/haptic_service.dart';
|
||||
import '../../data/repositories/account_repository.dart';
|
||||
import '../../shared/models/account.dart';
|
||||
import '../../shared/feature_flags/feature_flags_provider.dart';
|
||||
import '../settings/provider.dart';
|
||||
import 'provider.dart';
|
||||
import 'widgets/account_editor_overlay/account_editor_overlay.dart';
|
||||
import 'widgets/balance_card_carousel.dart';
|
||||
import 'widgets/budget_progress.dart';
|
||||
import 'widgets/color_editor_overlay.dart';
|
||||
import 'widgets/filter_chips.dart';
|
||||
import 'widgets/search_bar.dart' as custom;
|
||||
@@ -57,6 +58,7 @@ class _DashboardScreenState extends ConsumerState<DashboardScreen> {
|
||||
bool isAddingAccount = false;
|
||||
|
||||
void _onCardLongPress() {
|
||||
if (!ref.read(featureFlagsProvider).canEditCardColors) return;
|
||||
final colors = ref.read(cardColorsProvider);
|
||||
savedPrimary = colors.primary;
|
||||
savedSecondary = colors.secondary;
|
||||
@@ -180,15 +182,25 @@ class _DashboardScreenState extends ConsumerState<DashboardScreen> {
|
||||
createdAt: DateTime.now(),
|
||||
);
|
||||
|
||||
final newId = await ref.read(accountRepositoryProvider).add(newAccount);
|
||||
try {
|
||||
final newId = await ref.read(accountRepositoryProvider).add(newAccount);
|
||||
|
||||
await CardColorService.save(
|
||||
tempPrimary,
|
||||
tempSecondary,
|
||||
tempLightGradientType,
|
||||
tempDarkGradientType,
|
||||
accountId: newId,
|
||||
);
|
||||
await CardColorService.save(
|
||||
tempPrimary,
|
||||
tempSecondary,
|
||||
tempLightGradientType,
|
||||
tempDarkGradientType,
|
||||
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) {
|
||||
await ref
|
||||
.read(accountCardColorsProvider(editingAccount!.id).notifier)
|
||||
@@ -223,6 +235,7 @@ class _DashboardScreenState extends ConsumerState<DashboardScreen> {
|
||||
});
|
||||
}
|
||||
|
||||
if (!mounted) return;
|
||||
overlayEntry?.remove();
|
||||
overlayEntry = null;
|
||||
setState(() {
|
||||
@@ -266,8 +279,6 @@ class _DashboardScreenState extends ConsumerState<DashboardScreen> {
|
||||
final balance = ref.watch(totalBalanceProvider);
|
||||
final income = ref.watch(totalIncomeProvider);
|
||||
final expense = ref.watch(totalExpenseProvider);
|
||||
final monthExpense = ref.watch(currentMonthExpenseProvider);
|
||||
final budget = ref.watch(budgetProvider);
|
||||
final recent = ref.watch(recentTransactionsProvider);
|
||||
final activeAccount = ref.watch(activeAccountProvider);
|
||||
final globalCurrencyInfo = ref.watch(currencyProvider);
|
||||
@@ -281,8 +292,9 @@ class _DashboardScreenState extends ConsumerState<DashboardScreen> {
|
||||
final activeIndex = ref.watch(activeAccountIndexProvider);
|
||||
final accountsAsync = ref.watch(accountsProvider);
|
||||
final accountCount = accountsAsync.value?.length ?? 0;
|
||||
final maxAccounts = ref.watch(featureFlagsProvider).maxAccounts;
|
||||
final isOnAddAccountPage =
|
||||
accountCount < 5 && activeIndex == accountCount + 1;
|
||||
accountCount < maxAccounts && activeIndex == accountCount + 1;
|
||||
|
||||
return Scaffold(
|
||||
backgroundColor: Theme.of(context).scaffoldBackgroundColor,
|
||||
@@ -291,13 +303,32 @@ class _DashboardScreenState extends ConsumerState<DashboardScreen> {
|
||||
elevation: 0,
|
||||
scrolledUnderElevation: 0,
|
||||
titleSpacing: 20,
|
||||
title: Text(
|
||||
'Casha',
|
||||
style: Theme.of(context).textTheme.headlineMedium?.copyWith(
|
||||
fontWeight: FontWeight.w800,
|
||||
color: Theme.of(context).colorScheme.onSurface,
|
||||
letterSpacing: -0.5,
|
||||
),
|
||||
title: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(
|
||||
'Casha',
|
||||
style: Theme.of(context).textTheme.headlineMedium?.copyWith(
|
||||
fontWeight: FontWeight.w800,
|
||||
color: Theme.of(context).colorScheme.onSurface,
|
||||
letterSpacing: -0.5,
|
||||
),
|
||||
),
|
||||
if (ref.watch(featureFlagsProvider).canEditCardColors) ...[
|
||||
const SizedBox(width: 6),
|
||||
Text(
|
||||
'Pro',
|
||||
style: Theme.of(context).textTheme.headlineMedium?.copyWith(
|
||||
fontWeight: FontWeight.w500,
|
||||
color: Theme.of(context)
|
||||
.colorScheme
|
||||
.onSurface
|
||||
.withOpacity(0.4),
|
||||
letterSpacing: -0.5,
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
actions: [
|
||||
Padding(
|
||||
@@ -376,15 +407,6 @@ class _DashboardScreenState extends ConsumerState<DashboardScreen> {
|
||||
currencyInfo: currencyInfo,
|
||||
strings: s,
|
||||
),
|
||||
if (budget != null) ...[
|
||||
const SizedBox(height: 16),
|
||||
BudgetProgress(
|
||||
spent: monthExpense,
|
||||
budget: budget,
|
||||
currencyInfo: currencyInfo,
|
||||
strings: s,
|
||||
),
|
||||
],
|
||||
const SizedBox(height: 24),
|
||||
custom.SearchBar(
|
||||
controller: _searchController,
|
||||
@@ -449,6 +471,7 @@ class _AccountsInfoBlock extends ConsumerWidget {
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final s = ref.watch(stringsProvider);
|
||||
final maxAccounts = ref.watch(featureFlagsProvider).maxAccounts;
|
||||
final onSurface = Theme.of(context).colorScheme.onSurface;
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(bottom: 60),
|
||||
@@ -464,7 +487,7 @@ class _AccountsInfoBlock extends ConsumerWidget {
|
||||
const Icon(
|
||||
Icons.account_balance_wallet_rounded,
|
||||
size: 18,
|
||||
color: Color(0xFF7C6DED),
|
||||
color: const Color(0xFF7C6DED),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Text(
|
||||
@@ -490,7 +513,7 @@ class _AccountsInfoBlock extends ConsumerWidget {
|
||||
const SizedBox(height: 8),
|
||||
_InfoRow(
|
||||
icon: Icons.lock_outline_rounded,
|
||||
text: s.accountsInfoLimit,
|
||||
text: s.accountsLimitLabel(maxAccounts),
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
+144
-39
@@ -2,8 +2,13 @@ import 'dart:ui';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import '../../../../core/constants.dart';
|
||||
import '../../../../core/l10n/app_strings.dart';
|
||||
import '../../../../core/l10n/locale_provider.dart';
|
||||
import '../../../../core/services/haptic_service.dart';
|
||||
import '../../../../core/utils/card_layout.dart';
|
||||
import '../../../../shared/models/account.dart';
|
||||
import '../../../../shared/models/transaction.dart';
|
||||
import '../../../../shared/feature_flags/feature_flags_provider.dart';
|
||||
import '../../../../shared/widgets/byn_sign.dart';
|
||||
import '../../../settings/provider.dart';
|
||||
import '../../provider.dart';
|
||||
@@ -58,9 +63,7 @@ class _AccountEditorOverlayState extends State<AccountEditorOverlay> {
|
||||
return;
|
||||
}
|
||||
|
||||
dash.setState(() {
|
||||
dash.tempAccountName = _nameController.text;
|
||||
});
|
||||
dash.tempAccountName = _nameController.text;
|
||||
dash.overlayEntry?.markNeedsBuild();
|
||||
});
|
||||
}
|
||||
@@ -84,16 +87,18 @@ class _AccountEditorOverlayState extends State<AccountEditorOverlay> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final mq = MediaQuery.of(widget.context);
|
||||
final cardTop = mq.padding.top + kToolbarHeight + 16;
|
||||
const cardHeight = 190.0;
|
||||
const editorPanelHeight = 102.0;
|
||||
final editorPanelTop = cardTop + cardHeight + 20;
|
||||
final colorPanelTop = editorPanelTop + editorPanelHeight + 12;
|
||||
const colorPanelHeight = 410.0;
|
||||
final layout = CardOverlayLayout.fromMediaQuery(mq);
|
||||
final cardTop = layout.cardTop;
|
||||
final editorPanelHeight = layout.editorPanelHeight;
|
||||
|
||||
return Consumer(
|
||||
builder: (context, ref, _) {
|
||||
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;
|
||||
if (!dash.isAddingAccount) {
|
||||
@@ -218,6 +223,7 @@ class _AccountEditorOverlayState extends State<AccountEditorOverlay> {
|
||||
Brightness.dark
|
||||
? dash.tempDarkGradientType
|
||||
: dash.tempLightGradientType,
|
||||
cardHeight: cardHeight,
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -246,35 +252,136 @@ class _AccountEditorOverlayState extends State<AccountEditorOverlay> {
|
||||
),
|
||||
),
|
||||
),
|
||||
Positioned(
|
||||
top: colorPanelTop,
|
||||
left: 20,
|
||||
right: 20,
|
||||
child: GestureDetector(
|
||||
onTap: () {
|
||||
if (_showCurrencyDropdown) {
|
||||
setState(() {
|
||||
_showCurrencyDropdown = false;
|
||||
});
|
||||
}
|
||||
},
|
||||
behavior: HitTestBehavior.opaque,
|
||||
child: AccountColorPanel(
|
||||
dashboardState: dash,
|
||||
dashboardContext: widget.context,
|
||||
panelHeight: colorPanelHeight,
|
||||
isDuplicateName: _isDuplicateName,
|
||||
onDuplicateError: () {
|
||||
setState(() => _showDuplicateError = true);
|
||||
Future.delayed(const Duration(seconds: 3), () {
|
||||
if (mounted) {
|
||||
setState(() => _showDuplicateError = false);
|
||||
}
|
||||
});
|
||||
if (isPremium) ...[
|
||||
Positioned(
|
||||
top: colorPanelTop,
|
||||
left: 20,
|
||||
right: 20,
|
||||
child: GestureDetector(
|
||||
onTap: () {
|
||||
if (_showCurrencyDropdown) {
|
||||
setState(() {
|
||||
_showCurrencyDropdown = false;
|
||||
});
|
||||
}
|
||||
},
|
||||
behavior: HitTestBehavior.opaque,
|
||||
child: AccountColorPanel(
|
||||
dashboardState: dash,
|
||||
dashboardContext: widget.context,
|
||||
panelHeight: colorPanelHeight,
|
||||
layout: layout,
|
||||
isDuplicateName: _isDuplicateName,
|
||||
onDuplicateError: () {
|
||||
setState(() => _showDuplicateError = true);
|
||||
Future.delayed(const Duration(seconds: 3), () {
|
||||
if (mounted) {
|
||||
setState(() => _showDuplicateError = false);
|
||||
}
|
||||
});
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
] else ...[
|
||||
Positioned(
|
||||
top: editorPanelTop + editorPanelHeight + layout.sectionGap,
|
||||
left: 20,
|
||||
right: 20,
|
||||
child: GestureDetector(
|
||||
onTap: () {
|
||||
if (_showCurrencyDropdown) {
|
||||
setState(() {
|
||||
_showCurrencyDropdown = false;
|
||||
});
|
||||
}
|
||||
},
|
||||
behavior: HitTestBehavior.opaque,
|
||||
child: Container(
|
||||
padding: EdgeInsets.symmetric(
|
||||
horizontal: 16,
|
||||
vertical: layout.buttonVerticalPadding,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: Theme.of(widget.context).colorScheme.surface,
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
border: Border.all(
|
||||
color: Theme.of(
|
||||
widget.context,
|
||||
).colorScheme.onSurface.withOpacity(0.1),
|
||||
width: 1.5,
|
||||
),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.black.withOpacity(0.3),
|
||||
blurRadius: 24,
|
||||
offset: const Offset(0, 8),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: SizedBox(
|
||||
width: double.infinity,
|
||||
child: ElevatedButton(
|
||||
onPressed:
|
||||
dash.tempAccountName.trim().isEmpty
|
||||
? null
|
||||
: () {
|
||||
final accounts =
|
||||
ref.read(accountsProvider).value ?? [];
|
||||
if (_isDuplicateName(
|
||||
accounts,
|
||||
dash.tempAccountName,
|
||||
)) {
|
||||
setState(() => _showDuplicateError = true);
|
||||
Future.delayed(
|
||||
const Duration(seconds: 3),
|
||||
() {
|
||||
if (mounted) {
|
||||
setState(() =>
|
||||
_showDuplicateError = false);
|
||||
}
|
||||
},
|
||||
);
|
||||
return;
|
||||
}
|
||||
HapticService.light();
|
||||
dash.closeAccountOverlay(apply: true);
|
||||
},
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: const Color(0xFF7C6DED),
|
||||
foregroundColor: Colors.white,
|
||||
disabledBackgroundColor: Theme.of(
|
||||
widget.context,
|
||||
).colorScheme.onSurface.withOpacity(0.12),
|
||||
disabledForegroundColor: Theme.of(
|
||||
widget.context,
|
||||
).colorScheme.onSurface.withOpacity(0.38),
|
||||
padding: EdgeInsets.symmetric(
|
||||
vertical: layout.buttonVerticalPadding,
|
||||
),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
),
|
||||
child: Text(
|
||||
dash.isAddingAccount
|
||||
? AppStrings(
|
||||
ref.read(localeProvider),
|
||||
).addAccount
|
||||
: AppStrings(
|
||||
ref.read(localeProvider),
|
||||
).apply,
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.w700,
|
||||
fontSize: layout.compact ? 13 : 14,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
if (_showCurrencyDropdown)
|
||||
Positioned(
|
||||
top: editorPanelTop + 62,
|
||||
@@ -302,9 +409,7 @@ class _AccountEditorOverlayState extends State<AccountEditorOverlay> {
|
||||
onTap: () {
|
||||
setState(() {
|
||||
_selectedCurrency = entry.$1;
|
||||
dash.setState(() {
|
||||
dash.tempAccountCurrency = entry.$1;
|
||||
});
|
||||
dash.tempAccountCurrency = entry.$1;
|
||||
dash.overlayEntry?.markNeedsBuild();
|
||||
_showCurrencyDropdown = false;
|
||||
});
|
||||
@@ -358,7 +463,7 @@ class _AccountEditorOverlayState extends State<AccountEditorOverlay> {
|
||||
const Icon(
|
||||
Icons.check_rounded,
|
||||
size: 14,
|
||||
color: Color(0xFF7C6DED),
|
||||
color: const Color(0xFF7C6DED),
|
||||
),
|
||||
],
|
||||
],
|
||||
|
||||
@@ -5,6 +5,7 @@ import '../../../../core/l10n/app_strings.dart';
|
||||
import '../../../../core/l10n/locale_provider.dart';
|
||||
import '../../../../core/services/card_color_service.dart';
|
||||
import '../../../../core/services/haptic_service.dart';
|
||||
import '../../../../core/utils/card_layout.dart';
|
||||
import '../../../../shared/models/account.dart';
|
||||
import '../../provider.dart';
|
||||
import './panel_tab.dart';
|
||||
@@ -14,6 +15,7 @@ class AccountColorPanel extends StatelessWidget {
|
||||
final dynamic dashboardState;
|
||||
final BuildContext dashboardContext;
|
||||
final double panelHeight;
|
||||
final CardOverlayLayout layout;
|
||||
final bool Function(List<Account>, String) isDuplicateName;
|
||||
final VoidCallback onDuplicateError;
|
||||
|
||||
@@ -22,6 +24,7 @@ class AccountColorPanel extends StatelessWidget {
|
||||
required this.dashboardState,
|
||||
required this.dashboardContext,
|
||||
required this.panelHeight,
|
||||
required this.layout,
|
||||
required this.isDuplicateName,
|
||||
required this.onDuplicateError,
|
||||
});
|
||||
@@ -54,16 +57,14 @@ class AccountColorPanel extends StatelessWidget {
|
||||
);
|
||||
|
||||
void onHSVChanged(HSVColor hsv) {
|
||||
if (dashboardState.editingPrimary) {
|
||||
dashboardState.tempPrimaryHSV = hsv;
|
||||
dashboardState.tempPrimary = hsv.toColor();
|
||||
} else {
|
||||
dashboardState.tempSecondaryHSV = hsv;
|
||||
dashboardState.tempSecondary = hsv.toColor();
|
||||
}
|
||||
setPanelState(() {});
|
||||
dashboardState.setState(() {
|
||||
if (dashboardState.editingPrimary) {
|
||||
dashboardState.tempPrimaryHSV = hsv;
|
||||
dashboardState.tempPrimary = hsv.toColor();
|
||||
} else {
|
||||
dashboardState.tempSecondaryHSV = hsv;
|
||||
dashboardState.tempSecondary = hsv.toColor();
|
||||
}
|
||||
});
|
||||
dashboardState.overlayEntry?.markNeedsBuild();
|
||||
}
|
||||
|
||||
@@ -77,7 +78,12 @@ class AccountColorPanel extends StatelessWidget {
|
||||
: dashboardState.tempSecondaryHSV;
|
||||
|
||||
return Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16, 14, 16, 22),
|
||||
padding: EdgeInsets.fromLTRB(
|
||||
16,
|
||||
layout.panelPaddingTop,
|
||||
16,
|
||||
layout.panelPaddingBottom,
|
||||
),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
@@ -98,18 +104,16 @@ class AccountColorPanel extends StatelessWidget {
|
||||
: dashboardState.tempPrimary,
|
||||
isDimmed: isSolid,
|
||||
onTap: () {
|
||||
dashboardState.setState(() {
|
||||
if (isSolid)
|
||||
if (Theme.of(dashboardContext).brightness ==
|
||||
Brightness.dark) {
|
||||
dashboardState.tempDarkGradientType =
|
||||
CardColorService.defaultGradientDark;
|
||||
} else {
|
||||
dashboardState.tempLightGradientType =
|
||||
CardColorService.defaultGradientLight;
|
||||
}
|
||||
dashboardState.editingPrimary = true;
|
||||
});
|
||||
if (isSolid)
|
||||
if (Theme.of(dashboardContext).brightness ==
|
||||
Brightness.dark) {
|
||||
dashboardState.tempDarkGradientType =
|
||||
GradientType.linear;
|
||||
} else {
|
||||
dashboardState.tempLightGradientType =
|
||||
GradientType.linear;
|
||||
}
|
||||
dashboardState.editingPrimary = true;
|
||||
setPanelState(() {});
|
||||
dashboardState.overlayEntry?.markNeedsBuild();
|
||||
},
|
||||
@@ -124,18 +128,16 @@ class AccountColorPanel extends StatelessWidget {
|
||||
color: dashboardState.tempSecondary,
|
||||
isDimmed: isSolid,
|
||||
onTap: () {
|
||||
dashboardState.setState(() {
|
||||
if (isSolid)
|
||||
if (Theme.of(dashboardContext).brightness ==
|
||||
Brightness.dark) {
|
||||
dashboardState.tempDarkGradientType =
|
||||
CardColorService.defaultGradientDark;
|
||||
} else {
|
||||
dashboardState.tempLightGradientType =
|
||||
CardColorService.defaultGradientLight;
|
||||
}
|
||||
dashboardState.editingPrimary = false;
|
||||
});
|
||||
if (isSolid)
|
||||
if (Theme.of(dashboardContext).brightness ==
|
||||
Brightness.dark) {
|
||||
dashboardState.tempDarkGradientType =
|
||||
GradientType.linear;
|
||||
} else {
|
||||
dashboardState.tempLightGradientType =
|
||||
GradientType.linear;
|
||||
}
|
||||
dashboardState.editingPrimary = false;
|
||||
setPanelState(() {});
|
||||
dashboardState.overlayEntry?.markNeedsBuild();
|
||||
},
|
||||
@@ -156,17 +158,15 @@ class AccountColorPanel extends StatelessWidget {
|
||||
onTap: isSolid
|
||||
? null
|
||||
: () {
|
||||
dashboardState.setState(() {
|
||||
if (Theme.of(dashboardContext).brightness ==
|
||||
Brightness.dark) {
|
||||
dashboardState.tempDarkGradientType =
|
||||
GradientType.solid;
|
||||
} else {
|
||||
dashboardState.tempLightGradientType =
|
||||
GradientType.solid;
|
||||
}
|
||||
dashboardState.editingPrimary = true;
|
||||
});
|
||||
if (Theme.of(dashboardContext).brightness ==
|
||||
Brightness.dark) {
|
||||
dashboardState.tempDarkGradientType =
|
||||
GradientType.solid;
|
||||
} else {
|
||||
dashboardState.tempLightGradientType =
|
||||
GradientType.solid;
|
||||
}
|
||||
dashboardState.editingPrimary = true;
|
||||
setPanelState(() {});
|
||||
dashboardState.overlayEntry?.markNeedsBuild();
|
||||
},
|
||||
@@ -239,12 +239,12 @@ class AccountColorPanel extends StatelessWidget {
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
SizedBox(height: layout.tabSpacing),
|
||||
Expanded(
|
||||
child: LayoutBuilder(
|
||||
builder: (lbCtx, constraints) {
|
||||
const reservedBelow = 78.0;
|
||||
final spectrumH = (constraints.maxHeight - reservedBelow)
|
||||
final spectrumH = (constraints.maxHeight -
|
||||
layout.reservedBelowControls)
|
||||
.clamp(40.0, double.infinity);
|
||||
|
||||
return Column(
|
||||
@@ -262,9 +262,9 @@ class AccountColorPanel extends StatelessWidget {
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
SizedBox(height: layout.controlSpacing),
|
||||
SizedBox(
|
||||
height: 36,
|
||||
height: layout.hueSliderHeight,
|
||||
child: ColorPickerSlider(
|
||||
TrackType.hue,
|
||||
currentHSV,
|
||||
@@ -272,22 +272,19 @@ class AccountColorPanel extends StatelessWidget {
|
||||
displayThumbColor: true,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
SizedBox(height: layout.controlSpacing),
|
||||
IgnorePointer(
|
||||
ignoring: isSolid,
|
||||
child: AnimatedOpacity(
|
||||
duration: const Duration(milliseconds: 200),
|
||||
opacity: isSolid ? 0.4 : 1.0,
|
||||
child: SizedBox(
|
||||
height: 26,
|
||||
height: layout.hexRowHeight,
|
||||
child: Row(
|
||||
children: [
|
||||
GestureDetector(
|
||||
onTap: () {
|
||||
dashboardState.setState(
|
||||
() => dashboardState.editingPrimary =
|
||||
true,
|
||||
);
|
||||
dashboardState.editingPrimary = true;
|
||||
setPanelState(() {});
|
||||
dashboardState.overlayEntry
|
||||
?.markNeedsBuild();
|
||||
@@ -342,11 +339,7 @@ class AccountColorPanel extends StatelessWidget {
|
||||
if (!isSolid)
|
||||
GestureDetector(
|
||||
onTap: () {
|
||||
dashboardState.setState(
|
||||
() =>
|
||||
dashboardState.editingPrimary =
|
||||
false,
|
||||
);
|
||||
dashboardState.editingPrimary = false;
|
||||
setPanelState(() {});
|
||||
dashboardState.overlayEntry
|
||||
?.markNeedsBuild();
|
||||
@@ -411,14 +404,9 @@ class AccountColorPanel extends StatelessWidget {
|
||||
},
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
IgnorePointer(
|
||||
ignoring: isSolid,
|
||||
child: AnimatedOpacity(
|
||||
duration: const Duration(milliseconds: 200),
|
||||
opacity: isSolid ? 0.3 : 1.0,
|
||||
child: Row(
|
||||
children: GradientType.values
|
||||
SizedBox(height: layout.controlSpacing),
|
||||
Row(
|
||||
children: GradientType.values
|
||||
.where((t) => t != GradientType.solid)
|
||||
.map((type) {
|
||||
final isSelected = activeGradientType == type;
|
||||
@@ -444,27 +432,23 @@ class AccountColorPanel extends StatelessWidget {
|
||||
padding: const EdgeInsets.only(right: 6),
|
||||
child: GestureDetector(
|
||||
onTap: () {
|
||||
dashboardState.setState(
|
||||
() {
|
||||
if (Theme.of(dashboardContext)
|
||||
.brightness ==
|
||||
Brightness.dark) {
|
||||
dashboardState.tempDarkGradientType =
|
||||
type;
|
||||
} else {
|
||||
dashboardState.tempLightGradientType =
|
||||
type;
|
||||
}
|
||||
},
|
||||
);
|
||||
if (Theme.of(dashboardContext)
|
||||
.brightness ==
|
||||
Brightness.dark) {
|
||||
dashboardState.tempDarkGradientType =
|
||||
type;
|
||||
} else {
|
||||
dashboardState.tempLightGradientType =
|
||||
type;
|
||||
}
|
||||
setPanelState(() {});
|
||||
dashboardState.overlayEntry
|
||||
?.markNeedsBuild();
|
||||
},
|
||||
child: AnimatedContainer(
|
||||
duration: const Duration(milliseconds: 150),
|
||||
padding: const EdgeInsets.symmetric(
|
||||
vertical: 5,
|
||||
padding: EdgeInsets.symmetric(
|
||||
vertical: layout.compact ? 3 : 5,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: isSelected
|
||||
@@ -518,12 +502,10 @@ class AccountColorPanel extends StatelessWidget {
|
||||
),
|
||||
),
|
||||
);
|
||||
})
|
||||
.toList(),
|
||||
),
|
||||
),
|
||||
})
|
||||
.toList(),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
SizedBox(height: layout.controlSpacing),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
@@ -538,26 +520,27 @@ class AccountColorPanel extends StatelessWidget {
|
||||
final defS = isDarkTheme
|
||||
? CardColorService.defaultSecondary
|
||||
: CardColorService.defaultSecondaryLight;
|
||||
dashboardState.setState(() {
|
||||
dashboardState.tempPrimary = defP;
|
||||
dashboardState.tempSecondary = defS;
|
||||
dashboardState.tempPrimaryHSV = HSVColor.fromColor(
|
||||
defP,
|
||||
);
|
||||
dashboardState.tempSecondaryHSV =
|
||||
HSVColor.fromColor(defS);
|
||||
dashboardState.tempPrimary = defP;
|
||||
dashboardState.tempSecondary = defS;
|
||||
dashboardState.tempPrimaryHSV = HSVColor.fromColor(
|
||||
defP,
|
||||
);
|
||||
dashboardState.tempSecondaryHSV =
|
||||
HSVColor.fromColor(defS);
|
||||
dashboardState.tempLightGradientType =
|
||||
CardColorService.defaultGradientLight;
|
||||
dashboardState.tempDarkGradientType =
|
||||
CardColorService.defaultGradientDark;
|
||||
});
|
||||
setPanelState(() {});
|
||||
dashboardState.overlayEntry?.markNeedsBuild();
|
||||
},
|
||||
icon: const Icon(Icons.restart_alt_rounded, size: 15),
|
||||
icon: Icon(
|
||||
Icons.restart_alt_rounded,
|
||||
size: layout.compact ? 14 : 15,
|
||||
),
|
||||
label: Text(
|
||||
s.reset,
|
||||
style: const TextStyle(fontSize: 13),
|
||||
style: TextStyle(fontSize: layout.compact ? 12 : 13),
|
||||
),
|
||||
style: OutlinedButton.styleFrom(
|
||||
foregroundColor: Theme.of(
|
||||
@@ -568,7 +551,9 @@ class AccountColorPanel extends StatelessWidget {
|
||||
dashboardContext,
|
||||
).colorScheme.onSurface.withOpacity(0.2),
|
||||
),
|
||||
padding: const EdgeInsets.symmetric(vertical: 10),
|
||||
padding: EdgeInsets.symmetric(
|
||||
vertical: layout.buttonVerticalPadding,
|
||||
),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
@@ -613,7 +598,9 @@ class AccountColorPanel extends StatelessWidget {
|
||||
disabledForegroundColor: Theme.of(
|
||||
dashboardContext,
|
||||
).colorScheme.onSurface.withOpacity(0.38),
|
||||
padding: const EdgeInsets.symmetric(vertical: 10),
|
||||
padding: EdgeInsets.symmetric(
|
||||
vertical: layout.buttonVerticalPadding,
|
||||
),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
@@ -622,9 +609,9 @@ class AccountColorPanel extends StatelessWidget {
|
||||
dashboardState.isAddingAccount
|
||||
? s.addAccount
|
||||
: s.apply,
|
||||
style: const TextStyle(
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.w700,
|
||||
fontSize: 14,
|
||||
fontSize: layout.compact ? 13 : 14,
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
@@ -61,7 +61,7 @@ class _AccountEditorPanelState extends ConsumerState<AccountEditorPanel> {
|
||||
],
|
||||
),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 12),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 10),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
@@ -76,7 +76,7 @@ class _AccountEditorPanelState extends ConsumerState<AccountEditorPanel> {
|
||||
).colorScheme.onSurface.withOpacity(0.6),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
const SizedBox(height: 6),
|
||||
IntrinsicHeight(
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
|
||||
@@ -5,8 +5,11 @@ import 'package:sensors_plus/sensors_plus.dart';
|
||||
import '../../../core/constants.dart';
|
||||
import '../../../core/l10n/locale_provider.dart';
|
||||
import '../../../core/services/card_color_service.dart';
|
||||
import '../../../core/utils/card_layout.dart';
|
||||
import '../../../shared/utils/card_gradient.dart';
|
||||
import '../../../core/services/haptic_service.dart';
|
||||
import '../../../shared/providers/amount_format_provider.dart';
|
||||
import '../../../shared/feature_flags/feature_flags_provider.dart';
|
||||
import '../../../shared/widgets/byn_sign.dart';
|
||||
import '../../settings/provider.dart';
|
||||
import '../provider.dart';
|
||||
@@ -26,7 +29,7 @@ String _smartBalance(double amount, AmountFormat fmt, String symbol) {
|
||||
return symbol.isEmpty ? formatted : '$symbol$formatted';
|
||||
}
|
||||
|
||||
class BalanceCard extends ConsumerStatefulWidget {
|
||||
class BalanceCard extends StatefulWidget {
|
||||
final double balance;
|
||||
final CurrencyInfo currencyInfo;
|
||||
final VoidCallback? onLongPress;
|
||||
@@ -35,6 +38,8 @@ class BalanceCard extends ConsumerStatefulWidget {
|
||||
final GradientType? previewGradientType;
|
||||
final String? accountName;
|
||||
final CardColors? accountColors;
|
||||
final double? cardHeight;
|
||||
final Widget? resizeHandle;
|
||||
|
||||
const BalanceCard({
|
||||
super.key,
|
||||
@@ -46,13 +51,15 @@ class BalanceCard extends ConsumerStatefulWidget {
|
||||
this.previewGradientType,
|
||||
this.accountName,
|
||||
this.accountColors,
|
||||
this.cardHeight,
|
||||
this.resizeHandle,
|
||||
});
|
||||
|
||||
@override
|
||||
ConsumerState<BalanceCard> createState() => BalanceCardState();
|
||||
State<BalanceCard> createState() => BalanceCardState();
|
||||
}
|
||||
|
||||
class BalanceCardState extends ConsumerState<BalanceCard>
|
||||
class BalanceCardState extends State<BalanceCard>
|
||||
with SingleTickerProviderStateMixin {
|
||||
late final AnimationController _controller;
|
||||
double _tiltX = 0.0, _tiltY = 0.0;
|
||||
@@ -83,49 +90,10 @@ class BalanceCardState extends ConsumerState<BalanceCard>
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
Gradient _buildGradient(Color primary, Color secondary, GradientType type) {
|
||||
final colorDark = Color.lerp(secondary, Colors.black, 0.3)!;
|
||||
|
||||
switch (type) {
|
||||
case GradientType.linear:
|
||||
return LinearGradient(
|
||||
begin: Alignment.topLeft,
|
||||
end: Alignment.bottomRight,
|
||||
colors: [primary, secondary, colorDark],
|
||||
stops: const [0.0, 0.6, 1.0],
|
||||
);
|
||||
case GradientType.linearReverse:
|
||||
return LinearGradient(
|
||||
begin: Alignment.topRight,
|
||||
end: Alignment.bottomLeft,
|
||||
colors: [primary, secondary, colorDark],
|
||||
stops: const [0.0, 0.6, 1.0],
|
||||
);
|
||||
case GradientType.radial:
|
||||
return RadialGradient(
|
||||
center: Alignment.center,
|
||||
radius: 1.4,
|
||||
colors: [primary, secondary, colorDark],
|
||||
stops: const [0.0, 0.6, 1.0],
|
||||
);
|
||||
case GradientType.sweep:
|
||||
return SweepGradient(
|
||||
center: Alignment.center,
|
||||
startAngle: 0.0,
|
||||
endAngle: 3.14159 * 2,
|
||||
colors: [primary, secondary, colorDark, secondary, primary],
|
||||
stops: const [0.0, 0.25, 0.5, 0.75, 1.0],
|
||||
);
|
||||
case GradientType.solid:
|
||||
return LinearGradient(
|
||||
colors: [primary, primary, primary],
|
||||
stops: const [0.0, 0.5, 1.0],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Consumer(
|
||||
builder: (context, ref, _) {
|
||||
final s = ref.watch(stringsProvider);
|
||||
final rates = ref.read(exchangeRateServiceProvider);
|
||||
final fmt = ref.watch(amountFormatProvider);
|
||||
@@ -145,6 +113,7 @@ class BalanceCardState extends ConsumerState<BalanceCard>
|
||||
.toList();
|
||||
|
||||
final textColorMode = ref.watch(cardTextColorProvider);
|
||||
final canEditCardColors = ref.watch(featureFlagsProvider).canEditCardColors;
|
||||
final Color onCard = switch (textColorMode) {
|
||||
CardTextColorMode.white => Colors.white,
|
||||
CardTextColorMode.black => Colors.black,
|
||||
@@ -169,24 +138,27 @@ class BalanceCardState extends ConsumerState<BalanceCard>
|
||||
..setEntry(3, 2, 0.001)
|
||||
..rotateX(_tiltX * 0.42)
|
||||
..rotateY(_tiltY * 0.42),
|
||||
child: Container(
|
||||
width: double.infinity,
|
||||
height: 180,
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
gradient: _buildGradient(primary, secondary, gradientType),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.black.withOpacity(0.4),
|
||||
blurRadius: 20,
|
||||
offset: const Offset(0, 8),
|
||||
child: Stack(
|
||||
clipBehavior: Clip.none,
|
||||
children: [
|
||||
Container(
|
||||
width: double.infinity,
|
||||
height: widget.cardHeight ?? kBalanceCardHeight,
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
gradient: buildCardGradient(primary, secondary, gradientType),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.black.withOpacity(0.4),
|
||||
blurRadius: 20,
|
||||
offset: const Offset(0, 8),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
child: ClipRRect(
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
child: Stack(
|
||||
children: [
|
||||
child: ClipRRect(
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
child: Stack(
|
||||
children: [
|
||||
if (widget.accountName != null)
|
||||
Positioned(
|
||||
top: 20,
|
||||
@@ -356,12 +328,13 @@ class BalanceCardState extends ConsumerState<BalanceCard>
|
||||
],
|
||||
),
|
||||
),
|
||||
Positioned(
|
||||
bottom: 8,
|
||||
left: 0,
|
||||
right: 0,
|
||||
child: Text(
|
||||
s.tapAndHoldToEdit,
|
||||
if (canEditCardColors)
|
||||
Positioned(
|
||||
bottom: 8,
|
||||
left: 0,
|
||||
right: 0,
|
||||
child: Text(
|
||||
s.tapAndHoldToEdit,
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(
|
||||
fontSize: 9,
|
||||
@@ -373,10 +346,20 @@ class BalanceCardState extends ConsumerState<BalanceCard>
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
if (widget.resizeHandle != null)
|
||||
Positioned(
|
||||
right: 0,
|
||||
bottom: 0,
|
||||
child: widget.resizeHandle!,
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import '../../../core/services/card_color_service.dart';
|
||||
import '../../../core/utils/card_layout.dart';
|
||||
import '../../../core/services/haptic_service.dart';
|
||||
import '../../../shared/models/account.dart';
|
||||
import '../../../shared/models/transaction.dart';
|
||||
import '../../../shared/feature_flags/feature_flags_provider.dart';
|
||||
import '../../settings/provider.dart';
|
||||
import '../provider.dart';
|
||||
import 'balance_card.dart';
|
||||
@@ -58,15 +60,17 @@ class _BalanceCardCarouselState extends ConsumerState<BalanceCardCarousel> {
|
||||
Widget build(BuildContext context) {
|
||||
final accountsAsync = ref.watch(accountsProvider);
|
||||
final activeIndex = ref.watch(activeAccountIndexProvider);
|
||||
final cardHeight = ref.watch(cardHeightProvider);
|
||||
final maxAccounts = ref.watch(featureFlagsProvider).maxAccounts;
|
||||
|
||||
return accountsAsync.when(
|
||||
data: (accounts) {
|
||||
final totalPages = 1 + accounts.length + (accounts.length < 5 ? 1 : 0);
|
||||
final totalPages = 1 + accounts.length + (accounts.length < maxAccounts ? 1 : 0);
|
||||
|
||||
return Column(
|
||||
children: [
|
||||
SizedBox(
|
||||
height: 190,
|
||||
height: cardHeight + 10,
|
||||
child: OverflowBox(
|
||||
maxWidth: MediaQuery.of(context).size.width,
|
||||
child: PageView.builder(
|
||||
@@ -95,6 +99,7 @@ class _BalanceCardCarouselState extends ConsumerState<BalanceCardCarousel> {
|
||||
previewPrimary: widget.previewPrimary,
|
||||
previewSecondary: widget.previewSecondary,
|
||||
previewGradientType: widget.previewGradientType,
|
||||
cardHeight: cardHeight,
|
||||
);
|
||||
} else if (index <= accounts.length) {
|
||||
final account = accounts[index - 1];
|
||||
@@ -133,10 +138,12 @@ class _BalanceCardCarouselState extends ConsumerState<BalanceCardCarousel> {
|
||||
widget.onAccountLongPress?.call(account),
|
||||
accountName: account.name,
|
||||
accountColors: accountColors,
|
||||
cardHeight: cardHeight,
|
||||
);
|
||||
} else {
|
||||
cardWidget = AddAccountCard(
|
||||
onTap: widget.onAddAccountTap,
|
||||
cardHeight: cardHeight,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -153,15 +160,15 @@ class _BalanceCardCarouselState extends ConsumerState<BalanceCardCarousel> {
|
||||
],
|
||||
);
|
||||
},
|
||||
loading: () => const SizedBox(
|
||||
height: 180,
|
||||
child: Center(child: CircularProgressIndicator()),
|
||||
loading: () => SizedBox(
|
||||
height: cardHeight + 10,
|
||||
child: const Center(child: CircularProgressIndicator()),
|
||||
),
|
||||
error: (error, stack) {
|
||||
return Column(
|
||||
children: [
|
||||
SizedBox(
|
||||
height: 180,
|
||||
height: cardHeight + 10,
|
||||
child: BalanceCard(
|
||||
balance: widget.balance,
|
||||
currencyInfo: widget.currencyInfo,
|
||||
@@ -169,6 +176,7 @@ class _BalanceCardCarouselState extends ConsumerState<BalanceCardCarousel> {
|
||||
previewPrimary: widget.previewPrimary,
|
||||
previewSecondary: widget.previewSecondary,
|
||||
previewGradientType: widget.previewGradientType,
|
||||
cardHeight: cardHeight,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
@@ -182,8 +190,9 @@ class _BalanceCardCarouselState extends ConsumerState<BalanceCardCarousel> {
|
||||
|
||||
class AddAccountCard extends StatelessWidget {
|
||||
final VoidCallback? onTap;
|
||||
final double? cardHeight;
|
||||
|
||||
const AddAccountCard({super.key, this.onTap});
|
||||
const AddAccountCard({super.key, this.onTap, this.cardHeight});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@@ -192,13 +201,13 @@ class AddAccountCard extends StatelessWidget {
|
||||
child: Container(
|
||||
margin: const EdgeInsets.symmetric(
|
||||
horizontal: 10,
|
||||
vertical: 10,
|
||||
vertical: 5,
|
||||
),
|
||||
child: CustomPaint(
|
||||
painter: _DashedBorderPainter(),
|
||||
child: Container(
|
||||
width: double.infinity,
|
||||
height: 165,
|
||||
height: cardHeight ?? kAddAccountCardHeight,
|
||||
decoration: BoxDecoration(
|
||||
color: Theme.of(context).colorScheme.surface.withOpacity(0.4),
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
|
||||
@@ -1,187 +0,0 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import '../../../core/l10n/app_strings.dart';
|
||||
import '../../../shared/providers/amount_format_provider.dart';
|
||||
import '../../../shared/utils/currency_utils.dart';
|
||||
import '../../../shared/widgets/byn_sign.dart';
|
||||
import '../../settings/provider.dart';
|
||||
|
||||
class BudgetProgress extends ConsumerWidget {
|
||||
final double spent;
|
||||
final double budget;
|
||||
final CurrencyInfo currencyInfo;
|
||||
final AppStrings strings;
|
||||
const BudgetProgress({
|
||||
super.key,
|
||||
required this.spent,
|
||||
required this.budget,
|
||||
required this.currencyInfo,
|
||||
required this.strings,
|
||||
});
|
||||
|
||||
Border? _themeBorder(BuildContext context) {
|
||||
final isDark = Theme.of(context).brightness == Brightness.dark;
|
||||
return isDark ? null : Border.all(color: const Color(0xFFDDDDEE), width: 1);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final fmt = ref.watch(amountFormatProvider);
|
||||
final progress = budget > 0 ? spent / budget : 0.0;
|
||||
final isOver = progress > 1.0;
|
||||
final displayPercent = (progress * 100).toStringAsFixed(0);
|
||||
|
||||
return ClipRRect(
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
child: Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
color: Theme.of(context).colorScheme.surface,
|
||||
border: Border(
|
||||
left: BorderSide(
|
||||
color: isOver ? const Color(0xFFE05C6B) : const Color(0xFF7C6DED),
|
||||
width: 3,
|
||||
),
|
||||
top: _themeBorder(context)?.top ?? BorderSide.none,
|
||||
right: _themeBorder(context)?.right ?? BorderSide.none,
|
||||
bottom: _themeBorder(context)?.bottom ?? BorderSide.none,
|
||||
),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(
|
||||
strings.monthlyBudget,
|
||||
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
|
||||
color: Theme.of(
|
||||
context,
|
||||
).colorScheme.onSurface.withOpacity(0.6),
|
||||
),
|
||||
),
|
||||
Text(
|
||||
'$displayPercent%',
|
||||
style: TextStyle(
|
||||
color: isOver
|
||||
? const Color(0xFFE05C6B)
|
||||
: Theme.of(
|
||||
context,
|
||||
).colorScheme.onSurface.withOpacity(0.7),
|
||||
fontWeight: isOver ? FontWeight.w700 : FontWeight.normal,
|
||||
fontSize: 12,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
ClipRRect(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
child: LinearProgressIndicator(
|
||||
value: isOver ? 1.0 : progress,
|
||||
backgroundColor: Theme.of(
|
||||
context,
|
||||
).colorScheme.onSurface.withOpacity(0.1),
|
||||
valueColor: AlwaysStoppedAnimation<Color>(
|
||||
isOver
|
||||
? const Color(0xFFE05C6B)
|
||||
: (progress > 0.8
|
||||
? Colors.orange
|
||||
: const Color(0xFF4CAF8C)),
|
||||
),
|
||||
minHeight: 8,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
currencyInfo.code == 'BYN'
|
||||
? Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
Text(
|
||||
'${strings.spent}: ',
|
||||
style: Theme.of(context).textTheme.bodySmall
|
||||
?.copyWith(
|
||||
color: Theme.of(
|
||||
context,
|
||||
).colorScheme.onSurface.withOpacity(0.6),
|
||||
),
|
||||
),
|
||||
BynSign(
|
||||
fontSize: 12,
|
||||
color: Theme.of(
|
||||
context,
|
||||
).colorScheme.onSurface.withOpacity(0.6),
|
||||
),
|
||||
const SizedBox(width: 2),
|
||||
Text(
|
||||
formatAmount('', spent, fmt),
|
||||
style: Theme.of(context).textTheme.bodySmall
|
||||
?.copyWith(
|
||||
color: Theme.of(
|
||||
context,
|
||||
).colorScheme.onSurface.withOpacity(0.6),
|
||||
),
|
||||
),
|
||||
],
|
||||
)
|
||||
: Text(
|
||||
'${strings.spent}: ${formatAmount(currencyInfo.symbol, spent, fmt)}',
|
||||
style: Theme.of(context).textTheme.bodySmall?.copyWith(
|
||||
color: Theme.of(
|
||||
context,
|
||||
).colorScheme.onSurface.withOpacity(0.6),
|
||||
),
|
||||
),
|
||||
currencyInfo.code == 'BYN'
|
||||
? Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
Text(
|
||||
'${strings.limit}: ',
|
||||
style: Theme.of(context).textTheme.bodySmall
|
||||
?.copyWith(
|
||||
color: Theme.of(
|
||||
context,
|
||||
).colorScheme.onSurface.withOpacity(0.6),
|
||||
),
|
||||
),
|
||||
BynSign(
|
||||
fontSize: 12,
|
||||
color: Theme.of(
|
||||
context,
|
||||
).colorScheme.onSurface.withOpacity(0.6),
|
||||
),
|
||||
const SizedBox(width: 2),
|
||||
Text(
|
||||
formatAmount('', budget, fmt),
|
||||
style: Theme.of(context).textTheme.bodySmall
|
||||
?.copyWith(
|
||||
color: Theme.of(
|
||||
context,
|
||||
).colorScheme.onSurface.withOpacity(0.6),
|
||||
),
|
||||
),
|
||||
],
|
||||
)
|
||||
: Text(
|
||||
'${strings.limit}: ${formatAmount(currencyInfo.symbol, budget, fmt)}',
|
||||
style: Theme.of(context).textTheme.bodySmall?.copyWith(
|
||||
color: Theme.of(
|
||||
context,
|
||||
).colorScheme.onSurface.withOpacity(0.6),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,9 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import '../../../core/l10n/app_strings.dart';
|
||||
import '../../../core/l10n/locale_provider.dart';
|
||||
import '../../../core/services/card_color_service.dart';
|
||||
import '../../../core/services/haptic_service.dart';
|
||||
import '../../../core/utils/card_layout.dart';
|
||||
import '../../../shared/feature_flags/feature_flags_provider.dart';
|
||||
import '../../settings/provider.dart';
|
||||
import '../provider.dart';
|
||||
import 'balance_card.dart';
|
||||
@@ -34,10 +37,17 @@ class _FullScreenBlurOverlayState extends State<FullScreenBlurOverlay> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final mq = MediaQuery.of(widget.context);
|
||||
final cardTop = mq.padding.top + kToolbarHeight + 16;
|
||||
const cardHeight = 230.0;
|
||||
final panelTop = cardTop + cardHeight + 65;
|
||||
const panelHeight = 410.0;
|
||||
final layout = CardOverlayLayout.fromMediaQuery(mq);
|
||||
final cardTop = layout.cardTop;
|
||||
|
||||
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);
|
||||
|
||||
return Material(
|
||||
color: Colors.transparent,
|
||||
@@ -58,7 +68,7 @@ class _FullScreenBlurOverlayState extends State<FullScreenBlurOverlay> {
|
||||
),
|
||||
),
|
||||
Positioned(
|
||||
top: cardTop,
|
||||
top: adjustedCardTop,
|
||||
left: 0,
|
||||
right: 0,
|
||||
child: FractionallySizedBox(
|
||||
@@ -67,18 +77,33 @@ class _FullScreenBlurOverlayState extends State<FullScreenBlurOverlay> {
|
||||
height: cardHeight,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8),
|
||||
child: Consumer(
|
||||
builder: (ctx, ref, _) => BalanceCard(
|
||||
balance: ref.read(totalBalanceProvider),
|
||||
currencyInfo: ref.read(currencyProvider),
|
||||
onLongPress: null,
|
||||
previewPrimary: dash.tempPrimary,
|
||||
previewSecondary: dash.tempSecondary,
|
||||
previewGradientType:
|
||||
Theme.of(widget.context).brightness == Brightness.dark
|
||||
? dash.tempDarkGradientType
|
||||
: dash.tempLightGradientType,
|
||||
),
|
||||
child: Stack(
|
||||
clipBehavior: Clip.none,
|
||||
children: [
|
||||
Consumer(
|
||||
builder: (ctx, ref, _) => BalanceCard(
|
||||
balance: ref.read(totalBalanceProvider),
|
||||
currencyInfo: ref.read(currencyProvider),
|
||||
onLongPress: null,
|
||||
previewPrimary: dash.tempPrimary,
|
||||
previewSecondary: dash.tempSecondary,
|
||||
previewGradientType:
|
||||
Theme.of(widget.context).brightness == Brightness.dark
|
||||
? dash.tempDarkGradientType
|
||||
: dash.tempLightGradientType,
|
||||
cardHeight: cardHeight,
|
||||
resizeHandle: isPremium ? _CornerResizeHandle(
|
||||
cardHeight: cardHeight,
|
||||
onHeightChanged: (newHeight) {
|
||||
ref.read(cardHeightProvider.notifier).set(newHeight);
|
||||
if (ref.read(hapticEnabledProvider)) {
|
||||
HapticService.selection();
|
||||
}
|
||||
},
|
||||
) : null,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -91,7 +116,7 @@ class _FullScreenBlurOverlayState extends State<FullScreenBlurOverlay> {
|
||||
child: GestureDetector(
|
||||
onTap: () {},
|
||||
behavior: HitTestBehavior.opaque,
|
||||
child: _buildPanel(panelHeight),
|
||||
child: _buildPanel(panelHeight, layout),
|
||||
),
|
||||
),
|
||||
Positioned(
|
||||
@@ -130,9 +155,11 @@ class _FullScreenBlurOverlayState extends State<FullScreenBlurOverlay> {
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildPanel(double panelHeight) {
|
||||
Widget _buildPanel(double panelHeight, CardOverlayLayout layout) {
|
||||
return Container(
|
||||
height: panelHeight,
|
||||
decoration: BoxDecoration(
|
||||
@@ -159,16 +186,14 @@ class _FullScreenBlurOverlayState extends State<FullScreenBlurOverlay> {
|
||||
);
|
||||
|
||||
void onHSVChanged(HSVColor hsv) {
|
||||
if (dash.editingPrimary) {
|
||||
dash.tempPrimaryHSV = hsv;
|
||||
dash.tempPrimary = hsv.toColor();
|
||||
} else {
|
||||
dash.tempSecondaryHSV = hsv;
|
||||
dash.tempSecondary = hsv.toColor();
|
||||
}
|
||||
setPanelState(() {});
|
||||
dash.setState(() {
|
||||
if (dash.editingPrimary) {
|
||||
dash.tempPrimaryHSV = hsv;
|
||||
dash.tempPrimary = hsv.toColor();
|
||||
} else {
|
||||
dash.tempSecondaryHSV = hsv;
|
||||
dash.tempSecondary = hsv.toColor();
|
||||
}
|
||||
});
|
||||
dash.overlayEntry?.markNeedsBuild();
|
||||
}
|
||||
|
||||
@@ -182,7 +207,12 @@ class _FullScreenBlurOverlayState extends State<FullScreenBlurOverlay> {
|
||||
: dash.tempSecondaryHSV;
|
||||
|
||||
return Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16, 14, 16, 22),
|
||||
padding: EdgeInsets.fromLTRB(
|
||||
16,
|
||||
layout.panelPaddingTop,
|
||||
16,
|
||||
layout.panelPaddingBottom,
|
||||
),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
@@ -201,19 +231,17 @@ class _FullScreenBlurOverlayState extends State<FullScreenBlurOverlay> {
|
||||
: dash.tempPrimary,
|
||||
isDimmed: isSolid,
|
||||
onTap: () {
|
||||
dash.setState(() {
|
||||
if (isSolid) {
|
||||
if (Theme.of(widget.context).brightness ==
|
||||
Brightness.dark) {
|
||||
dash.tempDarkGradientType =
|
||||
CardColorService.defaultGradientDark;
|
||||
} else {
|
||||
dash.tempLightGradientType =
|
||||
CardColorService.defaultGradientLight;
|
||||
}
|
||||
if (isSolid) {
|
||||
if (Theme.of(widget.context).brightness ==
|
||||
Brightness.dark) {
|
||||
dash.tempDarkGradientType =
|
||||
GradientType.linear;
|
||||
} else {
|
||||
dash.tempLightGradientType =
|
||||
GradientType.linear;
|
||||
}
|
||||
dash.editingPrimary = true;
|
||||
});
|
||||
}
|
||||
dash.editingPrimary = true;
|
||||
setPanelState(() {});
|
||||
dash.overlayEntry?.markNeedsBuild();
|
||||
},
|
||||
@@ -227,19 +255,17 @@ class _FullScreenBlurOverlayState extends State<FullScreenBlurOverlay> {
|
||||
color: dash.tempSecondary,
|
||||
isDimmed: isSolid,
|
||||
onTap: () {
|
||||
dash.setState(() {
|
||||
if (isSolid) {
|
||||
if (Theme.of(widget.context).brightness ==
|
||||
Brightness.dark) {
|
||||
dash.tempDarkGradientType =
|
||||
CardColorService.defaultGradientDark;
|
||||
} else {
|
||||
dash.tempLightGradientType =
|
||||
CardColorService.defaultGradientLight;
|
||||
}
|
||||
if (isSolid) {
|
||||
if (Theme.of(widget.context).brightness ==
|
||||
Brightness.dark) {
|
||||
dash.tempDarkGradientType =
|
||||
GradientType.linear;
|
||||
} else {
|
||||
dash.tempLightGradientType =
|
||||
GradientType.linear;
|
||||
}
|
||||
dash.editingPrimary = false;
|
||||
});
|
||||
}
|
||||
dash.editingPrimary = false;
|
||||
setPanelState(() {});
|
||||
dash.overlayEntry?.markNeedsBuild();
|
||||
},
|
||||
@@ -259,17 +285,15 @@ class _FullScreenBlurOverlayState extends State<FullScreenBlurOverlay> {
|
||||
onTap: isSolid
|
||||
? null
|
||||
: () {
|
||||
dash.setState(() {
|
||||
if (Theme.of(widget.context).brightness ==
|
||||
Brightness.dark) {
|
||||
dash.tempDarkGradientType =
|
||||
GradientType.solid;
|
||||
} else {
|
||||
dash.tempLightGradientType =
|
||||
GradientType.solid;
|
||||
}
|
||||
dash.editingPrimary = true;
|
||||
});
|
||||
if (Theme.of(widget.context).brightness ==
|
||||
Brightness.dark) {
|
||||
dash.tempDarkGradientType =
|
||||
GradientType.solid;
|
||||
} else {
|
||||
dash.tempLightGradientType =
|
||||
GradientType.solid;
|
||||
}
|
||||
dash.editingPrimary = true;
|
||||
setPanelState(() {});
|
||||
dash.overlayEntry?.markNeedsBuild();
|
||||
},
|
||||
@@ -341,12 +365,12 @@ class _FullScreenBlurOverlayState extends State<FullScreenBlurOverlay> {
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
SizedBox(height: layout.tabSpacing),
|
||||
Expanded(
|
||||
child: LayoutBuilder(
|
||||
builder: (lbCtx, constraints) {
|
||||
const reservedBelow = 78.0;
|
||||
final spectrumH = (constraints.maxHeight - reservedBelow)
|
||||
final spectrumH = (constraints.maxHeight -
|
||||
layout.reservedBelowControls)
|
||||
.clamp(40.0, double.infinity);
|
||||
|
||||
return Column(
|
||||
@@ -364,9 +388,9 @@ class _FullScreenBlurOverlayState extends State<FullScreenBlurOverlay> {
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
SizedBox(height: layout.controlSpacing),
|
||||
SizedBox(
|
||||
height: 36,
|
||||
height: layout.hueSliderHeight,
|
||||
child: ColorPickerSlider(
|
||||
TrackType.hue,
|
||||
currentHSV,
|
||||
@@ -374,21 +398,19 @@ class _FullScreenBlurOverlayState extends State<FullScreenBlurOverlay> {
|
||||
displayThumbColor: true,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
SizedBox(height: layout.controlSpacing),
|
||||
IgnorePointer(
|
||||
ignoring: isSolid,
|
||||
child: AnimatedOpacity(
|
||||
duration: const Duration(milliseconds: 200),
|
||||
opacity: isSolid ? 0.4 : 1.0,
|
||||
child: SizedBox(
|
||||
height: 26,
|
||||
height: layout.hexRowHeight,
|
||||
child: Row(
|
||||
children: [
|
||||
GestureDetector(
|
||||
onTap: () {
|
||||
dash.setState(
|
||||
() => dash.editingPrimary = true,
|
||||
);
|
||||
dash.editingPrimary = true;
|
||||
setPanelState(() {});
|
||||
dash.overlayEntry?.markNeedsBuild();
|
||||
},
|
||||
@@ -439,9 +461,7 @@ class _FullScreenBlurOverlayState extends State<FullScreenBlurOverlay> {
|
||||
if (!isSolid)
|
||||
GestureDetector(
|
||||
onTap: () {
|
||||
dash.setState(
|
||||
() => dash.editingPrimary = false,
|
||||
);
|
||||
dash.editingPrimary = false;
|
||||
setPanelState(() {});
|
||||
dash.overlayEntry?.markNeedsBuild();
|
||||
},
|
||||
@@ -499,14 +519,9 @@ class _FullScreenBlurOverlayState extends State<FullScreenBlurOverlay> {
|
||||
},
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
IgnorePointer(
|
||||
ignoring: isSolid,
|
||||
child: AnimatedOpacity(
|
||||
duration: const Duration(milliseconds: 200),
|
||||
opacity: isSolid ? 0.3 : 1.0,
|
||||
child: Row(
|
||||
children: GradientType.values
|
||||
SizedBox(height: layout.controlSpacing),
|
||||
Row(
|
||||
children: GradientType.values
|
||||
.where((t) => t != GradientType.solid)
|
||||
.map((type) {
|
||||
final isSelected = activeGradientType == type;
|
||||
@@ -532,21 +547,19 @@ class _FullScreenBlurOverlayState extends State<FullScreenBlurOverlay> {
|
||||
padding: const EdgeInsets.only(right: 6),
|
||||
child: GestureDetector(
|
||||
onTap: () {
|
||||
dash.setState(() {
|
||||
if (Theme.of(widget.context).brightness ==
|
||||
Brightness.dark) {
|
||||
dash.tempDarkGradientType = type;
|
||||
} else {
|
||||
dash.tempLightGradientType = type;
|
||||
}
|
||||
});
|
||||
if (Theme.of(widget.context).brightness ==
|
||||
Brightness.dark) {
|
||||
dash.tempDarkGradientType = type;
|
||||
} else {
|
||||
dash.tempLightGradientType = type;
|
||||
}
|
||||
setPanelState(() {});
|
||||
dash.overlayEntry?.markNeedsBuild();
|
||||
},
|
||||
child: AnimatedContainer(
|
||||
duration: const Duration(milliseconds: 150),
|
||||
padding: const EdgeInsets.symmetric(
|
||||
vertical: 5,
|
||||
padding: EdgeInsets.symmetric(
|
||||
vertical: layout.compact ? 3 : 5,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: isSelected
|
||||
@@ -600,12 +613,10 @@ class _FullScreenBlurOverlayState extends State<FullScreenBlurOverlay> {
|
||||
),
|
||||
),
|
||||
);
|
||||
})
|
||||
.toList(),
|
||||
),
|
||||
),
|
||||
})
|
||||
.toList(),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
SizedBox(height: layout.controlSpacing),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
@@ -620,23 +631,24 @@ class _FullScreenBlurOverlayState extends State<FullScreenBlurOverlay> {
|
||||
final defS = isDarkTheme
|
||||
? CardColorService.defaultSecondary
|
||||
: CardColorService.defaultSecondaryLight;
|
||||
dash.setState(() {
|
||||
dash.tempPrimary = defP;
|
||||
dash.tempSecondary = defS;
|
||||
dash.tempPrimaryHSV = HSVColor.fromColor(defP);
|
||||
dash.tempSecondaryHSV = HSVColor.fromColor(defS);
|
||||
dash.tempLightGradientType =
|
||||
CardColorService.defaultGradientLight;
|
||||
dash.tempDarkGradientType =
|
||||
CardColorService.defaultGradientDark;
|
||||
});
|
||||
dash.tempPrimary = defP;
|
||||
dash.tempSecondary = defS;
|
||||
dash.tempPrimaryHSV = HSVColor.fromColor(defP);
|
||||
dash.tempSecondaryHSV = HSVColor.fromColor(defS);
|
||||
dash.tempLightGradientType =
|
||||
CardColorService.defaultGradientLight;
|
||||
dash.tempDarkGradientType =
|
||||
CardColorService.defaultGradientDark;
|
||||
setPanelState(() {});
|
||||
dash.overlayEntry?.markNeedsBuild();
|
||||
},
|
||||
icon: const Icon(Icons.restart_alt_rounded, size: 15),
|
||||
icon: Icon(
|
||||
Icons.restart_alt_rounded,
|
||||
size: layout.compact ? 14 : 15,
|
||||
),
|
||||
label: Text(
|
||||
s.reset,
|
||||
style: const TextStyle(fontSize: 13),
|
||||
style: TextStyle(fontSize: layout.compact ? 12 : 13),
|
||||
),
|
||||
style: OutlinedButton.styleFrom(
|
||||
foregroundColor: Theme.of(
|
||||
@@ -647,7 +659,9 @@ class _FullScreenBlurOverlayState extends State<FullScreenBlurOverlay> {
|
||||
widget.context,
|
||||
).colorScheme.onSurface.withOpacity(0.2),
|
||||
),
|
||||
padding: const EdgeInsets.symmetric(vertical: 10),
|
||||
padding: EdgeInsets.symmetric(
|
||||
vertical: layout.buttonVerticalPadding,
|
||||
),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
@@ -662,16 +676,18 @@ class _FullScreenBlurOverlayState extends State<FullScreenBlurOverlay> {
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: const Color(0xFF7C6DED),
|
||||
foregroundColor: Colors.white,
|
||||
padding: const EdgeInsets.symmetric(vertical: 10),
|
||||
padding: EdgeInsets.symmetric(
|
||||
vertical: layout.buttonVerticalPadding,
|
||||
),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
),
|
||||
child: Text(
|
||||
s.apply,
|
||||
style: const TextStyle(
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.w700,
|
||||
fontSize: 14,
|
||||
fontSize: layout.compact ? 13 : 14,
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -770,3 +786,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;
|
||||
}
|
||||
|
||||
@@ -94,7 +94,7 @@ class _FilterChip extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final chipColor = color ?? AppColors.accent;
|
||||
final chipColor = color ?? const Color(0xFF7C6DED);
|
||||
final isDark = Theme.of(context).brightness == Brightness.dark;
|
||||
|
||||
return GestureDetector(
|
||||
|
||||
@@ -52,7 +52,7 @@ class SearchBar extends StatelessWidget {
|
||||
),
|
||||
focusedBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
borderSide: const BorderSide(color: Color(0xFF7C6DED), width: 1.5),
|
||||
borderSide: BorderSide(color: const Color(0xFF7C6DED), width: 1.5),
|
||||
),
|
||||
border: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
|
||||
@@ -9,6 +9,7 @@ import '../../../core/l10n/locale_provider.dart';
|
||||
import '../../../shared/models/transaction.dart';
|
||||
import '../../../shared/models/account.dart';
|
||||
import '../../../shared/providers/amount_format_provider.dart';
|
||||
import '../../../shared/providers/category_provider.dart';
|
||||
import '../../../shared/utils/currency_utils.dart';
|
||||
import '../../../shared/widgets/byn_sign.dart';
|
||||
import '../../settings/provider.dart';
|
||||
@@ -29,7 +30,9 @@ class TransactionTile extends ConsumerWidget {
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final s = ref.watch(stringsProvider);
|
||||
final isRu = s.locale == AppLocale.ru;
|
||||
final fmt = ref.watch(amountFormatProvider);
|
||||
final catalog = ref.watch(categoryCatalogProvider);
|
||||
final isTransfer = transaction.category == 'Transfer';
|
||||
final isIncome = transaction.type == TransactionType.income;
|
||||
final color = isTransfer
|
||||
@@ -37,10 +40,11 @@ class TransactionTile extends ConsumerWidget {
|
||||
: (isIncome ? AppColors.income : AppColors.expense);
|
||||
final catColor = isTransfer
|
||||
? const Color(0xFF7C6DED)
|
||||
: (AppCategories.colors[transaction.category] ?? AppColors.accent);
|
||||
: catalog.colorFor(transaction.category);
|
||||
final catIcon = isTransfer
|
||||
? Icons.swap_horiz_rounded
|
||||
: (AppCategories.icons[transaction.category] ?? Icons.category_rounded);
|
||||
: catalog.iconFor(transaction.category);
|
||||
final catLabel = catalog.labelFor(transaction.category, isRu);
|
||||
|
||||
final activeAccount = ref.watch(activeAccountProvider);
|
||||
final displayCurrency =
|
||||
@@ -105,7 +109,7 @@ class TransactionTile extends ConsumerWidget {
|
||||
activeAccount,
|
||||
)
|
||||
: Text(
|
||||
s.categoryLabel(transaction.category),
|
||||
catLabel,
|
||||
style: Theme.of(context).textTheme.bodyMedium
|
||||
?.copyWith(
|
||||
fontWeight: FontWeight.w600,
|
||||
@@ -467,7 +471,7 @@ class _TransferChip extends StatelessWidget {
|
||||
label,
|
||||
style: const TextStyle(
|
||||
fontSize: 11,
|
||||
color: Color(0xFF7C6DED),
|
||||
color: const Color(0xFF7C6DED),
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
overflow: TextOverflow.ellipsis,
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import '../../shared/providers/onboarding_provider.dart';
|
||||
|
||||
class OnboardingNotifier extends Notifier<int> {
|
||||
@override
|
||||
int build() => 0;
|
||||
|
||||
void setPage(int page) => state = page;
|
||||
|
||||
Future<void> complete() async {
|
||||
final service = ref.read(onboardingServiceProvider);
|
||||
await service.completeOnboarding();
|
||||
}
|
||||
}
|
||||
|
||||
final onboardingProvider = NotifierProvider<OnboardingNotifier, int>(
|
||||
OnboardingNotifier.new,
|
||||
);
|
||||
@@ -0,0 +1,164 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import '../../core/l10n/locale_provider.dart';
|
||||
import '../../core/services/haptic_service.dart';
|
||||
import 'provider.dart';
|
||||
import 'widgets/fade_slide_in.dart';
|
||||
import 'widgets/onboarding_page.dart';
|
||||
import 'widgets/onboarding_page_indicator.dart';
|
||||
|
||||
class OnboardingScreen extends ConsumerStatefulWidget {
|
||||
const OnboardingScreen({super.key});
|
||||
|
||||
@override
|
||||
ConsumerState<OnboardingScreen> createState() => _OnboardingScreenState();
|
||||
}
|
||||
|
||||
class _OnboardingScreenState extends ConsumerState<OnboardingScreen> {
|
||||
final _controller = PageController();
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_controller.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _onPageChanged(int page) {
|
||||
ref.read(onboardingProvider.notifier).setPage(page);
|
||||
HapticService.light();
|
||||
if (page == 4) {
|
||||
HapticService.medium();
|
||||
ref.read(onboardingProvider.notifier).complete();
|
||||
Future.delayed(const Duration(milliseconds: 150), () {
|
||||
if (mounted) context.go('/dashboard');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final s = ref.watch(stringsProvider);
|
||||
final currentPage = ref.watch(onboardingProvider);
|
||||
|
||||
return Scaffold(
|
||||
body: SafeArea(
|
||||
child: Column(
|
||||
children: [
|
||||
Expanded(
|
||||
child: PageView(
|
||||
controller: _controller,
|
||||
onPageChanged: _onPageChanged,
|
||||
children: [
|
||||
OnboardingPage.welcome(
|
||||
welcomeText: s.onboardingWelcome,
|
||||
isActive: currentPage == 0,
|
||||
),
|
||||
OnboardingPage.content(
|
||||
icon: Icons.currency_exchange_rounded,
|
||||
headline: s.onboardingMultiCurrencyTitle,
|
||||
description: s.onboardingMultiCurrencyBody,
|
||||
isActive: currentPage == 1,
|
||||
),
|
||||
OnboardingPage.content(
|
||||
icon: Icons.credit_card_rounded,
|
||||
headline: s.onboardingCardsTitle,
|
||||
description: s.onboardingCardsBody,
|
||||
isActive: currentPage == 2,
|
||||
),
|
||||
_ReadyPage(isActive: currentPage == 3),
|
||||
const SizedBox.shrink(),
|
||||
],
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(bottom: 48),
|
||||
child: OnboardingPageIndicator(
|
||||
current: currentPage,
|
||||
count: 5,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _ReadyPage extends ConsumerWidget {
|
||||
final bool isActive;
|
||||
|
||||
const _ReadyPage({required this.isActive});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final s = ref.watch(stringsProvider);
|
||||
final colorScheme = Theme.of(context).colorScheme;
|
||||
|
||||
return Center(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 32),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
FadeSlideIn(
|
||||
active: isActive,
|
||||
child: Icon(
|
||||
Icons.waving_hand_rounded,
|
||||
size: 72,
|
||||
color: colorScheme.primary,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 28),
|
||||
FadeSlideIn(
|
||||
active: isActive,
|
||||
delay: const Duration(milliseconds: 150),
|
||||
child: Text(
|
||||
s.onboardingReadyTitle,
|
||||
textAlign: TextAlign.center,
|
||||
style: Theme.of(context).textTheme.headlineMedium?.copyWith(
|
||||
fontWeight: FontWeight.bold,
|
||||
color: colorScheme.onSurface,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
FadeSlideIn(
|
||||
active: isActive,
|
||||
delay: const Duration(milliseconds: 300),
|
||||
child: Text(
|
||||
s.onboardingReadyBody,
|
||||
textAlign: TextAlign.center,
|
||||
style: Theme.of(context).textTheme.bodyLarge?.copyWith(
|
||||
color: colorScheme.onSurface.withOpacity(0.5),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
FadeSlideIn(
|
||||
active: isActive,
|
||||
delay: const Duration(milliseconds: 450),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Text(
|
||||
s.onboardingSwipeRight,
|
||||
style: Theme.of(context).textTheme.titleMedium?.copyWith(
|
||||
color: colorScheme.primary,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Icon(
|
||||
Icons.arrow_forward_rounded,
|
||||
color: colorScheme.primary,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
import 'dart:async';
|
||||
import 'dart:math';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:sensors_plus/sensors_plus.dart';
|
||||
|
||||
class CashaShimmerText extends StatefulWidget {
|
||||
final String text;
|
||||
final TextStyle? style;
|
||||
|
||||
const CashaShimmerText({
|
||||
required this.text,
|
||||
this.style,
|
||||
super.key,
|
||||
});
|
||||
|
||||
@override
|
||||
State<CashaShimmerText> createState() => _CashaShimmerTextState();
|
||||
}
|
||||
|
||||
class _CashaShimmerTextState extends State<CashaShimmerText>
|
||||
with SingleTickerProviderStateMixin {
|
||||
late final AnimationController _controller;
|
||||
double _tiltX = 0.0, _tiltY = 0.0;
|
||||
double _targetTiltX = 0.0, _targetTiltY = 0.0;
|
||||
StreamSubscription<AccelerometerEvent>? _sub;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_controller = AnimationController(
|
||||
vsync: this,
|
||||
duration: const Duration(seconds: 5),
|
||||
)..repeat();
|
||||
|
||||
_sub = accelerometerEventStream(
|
||||
samplingPeriod: const Duration(milliseconds: 50),
|
||||
).listen((e) {
|
||||
_targetTiltY = (e.x / 9.8).clamp(-1.0, 1.0);
|
||||
_targetTiltX = ((e.y / 9.8) - 1.0).clamp(-1.0, 1.0);
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_controller.dispose();
|
||||
_sub?.cancel();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final primary = Theme.of(context).colorScheme.primary;
|
||||
final secondary = Theme.of(context).colorScheme.secondary;
|
||||
|
||||
return AnimatedBuilder(
|
||||
animation: _controller,
|
||||
builder: (context, child) {
|
||||
_tiltX += (_targetTiltX - _tiltX) * 0.15;
|
||||
_tiltY += (_targetTiltY - _tiltY) * 0.15;
|
||||
|
||||
final t = _controller.value;
|
||||
final shimmer = sin(t * 2 * pi) * 0.08;
|
||||
|
||||
final gx = (_tiltY + shimmer).clamp(-1.0, 1.0);
|
||||
final gy = (_tiltX + shimmer * 0.3).clamp(-1.0, 1.0);
|
||||
|
||||
return Transform(
|
||||
alignment: Alignment.center,
|
||||
transform: Matrix4.identity()
|
||||
..setEntry(3, 2, 0.001)
|
||||
..rotateX(_tiltX * 0.85)
|
||||
..rotateY(_tiltY * 0.85),
|
||||
child: ShaderMask(
|
||||
shaderCallback: (bounds) {
|
||||
return LinearGradient(
|
||||
begin: Alignment(gx - 0.8, gy - 0.4),
|
||||
end: Alignment(gx + 0.8, gy + 0.4),
|
||||
colors: [
|
||||
primary.withOpacity(0.7),
|
||||
primary,
|
||||
secondary,
|
||||
Colors.white,
|
||||
secondary,
|
||||
primary,
|
||||
primary.withOpacity(0.7),
|
||||
],
|
||||
stops: [0.0, 0.15, 0.35, 0.5, 0.65, 0.85, 1.0],
|
||||
).createShader(bounds);
|
||||
},
|
||||
blendMode: BlendMode.srcIn,
|
||||
child: child,
|
||||
),
|
||||
);
|
||||
},
|
||||
child: Text(
|
||||
widget.text,
|
||||
style: widget.style?.copyWith(color: Colors.white),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class FadeSlideIn extends StatefulWidget {
|
||||
final bool active;
|
||||
final Duration delay;
|
||||
final Duration duration;
|
||||
final Widget child;
|
||||
|
||||
const FadeSlideIn({
|
||||
required this.active,
|
||||
required this.child,
|
||||
this.delay = Duration.zero,
|
||||
this.duration = const Duration(milliseconds: 500),
|
||||
super.key,
|
||||
});
|
||||
|
||||
@override
|
||||
State<FadeSlideIn> createState() => _FadeSlideInState();
|
||||
}
|
||||
|
||||
class _FadeSlideInState extends State<FadeSlideIn>
|
||||
with SingleTickerProviderStateMixin {
|
||||
late final AnimationController _controller;
|
||||
late final Animation<double> _opacity;
|
||||
late final Animation<Offset> _offset;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_controller = AnimationController(
|
||||
vsync: this,
|
||||
duration: widget.duration,
|
||||
);
|
||||
_opacity = Tween<double>(begin: 0.0, end: 1.0).animate(
|
||||
CurvedAnimation(parent: _controller, curve: Curves.easeOut),
|
||||
);
|
||||
_offset = Tween<Offset>(
|
||||
begin: const Offset(0, 0.15),
|
||||
end: Offset.zero,
|
||||
).animate(CurvedAnimation(parent: _controller, curve: Curves.easeOut));
|
||||
}
|
||||
|
||||
@override
|
||||
void didUpdateWidget(covariant FadeSlideIn oldWidget) {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
if (widget.active && !oldWidget.active) {
|
||||
_controller.reset();
|
||||
Future.delayed(widget.delay, () {
|
||||
if (mounted) _controller.forward();
|
||||
});
|
||||
} else if (!widget.active && oldWidget.active) {
|
||||
_controller.reset();
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_controller.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return AnimatedBuilder(
|
||||
animation: _controller,
|
||||
builder: (context, child) {
|
||||
return Opacity(
|
||||
opacity: _opacity.value,
|
||||
child: FractionalTranslation(
|
||||
translation: _offset.value,
|
||||
child: child,
|
||||
),
|
||||
);
|
||||
},
|
||||
child: widget.child,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'casha_shimmer_text.dart';
|
||||
import 'fade_slide_in.dart';
|
||||
|
||||
class OnboardingPage extends StatelessWidget {
|
||||
final IconData? icon;
|
||||
final String? headline;
|
||||
final String? description;
|
||||
final String? welcomeText;
|
||||
final bool isWelcomePage;
|
||||
final bool isActive;
|
||||
|
||||
const OnboardingPage.welcome({
|
||||
required this.welcomeText,
|
||||
this.isActive = false,
|
||||
super.key,
|
||||
}) : icon = null,
|
||||
headline = null,
|
||||
description = null,
|
||||
isWelcomePage = true;
|
||||
|
||||
const OnboardingPage.content({
|
||||
required this.icon,
|
||||
required this.headline,
|
||||
required this.description,
|
||||
this.isActive = false,
|
||||
super.key,
|
||||
}) : welcomeText = null,
|
||||
isWelcomePage = false;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (isWelcomePage) {
|
||||
final colorScheme = Theme.of(context).colorScheme;
|
||||
return Center(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(
|
||||
welcomeText!,
|
||||
style: Theme.of(context).textTheme.titleMedium?.copyWith(
|
||||
fontWeight: FontWeight.w300,
|
||||
color: colorScheme.onSurface.withOpacity(0.4),
|
||||
letterSpacing: 2,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
CashaShimmerText(
|
||||
text: 'Casha',
|
||||
style: Theme.of(context).textTheme.displayLarge?.copyWith(
|
||||
fontSize: 72,
|
||||
fontWeight: FontWeight.w900,
|
||||
letterSpacing: -1,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
final colorScheme = Theme.of(context).colorScheme;
|
||||
return Center(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 32),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
FadeSlideIn(
|
||||
active: isActive,
|
||||
child: Container(
|
||||
padding: const EdgeInsets.all(24),
|
||||
decoration: BoxDecoration(
|
||||
color: colorScheme.primary.withOpacity(0.12),
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
child: Icon(
|
||||
icon,
|
||||
size: 64,
|
||||
color: colorScheme.primary,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 32),
|
||||
FadeSlideIn(
|
||||
active: isActive,
|
||||
delay: const Duration(milliseconds: 150),
|
||||
child: Text(
|
||||
headline!,
|
||||
textAlign: TextAlign.center,
|
||||
style: Theme.of(context).textTheme.headlineSmall?.copyWith(
|
||||
fontWeight: FontWeight.bold,
|
||||
color: colorScheme.onSurface,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
FadeSlideIn(
|
||||
active: isActive,
|
||||
delay: const Duration(milliseconds: 300),
|
||||
child: Text(
|
||||
description!,
|
||||
textAlign: TextAlign.center,
|
||||
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
|
||||
color: colorScheme.onSurface.withOpacity(0.6),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class OnboardingPageIndicator extends StatelessWidget {
|
||||
final int current;
|
||||
final int count;
|
||||
|
||||
const OnboardingPageIndicator({
|
||||
required this.current,
|
||||
required this.count,
|
||||
super.key,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final color = Theme.of(context).colorScheme.primary;
|
||||
final outlineColor = Theme.of(context).colorScheme.secondary;
|
||||
return Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: List.generate(count, (i) {
|
||||
final isActive = i == current;
|
||||
final isLast = i == count - 1;
|
||||
return AnimatedContainer(
|
||||
duration: const Duration(milliseconds: 200),
|
||||
margin: const EdgeInsets.symmetric(horizontal: 4),
|
||||
width: isActive ? 24 : 8,
|
||||
height: 8,
|
||||
decoration: BoxDecoration(
|
||||
color: isActive ? color : color.withOpacity(0.3),
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
border: isLast && !isActive
|
||||
? Border.all(color: outlineColor, width: 1.5)
|
||||
: null,
|
||||
),
|
||||
);
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,700 @@
|
||||
import 'dart:async';
|
||||
|
||||
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 '../../../core/utils/result.dart';
|
||||
import '../../../shared/models/app_category.dart';
|
||||
import '../../../shared/models/transaction.dart';
|
||||
import '../../../shared/providers/category_provider.dart';
|
||||
import '../../../shared/services/translation_service.dart';
|
||||
import '../../../shared/widgets/error_snackbar.dart';
|
||||
|
||||
Future<void> showCategoryEditor(
|
||||
BuildContext context, {
|
||||
AppCategory? existing,
|
||||
}) {
|
||||
return showModalBottomSheet<void>(
|
||||
context: context,
|
||||
isScrollControlled: true,
|
||||
backgroundColor: Colors.transparent,
|
||||
builder: (_) => CategoryEditorSheet(existing: existing),
|
||||
);
|
||||
}
|
||||
|
||||
class CategoryEditorSheet extends ConsumerStatefulWidget {
|
||||
final AppCategory? existing;
|
||||
|
||||
const CategoryEditorSheet({super.key, this.existing});
|
||||
|
||||
@override
|
||||
ConsumerState<CategoryEditorSheet> createState() =>
|
||||
_CategoryEditorSheetState();
|
||||
}
|
||||
|
||||
class _CategoryEditorSheetState extends ConsumerState<CategoryEditorSheet> {
|
||||
late final TextEditingController _enController;
|
||||
late final TextEditingController _ruController;
|
||||
late TransactionType _type;
|
||||
late String _iconName;
|
||||
late int _colorValue;
|
||||
|
||||
String? _enSuggestion;
|
||||
String? _ruSuggestion;
|
||||
bool _translatingEn = false;
|
||||
bool _translatingRu = false;
|
||||
bool _saving = false;
|
||||
DateTime? _lastTranslateTime;
|
||||
bool _enOverflow = false;
|
||||
bool _ruOverflow = false;
|
||||
Timer? _enOverflowTimer;
|
||||
Timer? _ruOverflowTimer;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
final existing = widget.existing;
|
||||
_enController = TextEditingController(text: existing?.labelEn ?? '');
|
||||
_ruController = TextEditingController(text: existing?.labelRu ?? '');
|
||||
_type = existing?.type == TransactionType.income
|
||||
? TransactionType.income
|
||||
: TransactionType.expense;
|
||||
_iconName = existing?.iconName ?? kCategoryIcons.keys.first;
|
||||
_colorValue = existing?.color.value ?? kCategoryColors.first.value;
|
||||
_enController.addListener(_onEnChanged);
|
||||
_ruController.addListener(_onRuChanged);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_enOverflowTimer?.cancel();
|
||||
_ruOverflowTimer?.cancel();
|
||||
_enController.dispose();
|
||||
_ruController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _onEnChanged() {
|
||||
if (_enController.text.trim().isNotEmpty && _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() {
|
||||
if (_ruController.text.trim().isNotEmpty && _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 {
|
||||
final source = _enController.text.trim();
|
||||
if (source.isEmpty) return;
|
||||
setState(() => _translatingRu = true);
|
||||
final service = ref.read(translationServiceProvider);
|
||||
TranslationResult? result;
|
||||
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;
|
||||
setState(() {
|
||||
_translatingRu = false;
|
||||
_ruSuggestion = result?.text;
|
||||
});
|
||||
if (result == null) {
|
||||
showErrorSnackbar(context, ref.read(stringsProvider).translationFailed);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _translateToEn() async {
|
||||
final source = _ruController.text.trim();
|
||||
if (source.isEmpty) return;
|
||||
setState(() => _translatingEn = true);
|
||||
final service = ref.read(translationServiceProvider);
|
||||
TranslationResult? result;
|
||||
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;
|
||||
setState(() {
|
||||
_translatingEn = false;
|
||||
_enSuggestion = result?.text;
|
||||
});
|
||||
if (result == null) {
|
||||
showErrorSnackbar(context, ref.read(stringsProvider).translationFailed);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _save() async {
|
||||
final s = ref.read(stringsProvider);
|
||||
if (_enController.text.trim().isEmpty &&
|
||||
_ruController.text.trim().isEmpty) {
|
||||
showErrorSnackbar(context, s.categoryNameRequired);
|
||||
return;
|
||||
}
|
||||
setState(() => _saving = true);
|
||||
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 existing = widget.existing;
|
||||
final result = existing != null && existing.id != null
|
||||
? await actions.edit(
|
||||
id: existing.id!,
|
||||
type: _type,
|
||||
labelEn: labelEn,
|
||||
labelRu: labelRu,
|
||||
iconName: _iconName,
|
||||
colorValue: _colorValue,
|
||||
)
|
||||
: await actions.create(
|
||||
type: _type,
|
||||
labelEn: labelEn,
|
||||
labelRu: labelRu,
|
||||
iconName: _iconName,
|
||||
colorValue: _colorValue,
|
||||
);
|
||||
if (!mounted) return;
|
||||
setState(() => _saving = false);
|
||||
if (result case Failure(message: final message)) {
|
||||
showErrorSnackbar(context, message);
|
||||
} else {
|
||||
Navigator.of(context).pop();
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final s = ref.watch(stringsProvider);
|
||||
final theme = Theme.of(context);
|
||||
final bottomInset = MediaQuery.of(context).viewInsets.bottom;
|
||||
|
||||
return Padding(
|
||||
padding: EdgeInsets.only(bottom: bottomInset),
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
color: theme.scaffoldBackgroundColor,
|
||||
borderRadius: const BorderRadius.vertical(top: Radius.circular(24)),
|
||||
),
|
||||
child: SafeArea(
|
||||
top: false,
|
||||
child: SingleChildScrollView(
|
||||
padding: const EdgeInsets.fromLTRB(20, 12, 20, 20),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Center(
|
||||
child: Container(
|
||||
width: 40,
|
||||
height: 4,
|
||||
decoration: BoxDecoration(
|
||||
color: theme.colorScheme.onSurface.withOpacity(0.2),
|
||||
borderRadius: BorderRadius.circular(2),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 28),
|
||||
Text(
|
||||
widget.existing != null ? s.editCategory : s.newCategory,
|
||||
style: theme.textTheme.titleLarge?.copyWith(
|
||||
fontWeight: FontWeight.w700,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
_TypeToggle(
|
||||
type: _type,
|
||||
onChanged: (t) => setState(() => _type = t),
|
||||
expenseLabel: s.typeExpense,
|
||||
incomeLabel: s.typeIncome,
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
_TranslatableField(
|
||||
controller: _enController,
|
||||
label: s.nameEn,
|
||||
hint: s.nameEnHint,
|
||||
suggestion: _enSuggestion,
|
||||
isTranslating: _translatingEn,
|
||||
isOverflow: _enOverflow,
|
||||
canTranslate: _ruController.text.trim().isNotEmpty,
|
||||
translatingLabel: s.translating,
|
||||
applyLabel: s.applyTranslation,
|
||||
onTranslate: _translateToEn,
|
||||
onApply: () {
|
||||
_enController.text = _enSuggestion ?? '';
|
||||
setState(() => _enSuggestion = null);
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
_TranslatableField(
|
||||
controller: _ruController,
|
||||
label: s.nameRu,
|
||||
hint: s.nameRuHint,
|
||||
suggestion: _ruSuggestion,
|
||||
isTranslating: _translatingRu,
|
||||
isOverflow: _ruOverflow,
|
||||
canTranslate: _enController.text.trim().isNotEmpty,
|
||||
translatingLabel: s.translating,
|
||||
applyLabel: s.applyTranslation,
|
||||
onTranslate: _translateToRu,
|
||||
onApply: () {
|
||||
_ruController.text = _ruSuggestion ?? '';
|
||||
setState(() => _ruSuggestion = null);
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
Text(
|
||||
s.categoryIcon,
|
||||
style: theme.textTheme.bodyMedium?.copyWith(
|
||||
fontWeight: FontWeight.w600,
|
||||
color: theme.colorScheme.onSurface.withOpacity(0.7),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
_IconGrid(
|
||||
selected: _iconName,
|
||||
color: Color(_colorValue),
|
||||
onSelected: (name) {
|
||||
HapticService.light();
|
||||
setState(() => _iconName = name);
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
Text(
|
||||
s.categoryColor,
|
||||
style: theme.textTheme.bodyMedium?.copyWith(
|
||||
fontWeight: FontWeight.w600,
|
||||
color: theme.colorScheme.onSurface.withOpacity(0.7),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
_ColorRow(
|
||||
selected: _colorValue,
|
||||
onSelected: (value) {
|
||||
HapticService.light();
|
||||
setState(() => _colorValue = value);
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
SizedBox(
|
||||
width: double.infinity,
|
||||
child: FilledButton(
|
||||
onPressed: _saving ? null : _save,
|
||||
style: FilledButton.styleFrom(
|
||||
backgroundColor: const Color(0xFF7C6DED),
|
||||
padding: const EdgeInsets.symmetric(vertical: 16),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(14),
|
||||
),
|
||||
),
|
||||
child: _saving
|
||||
? const SizedBox(
|
||||
width: 20,
|
||||
height: 20,
|
||||
child: CircularProgressIndicator(
|
||||
strokeWidth: 2,
|
||||
color: Colors.white,
|
||||
),
|
||||
)
|
||||
: Text(
|
||||
s.save,
|
||||
style: const TextStyle(
|
||||
color: Colors.white,
|
||||
fontWeight: FontWeight.w700,
|
||||
fontSize: 16,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _TypeToggle extends StatelessWidget {
|
||||
final TransactionType type;
|
||||
final ValueChanged<TransactionType> onChanged;
|
||||
final String expenseLabel;
|
||||
final String incomeLabel;
|
||||
|
||||
const _TypeToggle({
|
||||
required this.type,
|
||||
required this.onChanged,
|
||||
required this.expenseLabel,
|
||||
required this.incomeLabel,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(4),
|
||||
decoration: BoxDecoration(
|
||||
color: theme.colorScheme.surface,
|
||||
borderRadius: BorderRadius.circular(14),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
_segment(
|
||||
context,
|
||||
label: expenseLabel,
|
||||
selected: type == TransactionType.expense,
|
||||
color: AppColors.expense,
|
||||
onTap: () => onChanged(TransactionType.expense),
|
||||
),
|
||||
_segment(
|
||||
context,
|
||||
label: incomeLabel,
|
||||
selected: type == TransactionType.income,
|
||||
color: AppColors.income,
|
||||
onTap: () => onChanged(TransactionType.income),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _segment(
|
||||
BuildContext context, {
|
||||
required String label,
|
||||
required bool selected,
|
||||
required Color color,
|
||||
required VoidCallback onTap,
|
||||
}) {
|
||||
return Expanded(
|
||||
child: GestureDetector(
|
||||
onTap: onTap,
|
||||
child: AnimatedContainer(
|
||||
duration: const Duration(milliseconds: 200),
|
||||
padding: const EdgeInsets.symmetric(vertical: 12),
|
||||
decoration: BoxDecoration(
|
||||
color: selected ? color.withOpacity(0.18) : Colors.transparent,
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
),
|
||||
alignment: Alignment.center,
|
||||
child: Text(
|
||||
label,
|
||||
style: TextStyle(
|
||||
color: selected
|
||||
? color
|
||||
: Theme.of(context).colorScheme.onSurface.withOpacity(0.6),
|
||||
fontWeight: selected ? FontWeight.w700 : FontWeight.w500,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _TranslatableField extends StatelessWidget {
|
||||
final TextEditingController controller;
|
||||
final String label;
|
||||
final String hint;
|
||||
final String? suggestion;
|
||||
final bool isTranslating;
|
||||
final bool canTranslate;
|
||||
final String translatingLabel;
|
||||
final String applyLabel;
|
||||
final bool isOverflow;
|
||||
final VoidCallback onTranslate;
|
||||
final VoidCallback onApply;
|
||||
|
||||
const _TranslatableField({
|
||||
required this.controller,
|
||||
required this.label,
|
||||
required this.hint,
|
||||
required this.suggestion,
|
||||
required this.isTranslating,
|
||||
required this.isOverflow,
|
||||
required this.canTranslate,
|
||||
required this.translatingLabel,
|
||||
required this.applyLabel,
|
||||
required this.onTranslate,
|
||||
required this.onApply,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
final isDark = theme.brightness == Brightness.dark;
|
||||
return AnimatedBuilder(
|
||||
animation: controller,
|
||||
builder: (context, _) {
|
||||
final isEmpty = controller.text.trim().isEmpty;
|
||||
final showGhost = isEmpty && suggestion != null && !isTranslating;
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
label,
|
||||
style: theme.textTheme.bodySmall?.copyWith(
|
||||
color: theme.colorScheme.onSurface.withOpacity(0.6),
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 6),
|
||||
Container(
|
||||
decoration: BoxDecoration(
|
||||
color: theme.colorScheme.surface,
|
||||
borderRadius: BorderRadius.circular(14),
|
||||
border: isOverflow
|
||||
? Border.all(color: AppColors.expense, width: 1.5)
|
||||
: isDark
|
||||
? null
|
||||
: Border.all(color: const Color(0xFFDDDDEE), width: 1),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Stack(
|
||||
children: [
|
||||
if (showGhost)
|
||||
Positioned.fill(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 14,
|
||||
),
|
||||
child: Align(
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
suggestion!,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: theme.textTheme.bodyLarge?.copyWith(
|
||||
color: theme.colorScheme.onSurface
|
||||
.withOpacity(0.28),
|
||||
fontStyle: FontStyle.italic,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
TextField(
|
||||
controller: controller,
|
||||
style: theme.textTheme.bodyLarge,
|
||||
maxLength: 20,
|
||||
decoration: InputDecoration(
|
||||
hintText: showGhost ? '' : hint,
|
||||
isDense: true,
|
||||
filled: false,
|
||||
counterText: '',
|
||||
enabledBorder: InputBorder.none,
|
||||
focusedBorder: InputBorder.none,
|
||||
border: InputBorder.none,
|
||||
contentPadding: const EdgeInsets.symmetric(
|
||||
horizontal: 14,
|
||||
vertical: 14,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
_trailing(context),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Widget _trailing(BuildContext context) {
|
||||
if (isTranslating) {
|
||||
return const Padding(
|
||||
padding: EdgeInsets.symmetric(horizontal: 14),
|
||||
child: SizedBox(
|
||||
width: 18,
|
||||
height: 18,
|
||||
child: CircularProgressIndicator(strokeWidth: 2),
|
||||
),
|
||||
);
|
||||
}
|
||||
final isEmpty = controller.text.trim().isEmpty;
|
||||
if (isEmpty && suggestion != null) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(right: 6),
|
||||
child: TextButton(
|
||||
onPressed: onApply,
|
||||
style: TextButton.styleFrom(
|
||||
foregroundColor: const Color(0xFF7C6DED),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 10),
|
||||
minimumSize: const Size(0, 36),
|
||||
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
|
||||
),
|
||||
child: Text(
|
||||
applyLabel,
|
||||
style: const TextStyle(fontWeight: FontWeight.w700),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
if (isEmpty && canTranslate) {
|
||||
return IconButton(
|
||||
onPressed: onTranslate,
|
||||
icon: const Icon(Icons.translate_rounded, size: 20),
|
||||
color: const Color(0xFF7C6DED),
|
||||
tooltip: '',
|
||||
);
|
||||
}
|
||||
return const SizedBox(width: 8);
|
||||
}
|
||||
}
|
||||
|
||||
class _IconGrid extends StatelessWidget {
|
||||
final String selected;
|
||||
final Color color;
|
||||
final ValueChanged<String> onSelected;
|
||||
|
||||
const _IconGrid({
|
||||
required this.selected,
|
||||
required this.color,
|
||||
required this.onSelected,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
return Center(
|
||||
child: Wrap(
|
||||
alignment: WrapAlignment.center,
|
||||
spacing: 10,
|
||||
runSpacing: 10,
|
||||
children: kCategoryIcons.entries.map((entry) {
|
||||
final isSelected = entry.key == selected;
|
||||
return GestureDetector(
|
||||
onTap: () => onSelected(entry.key),
|
||||
child: Container(
|
||||
width: 48,
|
||||
height: 48,
|
||||
decoration: BoxDecoration(
|
||||
color: isSelected
|
||||
? color.withOpacity(0.2)
|
||||
: theme.colorScheme.surface,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
border: Border.all(
|
||||
color: isSelected ? color : Colors.transparent,
|
||||
width: 1.5,
|
||||
),
|
||||
),
|
||||
child: Icon(
|
||||
entry.value,
|
||||
color: isSelected
|
||||
? color
|
||||
: theme.colorScheme.onSurface.withOpacity(0.6),
|
||||
size: 22,
|
||||
),
|
||||
),
|
||||
);
|
||||
}).toList(),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _ColorRow extends StatelessWidget {
|
||||
final int selected;
|
||||
final ValueChanged<int> onSelected;
|
||||
|
||||
const _ColorRow({required this.selected, required this.onSelected});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Center(
|
||||
child: Wrap(
|
||||
alignment: WrapAlignment.center,
|
||||
spacing: 12,
|
||||
runSpacing: 12,
|
||||
children: kCategoryColors.map((color) {
|
||||
final isSelected = color.value == selected;
|
||||
return GestureDetector(
|
||||
onTap: () => onSelected(color.value),
|
||||
child: Container(
|
||||
width: 40,
|
||||
height: 40,
|
||||
decoration: BoxDecoration(
|
||||
color: color,
|
||||
shape: BoxShape.circle,
|
||||
border: Border.all(
|
||||
color: isSelected ? Colors.white : Colors.transparent,
|
||||
width: 3,
|
||||
),
|
||||
boxShadow: isSelected
|
||||
? [
|
||||
BoxShadow(
|
||||
color: color.withOpacity(0.5),
|
||||
blurRadius: 8,
|
||||
spreadRadius: 1,
|
||||
),
|
||||
]
|
||||
: null,
|
||||
),
|
||||
child: isSelected
|
||||
? const Icon(Icons.check_rounded, color: Colors.white, size: 20)
|
||||
: null,
|
||||
),
|
||||
);
|
||||
}).toList(),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,267 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import '../../../core/constants.dart';
|
||||
import '../../../core/l10n/app_strings.dart';
|
||||
import '../../../core/l10n/locale_provider.dart';
|
||||
import '../../../core/services/haptic_service.dart';
|
||||
import '../../../shared/models/app_category.dart';
|
||||
import '../../../shared/models/transaction.dart';
|
||||
import '../../../shared/providers/category_provider.dart';
|
||||
import 'category_editor_sheet.dart';
|
||||
|
||||
class CategoryManagerScreen extends ConsumerWidget {
|
||||
const CategoryManagerScreen({super.key});
|
||||
|
||||
Future<void> _confirmDelete(
|
||||
BuildContext context,
|
||||
WidgetRef ref,
|
||||
AppCategory category,
|
||||
) async {
|
||||
final s = ref.read(stringsProvider);
|
||||
final confirmed = await showDialog<bool>(
|
||||
context: context,
|
||||
builder: (ctx) => AlertDialog(
|
||||
title: Text(s.deleteCategoryConfirm),
|
||||
content: Text(s.deleteCategoryWarning),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(ctx, false),
|
||||
child: Text(s.cancel),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(ctx, true),
|
||||
style: TextButton.styleFrom(foregroundColor: AppColors.expense),
|
||||
child: Text(s.delete),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
if (confirmed == true && category.id != null) {
|
||||
HapticService.medium();
|
||||
await ref.read(categoryActionsProvider).remove(category.id!);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final s = ref.watch(stringsProvider);
|
||||
final isRu = s.locale == AppLocale.ru;
|
||||
final catalog = ref.watch(categoryCatalogProvider);
|
||||
final custom = catalog.custom;
|
||||
final defaults = catalog.all.where((c) => !c.isCustom).toList();
|
||||
|
||||
return Scaffold(
|
||||
backgroundColor: Theme.of(context).scaffoldBackgroundColor,
|
||||
appBar: AppBar(
|
||||
backgroundColor: Theme.of(context).scaffoldBackgroundColor,
|
||||
elevation: 0,
|
||||
scrolledUnderElevation: 0,
|
||||
title: Text(
|
||||
s.manageCategories,
|
||||
style: Theme.of(context).textTheme.titleLarge?.copyWith(
|
||||
fontWeight: FontWeight.w700,
|
||||
),
|
||||
),
|
||||
),
|
||||
floatingActionButton: FloatingActionButton.extended(
|
||||
onPressed: () {
|
||||
HapticService.medium();
|
||||
showCategoryEditor(context);
|
||||
},
|
||||
backgroundColor: const Color(0xFF7C6DED),
|
||||
foregroundColor: Colors.white,
|
||||
icon: const Icon(Icons.add),
|
||||
label: Text(
|
||||
s.addCategory,
|
||||
style: const TextStyle(fontWeight: FontWeight.w600),
|
||||
),
|
||||
),
|
||||
body: ListView(
|
||||
physics: const ClampingScrollPhysics(),
|
||||
padding: const EdgeInsets.fromLTRB(20, 8, 20, 100),
|
||||
children: [
|
||||
_SectionLabel(text: s.customCategories),
|
||||
const SizedBox(height: 12),
|
||||
if (custom.isEmpty)
|
||||
_EmptyState(
|
||||
title: s.noCustomCategories,
|
||||
subtitle: s.noCustomCategoriesHint,
|
||||
)
|
||||
else
|
||||
...custom.map(
|
||||
(c) => Padding(
|
||||
padding: const EdgeInsets.only(bottom: 10),
|
||||
child: _CategoryRow(
|
||||
category: c,
|
||||
isRu: isRu,
|
||||
onTap: () => showCategoryEditor(context, existing: c),
|
||||
onDelete: () => _confirmDelete(context, ref, c),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 28),
|
||||
_SectionLabel(text: s.defaultCategories),
|
||||
const SizedBox(height: 12),
|
||||
...defaults.map(
|
||||
(c) => Padding(
|
||||
padding: const EdgeInsets.only(bottom: 10),
|
||||
child: _CategoryRow(category: c, isRu: isRu),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _SectionLabel extends StatelessWidget {
|
||||
final String text;
|
||||
|
||||
const _SectionLabel({required this.text});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Text(
|
||||
text.toUpperCase(),
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
letterSpacing: 1.1,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: Theme.of(context).colorScheme.onSurface.withOpacity(0.5),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _CategoryRow extends ConsumerWidget {
|
||||
final AppCategory category;
|
||||
final bool isRu;
|
||||
final VoidCallback? onTap;
|
||||
final VoidCallback? onDelete;
|
||||
|
||||
const _CategoryRow({
|
||||
required this.category,
|
||||
required this.isRu,
|
||||
this.onTap,
|
||||
this.onDelete,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final s = ref.watch(stringsProvider);
|
||||
final theme = Theme.of(context);
|
||||
final isDark = theme.brightness == Brightness.dark;
|
||||
final isIncome = category.type == TransactionType.income;
|
||||
return GestureDetector(
|
||||
onTap: onTap,
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 12),
|
||||
decoration: BoxDecoration(
|
||||
color: theme.colorScheme.surface,
|
||||
borderRadius: BorderRadius.circular(14),
|
||||
border: isDark
|
||||
? null
|
||||
: Border.all(color: const Color(0xFFDDDDEE), width: 1),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Container(
|
||||
width: 40,
|
||||
height: 40,
|
||||
decoration: BoxDecoration(
|
||||
color: category.color.withOpacity(0.15),
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
),
|
||||
child: Icon(category.icon, color: category.color, size: 20),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
category.label(isRu),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: theme.textTheme.bodyLarge?.copyWith(
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 2),
|
||||
Text(
|
||||
isIncome ? s.income : s.expenses,
|
||||
style: theme.textTheme.bodySmall?.copyWith(
|
||||
color: (isIncome ? AppColors.income : AppColors.expense)
|
||||
.withOpacity(0.9),
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
if (onDelete != null)
|
||||
IconButton(
|
||||
onPressed: onDelete,
|
||||
icon: const Icon(Icons.delete_outline_rounded, size: 20),
|
||||
color: theme.colorScheme.onSurface.withOpacity(0.4),
|
||||
)
|
||||
else
|
||||
Icon(
|
||||
Icons.lock_outline_rounded,
|
||||
size: 18,
|
||||
color: theme.colorScheme.onSurface.withOpacity(0.25),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _EmptyState extends StatelessWidget {
|
||||
final String title;
|
||||
final String subtitle;
|
||||
|
||||
const _EmptyState({required this.title, required this.subtitle});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
return Container(
|
||||
width: double.infinity,
|
||||
padding: const EdgeInsets.symmetric(vertical: 32, horizontal: 20),
|
||||
decoration: BoxDecoration(
|
||||
color: theme.colorScheme.surface,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
border: theme.brightness == Brightness.dark
|
||||
? null
|
||||
: Border.all(color: const Color(0xFFDDDDEE), width: 1),
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
Icon(
|
||||
Icons.category_outlined,
|
||||
size: 36,
|
||||
color: theme.colorScheme.onSurface.withOpacity(0.3),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
Text(
|
||||
title,
|
||||
textAlign: TextAlign.center,
|
||||
style: theme.textTheme.bodyLarge?.copyWith(
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
subtitle,
|
||||
textAlign: TextAlign.center,
|
||||
style: theme.textTheme.bodySmall?.copyWith(
|
||||
color: theme.colorScheme.onSurface.withOpacity(0.6),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -11,34 +11,6 @@ import '../../shared/utils/currency_utils.dart';
|
||||
import '../../shared/providers/amount_format_provider.dart';
|
||||
import '../dashboard/provider.dart';
|
||||
|
||||
final budgetProvider = NotifierProvider<BudgetNotifier, double?>(
|
||||
BudgetNotifier.new,
|
||||
);
|
||||
|
||||
class BudgetNotifier extends Notifier<double?> {
|
||||
@override
|
||||
double? build() {
|
||||
final storage = ref.watch(storageServiceProvider);
|
||||
return storage.loadBudget();
|
||||
}
|
||||
|
||||
Future<void> setBudget(double? budget) async {
|
||||
final storage = ref.read(storageServiceProvider);
|
||||
await storage.saveBudget(budget);
|
||||
state = budget;
|
||||
}
|
||||
|
||||
void onCurrencyChanged(
|
||||
String oldCode,
|
||||
String newCode,
|
||||
ExchangeRateService rates,
|
||||
) {
|
||||
if (state == null) return;
|
||||
final converted = rates.convert(state!, oldCode, newCode);
|
||||
setBudget(converted);
|
||||
}
|
||||
}
|
||||
|
||||
class CurrencyInfo {
|
||||
final String symbol;
|
||||
final String code;
|
||||
@@ -131,6 +103,31 @@ final exchangeRateServiceProvider = Provider<ExchangeRateService>((ref) {
|
||||
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 {
|
||||
await ref.read(exchangeRateServiceProvider).fetchRates();
|
||||
});
|
||||
|
||||
@@ -5,7 +5,6 @@ import '../../core/l10n/locale_provider.dart';
|
||||
import '../../core/services/biometric_service.dart';
|
||||
import '../../core/services/haptic_service.dart';
|
||||
import '../dashboard/provider.dart';
|
||||
import 'provider.dart';
|
||||
import 'widgets/theme_section.dart';
|
||||
import 'widgets/card_text_color_section.dart';
|
||||
import 'widgets/haptic_section.dart';
|
||||
@@ -13,7 +12,8 @@ import 'widgets/currency_conversions_section.dart';
|
||||
import 'widgets/language_section.dart';
|
||||
import 'widgets/currency_section.dart';
|
||||
import 'widgets/amount_format_section.dart';
|
||||
import 'widgets/budget_section.dart';
|
||||
import 'widgets/categories_section.dart';
|
||||
import '../../shared/widgets/pro_subscription_card.dart';
|
||||
|
||||
class SettingsScreen extends ConsumerWidget {
|
||||
const SettingsScreen({super.key});
|
||||
@@ -111,70 +111,66 @@ class SettingsScreen extends ConsumerWidget {
|
||||
|
||||
return Scaffold(
|
||||
backgroundColor: Theme.of(context).scaffoldBackgroundColor,
|
||||
appBar: AppBar(
|
||||
title: Text(
|
||||
s.settings,
|
||||
style: Theme.of(context).textTheme.titleLarge?.copyWith(
|
||||
fontWeight: FontWeight.w700,
|
||||
color: Theme.of(context).colorScheme.onSurface,
|
||||
),
|
||||
body: SafeArea(
|
||||
child: ListView(
|
||||
physics: const ClampingScrollPhysics(),
|
||||
padding: const EdgeInsets.fromLTRB(20, 16, 20, 40),
|
||||
children: [
|
||||
const ProSubscriptionCard(),
|
||||
const SizedBox(height: 12),
|
||||
const CurrencySection(),
|
||||
const SizedBox(height: 12),
|
||||
const ThemeSection(),
|
||||
const SizedBox(height: 12),
|
||||
const LanguageSection(),
|
||||
const SizedBox(height: 12),
|
||||
const _BiometricSection(),
|
||||
const SizedBox(height: 12),
|
||||
const CardTextColorSection(),
|
||||
const SizedBox(height: 12),
|
||||
const HapticSection(),
|
||||
const SizedBox(height: 12),
|
||||
const AmountFormatSection(),
|
||||
const SizedBox(height: 12),
|
||||
const CurrencyConversionsSection(),
|
||||
const SizedBox(height: 12),
|
||||
const CategoriesSection(),
|
||||
const SizedBox(height: 24),
|
||||
Text(
|
||||
s.dangerZone,
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
letterSpacing: 1.2,
|
||||
color: const Color(0xFFE05C6B).withOpacity(0.8),
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
SizedBox(
|
||||
width: double.infinity,
|
||||
child: OutlinedButton.icon(
|
||||
onPressed: () => _confirmClearData(context, ref),
|
||||
icon: const Icon(Icons.delete_forever, color: Color(0xFFE05C6B)),
|
||||
label: Text(
|
||||
s.clearAllTransactions,
|
||||
style: const TextStyle(color: Color(0xFFE05C6B)),
|
||||
),
|
||||
style: OutlinedButton.styleFrom(
|
||||
side: BorderSide(
|
||||
color: const Color(0xFFE05C6B).withOpacity(0.5),
|
||||
),
|
||||
padding: const EdgeInsets.symmetric(vertical: 14),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 40),
|
||||
const _FooterWidget(),
|
||||
],
|
||||
),
|
||||
),
|
||||
body: ListView(
|
||||
physics: const ClampingScrollPhysics(),
|
||||
padding: const EdgeInsets.fromLTRB(20, 16, 20, 40),
|
||||
children: [
|
||||
const ThemeSection(),
|
||||
const SizedBox(height: 16),
|
||||
const CardTextColorSection(),
|
||||
const SizedBox(height: 16),
|
||||
const HapticSection(),
|
||||
const SizedBox(height: 16),
|
||||
const CurrencyConversionsSection(),
|
||||
const SizedBox(height: 16),
|
||||
const _BiometricSection(),
|
||||
const LanguageSection(),
|
||||
const SizedBox(height: 16),
|
||||
const CurrencySection(),
|
||||
const SizedBox(height: 16),
|
||||
const AmountFormatSection(),
|
||||
const SizedBox(height: 16),
|
||||
const BudgetSection(),
|
||||
const SizedBox(height: 24),
|
||||
Text(
|
||||
s.dangerZone,
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
letterSpacing: 1.2,
|
||||
color: const Color(0xFFE05C6B).withOpacity(0.8),
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
SizedBox(
|
||||
width: double.infinity,
|
||||
child: OutlinedButton.icon(
|
||||
onPressed: () => _confirmClearData(context, ref),
|
||||
icon: const Icon(Icons.delete_forever, color: Color(0xFFE05C6B)),
|
||||
label: Text(
|
||||
s.clearAllTransactions,
|
||||
style: const TextStyle(color: Color(0xFFE05C6B)),
|
||||
),
|
||||
style: OutlinedButton.styleFrom(
|
||||
side: BorderSide(
|
||||
color: const Color(0xFFE05C6B).withOpacity(0.5),
|
||||
),
|
||||
padding: const EdgeInsets.symmetric(vertical: 14),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 40),
|
||||
const _FooterWidget(),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -287,12 +283,12 @@ class _BiometricSectionState extends ConsumerState<_BiometricSection> {
|
||||
Container(
|
||||
padding: const EdgeInsets.all(10),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.accent.withOpacity(0.15),
|
||||
color: const Color(0xFF7C6DED).withOpacity(0.15),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: const Icon(
|
||||
Icons.fingerprint,
|
||||
color: AppColors.accent,
|
||||
color: const Color(0xFF7C6DED),
|
||||
size: 20,
|
||||
),
|
||||
),
|
||||
|
||||
@@ -33,12 +33,12 @@ class AmountFormatSection extends ConsumerWidget {
|
||||
Container(
|
||||
padding: const EdgeInsets.all(10),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.accent.withOpacity(0.15),
|
||||
color: const Color(0xFF7C6DED).withOpacity(0.15),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: const Icon(
|
||||
Icons.format_list_numbered_rounded,
|
||||
color: AppColors.accent,
|
||||
color: const Color(0xFF7C6DED),
|
||||
size: 20,
|
||||
),
|
||||
),
|
||||
@@ -69,11 +69,11 @@ class AmountFormatSection extends ConsumerWidget {
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: isSelected
|
||||
? AppColors.accent.withOpacity(0.2)
|
||||
? const Color(0xFF7C6DED).withOpacity(0.2)
|
||||
: Theme.of(context).scaffoldBackgroundColor,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
border: isSelected
|
||||
? Border.all(color: AppColors.accent, width: 1.5)
|
||||
? Border.all(color: const Color(0xFF7C6DED), width: 1.5)
|
||||
: (isDark
|
||||
? null
|
||||
: Border.all(
|
||||
@@ -88,7 +88,7 @@ class AmountFormatSection extends ConsumerWidget {
|
||||
format.label,
|
||||
style: TextStyle(
|
||||
color: isSelected
|
||||
? AppColors.accent
|
||||
? const Color(0xFF7C6DED)
|
||||
: Theme.of(context).colorScheme.onSurface,
|
||||
fontWeight: isSelected
|
||||
? FontWeight.w600
|
||||
|
||||
@@ -1,219 +0,0 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import '../../../core/constants.dart';
|
||||
import '../../../core/l10n/locale_provider.dart';
|
||||
import '../../../shared/providers/amount_format_provider.dart';
|
||||
import '../../../shared/utils/currency_utils.dart';
|
||||
import '../../../shared/widgets/byn_sign.dart';
|
||||
import '../provider.dart';
|
||||
|
||||
class BudgetSection extends ConsumerStatefulWidget {
|
||||
const BudgetSection({super.key});
|
||||
|
||||
@override
|
||||
ConsumerState<BudgetSection> createState() => _BudgetSectionState();
|
||||
}
|
||||
|
||||
class _BudgetSectionState extends ConsumerState<BudgetSection> {
|
||||
final _budgetController = TextEditingController();
|
||||
bool _isEditing = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
final budget = ref.read(budgetProvider);
|
||||
if (budget != null) {
|
||||
_budgetController.text = budget.toStringAsFixed(2);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_budgetController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
Future<void> _saveBudget() async {
|
||||
final text = _budgetController.text.trim();
|
||||
if (text.isEmpty) {
|
||||
await ref.read(budgetProvider.notifier).setBudget(null);
|
||||
} else {
|
||||
final value = double.tryParse(text);
|
||||
if (value != null && value > 0) {
|
||||
await ref.read(budgetProvider.notifier).setBudget(value);
|
||||
}
|
||||
}
|
||||
setState(() => _isEditing = false);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final s = ref.watch(stringsProvider);
|
||||
final budget = ref.watch(budgetProvider);
|
||||
final currencyInfo = ref.watch(currencyProvider);
|
||||
final fmt = ref.watch(amountFormatProvider);
|
||||
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: AppColors.accent.withOpacity(0.15),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: const Icon(
|
||||
Icons.account_balance_wallet_rounded,
|
||||
color: AppColors.accent,
|
||||
size: 20,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Text(
|
||||
s.monthlyBudgetSetting,
|
||||
style: Theme.of(context).textTheme.titleMedium?.copyWith(
|
||||
fontWeight: FontWeight.w600,
|
||||
color: Theme.of(context).colorScheme.onSurface,
|
||||
),
|
||||
),
|
||||
),
|
||||
if (!_isEditing)
|
||||
IconButton(
|
||||
icon: const Icon(Icons.edit_rounded, size: 20),
|
||||
color: Theme.of(
|
||||
context,
|
||||
).colorScheme.onSurface.withOpacity(0.6),
|
||||
onPressed: () => setState(() => _isEditing = true),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
if (_isEditing)
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
TextFormField(
|
||||
controller: _budgetController,
|
||||
keyboardType: const TextInputType.numberWithOptions(
|
||||
decimal: true,
|
||||
),
|
||||
inputFormatters: [
|
||||
FilteringTextInputFormatter.allow(
|
||||
RegExp(r'^\d+\.?\d{0,2}'),
|
||||
),
|
||||
],
|
||||
decoration: InputDecoration(
|
||||
prefix: currencyInfo.code == 'BYN'
|
||||
? Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
BynSign(
|
||||
fontSize: 16,
|
||||
color: Theme.of(context).colorScheme.onSurface,
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
],
|
||||
)
|
||||
: null,
|
||||
prefixText: currencyInfo.code != 'BYN'
|
||||
? (currencyInfo.symbol == '₽'
|
||||
? '${currencyInfo.symbol} '
|
||||
: currencyInfo.symbol)
|
||||
: null,
|
||||
hintText: '0.00',
|
||||
helperText: s.leaveEmptyToRemove,
|
||||
),
|
||||
autofocus: true,
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
children: [
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
final budget = ref.read(budgetProvider);
|
||||
_budgetController.text =
|
||||
budget?.toStringAsFixed(2) ?? '';
|
||||
setState(() => _isEditing = false);
|
||||
},
|
||||
child: Text(s.cancel),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
ElevatedButton(
|
||||
onPressed: _saveBudget,
|
||||
style: ElevatedButton.styleFrom(
|
||||
minimumSize: const Size(80, 40),
|
||||
),
|
||||
child: Text(s.save),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
)
|
||||
else
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
budget != null && currencyInfo.code == 'BYN'
|
||||
? Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
BynSign(fontSize: 24, color: AppColors.accent),
|
||||
const SizedBox(width: 2),
|
||||
Text(
|
||||
formatAmount('', budget, fmt),
|
||||
style: Theme.of(context).textTheme.headlineSmall
|
||||
?.copyWith(
|
||||
color: AppColors.accent,
|
||||
fontWeight: FontWeight.w700,
|
||||
),
|
||||
),
|
||||
],
|
||||
)
|
||||
: Text(
|
||||
budget != null
|
||||
? formatAmount(currencyInfo.symbol, budget, fmt)
|
||||
: s.budgetNone,
|
||||
style: Theme.of(context).textTheme.headlineSmall
|
||||
?.copyWith(
|
||||
color: budget != null
|
||||
? AppColors.accent
|
||||
: Theme.of(
|
||||
context,
|
||||
).colorScheme.onSurface.withOpacity(0.6),
|
||||
fontWeight: FontWeight.w700,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
budget != null
|
||||
? s.yourMonthlySpendingLimit
|
||||
: s.setMonthlySpendingLimit,
|
||||
style: Theme.of(context).textTheme.bodySmall?.copyWith(
|
||||
color: Theme.of(
|
||||
context,
|
||||
).colorScheme.onSurface.withOpacity(0.6),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -14,7 +14,7 @@ class CardTextColorSection extends ConsumerWidget {
|
||||
final isDark = Theme.of(context).brightness == Brightness.dark;
|
||||
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(20),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 14),
|
||||
decoration: BoxDecoration(
|
||||
color: Theme.of(context).colorScheme.surface,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
@@ -30,12 +30,12 @@ class CardTextColorSection extends ConsumerWidget {
|
||||
Container(
|
||||
padding: const EdgeInsets.all(10),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.accent.withOpacity(0.15),
|
||||
color: const Color(0xFF7C6DED).withOpacity(0.15),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: const Icon(
|
||||
Icons.text_fields_rounded,
|
||||
color: AppColors.accent,
|
||||
color: const Color(0xFF7C6DED),
|
||||
size: 20,
|
||||
),
|
||||
),
|
||||
@@ -49,7 +49,7 @@ class CardTextColorSection extends ConsumerWidget {
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
const SizedBox(height: 12),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
@@ -113,17 +113,17 @@ class _CardTextColorOption extends StatelessWidget {
|
||||
onTap: onTap,
|
||||
child: AnimatedContainer(
|
||||
duration: const Duration(milliseconds: 200),
|
||||
padding: const EdgeInsets.symmetric(vertical: 12),
|
||||
padding: const EdgeInsets.symmetric(vertical: 10),
|
||||
decoration: BoxDecoration(
|
||||
color: isSelected
|
||||
? AppColors.accent.withOpacity(0.15)
|
||||
? const Color(0xFF7C6DED).withOpacity(0.15)
|
||||
: (isDark
|
||||
? Colors.white.withOpacity(0.05)
|
||||
: Colors.black.withOpacity(0.03)),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
border: Border.all(
|
||||
color: isSelected
|
||||
? AppColors.accent
|
||||
? const Color(0xFF7C6DED)
|
||||
: (isDark
|
||||
? Colors.white.withOpacity(0.1)
|
||||
: Colors.black.withOpacity(0.08)),
|
||||
@@ -136,7 +136,7 @@ class _CardTextColorOption extends StatelessWidget {
|
||||
Icon(
|
||||
icon,
|
||||
color: isSelected
|
||||
? AppColors.accent
|
||||
? const Color(0xFF7C6DED)
|
||||
: Theme.of(context).colorScheme.onSurface.withOpacity(0.5),
|
||||
size: 22,
|
||||
),
|
||||
@@ -147,7 +147,7 @@ class _CardTextColorOption extends StatelessWidget {
|
||||
fontSize: 11,
|
||||
fontWeight: isSelected ? FontWeight.w600 : FontWeight.normal,
|
||||
color: isSelected
|
||||
? AppColors.accent
|
||||
? const Color(0xFF7C6DED)
|
||||
: Theme.of(context).colorScheme.onSurface.withOpacity(0.6),
|
||||
),
|
||||
textAlign: TextAlign.center,
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import '../../../core/constants.dart';
|
||||
import '../../../core/l10n/locale_provider.dart';
|
||||
import '../../../core/services/haptic_service.dart';
|
||||
|
||||
class CategoriesSection extends ConsumerWidget {
|
||||
const CategoriesSection({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final s = ref.watch(stringsProvider);
|
||||
final theme = Theme.of(context);
|
||||
final isDark = theme.brightness == Brightness.dark;
|
||||
|
||||
return GestureDetector(
|
||||
onTap: () {
|
||||
HapticService.light();
|
||||
context.push('/settings/categories');
|
||||
},
|
||||
child: Container(
|
||||
padding: const EdgeInsets.all(20),
|
||||
decoration: BoxDecoration(
|
||||
color: theme.colorScheme.surface,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
border: isDark
|
||||
? null
|
||||
: Border.all(color: const Color(0xFFDDDDEE), width: 1),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Container(
|
||||
padding: const EdgeInsets.all(10),
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0xFF7C6DED).withOpacity(0.15),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: const Icon(
|
||||
Icons.category_rounded,
|
||||
color: const Color(0xFF7C6DED),
|
||||
size: 20,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
s.manageCategories,
|
||||
style: theme.textTheme.titleMedium?.copyWith(
|
||||
fontWeight: FontWeight.w600,
|
||||
color: theme.colorScheme.onSurface,
|
||||
),
|
||||
),
|
||||
Text(
|
||||
s.manageCategoriesSubtitle,
|
||||
style: theme.textTheme.bodySmall?.copyWith(
|
||||
color: theme.colorScheme.onSurface.withOpacity(0.6),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
Icon(
|
||||
Icons.chevron_right_rounded,
|
||||
color: theme.colorScheme.onSurface.withOpacity(0.4),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -27,12 +27,12 @@ class CurrencyConversionsSection extends ConsumerWidget {
|
||||
Container(
|
||||
padding: const EdgeInsets.all(10),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.accent.withOpacity(0.15),
|
||||
color: const Color(0xFF7C6DED).withOpacity(0.15),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: const Icon(
|
||||
Icons.currency_exchange_rounded,
|
||||
color: AppColors.accent,
|
||||
color: const Color(0xFF7C6DED),
|
||||
size: 20,
|
||||
),
|
||||
),
|
||||
|
||||
@@ -15,7 +15,7 @@ class CurrencySection extends ConsumerWidget {
|
||||
final isDark = Theme.of(context).brightness == Brightness.dark;
|
||||
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(20),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 14),
|
||||
decoration: BoxDecoration(
|
||||
color: Theme.of(context).colorScheme.surface,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
@@ -31,12 +31,12 @@ class CurrencySection extends ConsumerWidget {
|
||||
Container(
|
||||
padding: const EdgeInsets.all(10),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.accent.withOpacity(0.15),
|
||||
color: const Color(0xFF7C6DED).withOpacity(0.15),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: const Icon(
|
||||
Icons.attach_money_rounded,
|
||||
color: AppColors.accent,
|
||||
color: const Color(0xFF7C6DED),
|
||||
size: 20,
|
||||
),
|
||||
),
|
||||
@@ -52,7 +52,7 @@ class CurrencySection extends ConsumerWidget {
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
const SizedBox(height: 12),
|
||||
Row(
|
||||
children: ['USD', 'EUR', 'BYN', 'RUB'].map((code) {
|
||||
final info = currencyMap[code]!;
|
||||
@@ -62,22 +62,17 @@ class CurrencySection extends ConsumerWidget {
|
||||
padding: const EdgeInsets.only(right: 8),
|
||||
child: GestureDetector(
|
||||
onTap: () {
|
||||
final oldCode = ref.read(currencyProvider).code;
|
||||
final rates = ref.read(exchangeRateServiceProvider);
|
||||
ref
|
||||
.read(budgetProvider.notifier)
|
||||
.onCurrencyChanged(oldCode, code, rates);
|
||||
ref.read(currencyProvider.notifier).setCurrency(code);
|
||||
},
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(vertical: 12),
|
||||
padding: const EdgeInsets.symmetric(vertical: 10),
|
||||
decoration: BoxDecoration(
|
||||
color: isSelected
|
||||
? AppColors.accent.withOpacity(0.2)
|
||||
? const Color(0xFF7C6DED).withOpacity(0.2)
|
||||
: Theme.of(context).scaffoldBackgroundColor,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
border: isSelected
|
||||
? Border.all(color: AppColors.accent, width: 1.5)
|
||||
? Border.all(color: const Color(0xFF7C6DED), width: 1.5)
|
||||
: (isDark
|
||||
? null
|
||||
: Border.all(
|
||||
@@ -88,19 +83,25 @@ class CurrencySection extends ConsumerWidget {
|
||||
child: Column(
|
||||
children: [
|
||||
code == 'BYN'
|
||||
? BynSign(
|
||||
fontSize: 28,
|
||||
color: isSelected
|
||||
? AppColors.accent
|
||||
: Theme.of(context).colorScheme.onSurface
|
||||
.withOpacity(0.6),
|
||||
? SizedBox(
|
||||
height: 28,
|
||||
child: Align(
|
||||
alignment: Alignment.center,
|
||||
child: BynSign(
|
||||
fontSize: 24,
|
||||
color: isSelected
|
||||
? const Color(0xFF7C6DED)
|
||||
: Theme.of(context).colorScheme.onSurface
|
||||
.withOpacity(0.6),
|
||||
),
|
||||
),
|
||||
)
|
||||
: Text(
|
||||
info.symbol,
|
||||
style: Theme.of(context).textTheme.titleLarge
|
||||
?.copyWith(
|
||||
color: isSelected
|
||||
? AppColors.accent
|
||||
? const Color(0xFF7C6DED)
|
||||
: Theme.of(context)
|
||||
.colorScheme
|
||||
.onSurface
|
||||
@@ -116,7 +117,7 @@ class CurrencySection extends ConsumerWidget {
|
||||
style: Theme.of(context).textTheme.bodySmall
|
||||
?.copyWith(
|
||||
color: isSelected
|
||||
? AppColors.accent
|
||||
? const Color(0xFF7C6DED)
|
||||
: Theme.of(context).colorScheme.onSurface
|
||||
.withOpacity(0.6),
|
||||
fontWeight: isSelected
|
||||
|
||||
@@ -25,12 +25,12 @@ class HapticSection extends ConsumerWidget {
|
||||
Container(
|
||||
padding: const EdgeInsets.all(10),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.accent.withOpacity(0.15),
|
||||
color: const Color(0xFF7C6DED).withOpacity(0.15),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: const Icon(
|
||||
Icons.vibration_rounded,
|
||||
color: AppColors.accent,
|
||||
color: const Color(0xFF7C6DED),
|
||||
size: 20,
|
||||
),
|
||||
),
|
||||
|
||||
@@ -28,12 +28,12 @@ class LanguageSection extends ConsumerWidget {
|
||||
Container(
|
||||
padding: const EdgeInsets.all(10),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.accent.withOpacity(0.15),
|
||||
color: const Color(0xFF7C6DED).withOpacity(0.15),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: const Icon(
|
||||
Icons.language_rounded,
|
||||
color: AppColors.accent,
|
||||
color: const Color(0xFF7C6DED),
|
||||
size: 20,
|
||||
),
|
||||
),
|
||||
@@ -59,11 +59,11 @@ class LanguageSection extends ConsumerWidget {
|
||||
padding: const EdgeInsets.symmetric(vertical: 12),
|
||||
decoration: BoxDecoration(
|
||||
color: currentLocale == AppLocale.en
|
||||
? AppColors.accent.withOpacity(0.2)
|
||||
? const Color(0xFF7C6DED).withOpacity(0.2)
|
||||
: Theme.of(context).scaffoldBackgroundColor,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
border: currentLocale == AppLocale.en
|
||||
? Border.all(color: AppColors.accent, width: 1.5)
|
||||
? Border.all(color: const Color(0xFF7C6DED), width: 1.5)
|
||||
: (isDark ? null : Border.all(color: const Color(0xFFDDDDEE), width: 1)),
|
||||
),
|
||||
child: Text(
|
||||
@@ -71,7 +71,7 @@ class LanguageSection extends ConsumerWidget {
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(
|
||||
color: currentLocale == AppLocale.en
|
||||
? AppColors.accent
|
||||
? const Color(0xFF7C6DED)
|
||||
: Theme.of(context).colorScheme.onSurface.withOpacity(0.6),
|
||||
fontWeight: currentLocale == AppLocale.en ? FontWeight.w600 : FontWeight.normal,
|
||||
),
|
||||
@@ -87,11 +87,11 @@ class LanguageSection extends ConsumerWidget {
|
||||
padding: const EdgeInsets.symmetric(vertical: 12),
|
||||
decoration: BoxDecoration(
|
||||
color: currentLocale == AppLocale.ru
|
||||
? AppColors.accent.withOpacity(0.2)
|
||||
? const Color(0xFF7C6DED).withOpacity(0.2)
|
||||
: Theme.of(context).scaffoldBackgroundColor,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
border: currentLocale == AppLocale.ru
|
||||
? Border.all(color: AppColors.accent, width: 1.5)
|
||||
? Border.all(color: const Color(0xFF7C6DED), width: 1.5)
|
||||
: (isDark ? null : Border.all(color: const Color(0xFFDDDDEE), width: 1)),
|
||||
),
|
||||
child: Text(
|
||||
@@ -99,7 +99,7 @@ class LanguageSection extends ConsumerWidget {
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(
|
||||
color: currentLocale == AppLocale.ru
|
||||
? AppColors.accent
|
||||
? const Color(0xFF7C6DED)
|
||||
: Theme.of(context).colorScheme.onSurface.withOpacity(0.6),
|
||||
fontWeight: currentLocale == AppLocale.ru ? FontWeight.w600 : FontWeight.normal,
|
||||
),
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import '../../../core/constants.dart';
|
||||
import '../../../core/l10n/locale_provider.dart';
|
||||
import '../../../shared/providers/current_user_provider.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 ? const Color(0xFF7C6DED) : AppColors.warning)
|
||||
.withOpacity(0.15),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: Icon(
|
||||
user.isVip ? Icons.workspace_premium_rounded : Icons.lock_outline_rounded,
|
||||
color: user.isVip ? const Color(0xFF7C6DED) : 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),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -14,7 +14,7 @@ class ThemeSection extends ConsumerWidget {
|
||||
final isDark = Theme.of(context).brightness == Brightness.dark;
|
||||
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(20),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 14),
|
||||
decoration: BoxDecoration(
|
||||
color: Theme.of(context).colorScheme.surface,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
@@ -28,7 +28,7 @@ class ThemeSection extends ConsumerWidget {
|
||||
Container(
|
||||
padding: const EdgeInsets.all(10),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.accent.withOpacity(0.15),
|
||||
color: const Color(0xFF7C6DED).withOpacity(0.15),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: Icon(
|
||||
@@ -37,7 +37,7 @@ class ThemeSection extends ConsumerWidget {
|
||||
: themeMode == ThemeMode.light
|
||||
? Icons.light_mode_rounded
|
||||
: Icons.brightness_auto_rounded,
|
||||
color: AppColors.accent,
|
||||
color: const Color(0xFF7C6DED),
|
||||
size: 20,
|
||||
),
|
||||
),
|
||||
@@ -51,7 +51,7 @@ class ThemeSection extends ConsumerWidget {
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
const SizedBox(height: 12),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
@@ -109,15 +109,15 @@ class _ThemeOption extends StatelessWidget {
|
||||
onTap: onTap,
|
||||
child: AnimatedContainer(
|
||||
duration: const Duration(milliseconds: 200),
|
||||
padding: const EdgeInsets.symmetric(vertical: 12),
|
||||
padding: const EdgeInsets.symmetric(vertical: 10),
|
||||
decoration: BoxDecoration(
|
||||
color: isSelected
|
||||
? AppColors.accent.withOpacity(0.15)
|
||||
? const Color(0xFF7C6DED).withOpacity(0.15)
|
||||
: (isDark ? Colors.white.withOpacity(0.05) : Colors.black.withOpacity(0.03)),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
border: Border.all(
|
||||
color: isSelected
|
||||
? AppColors.accent
|
||||
? const Color(0xFF7C6DED)
|
||||
: (isDark ? Colors.white.withOpacity(0.1) : Colors.black.withOpacity(0.08)),
|
||||
width: isSelected ? 2 : 1,
|
||||
),
|
||||
@@ -128,7 +128,7 @@ class _ThemeOption extends StatelessWidget {
|
||||
Icon(
|
||||
icon,
|
||||
color: isSelected
|
||||
? AppColors.accent
|
||||
? const Color(0xFF7C6DED)
|
||||
: Theme.of(context).colorScheme.onSurface.withOpacity(0.5),
|
||||
size: 22,
|
||||
),
|
||||
@@ -139,7 +139,7 @@ class _ThemeOption extends StatelessWidget {
|
||||
fontSize: 11,
|
||||
fontWeight: isSelected ? FontWeight.w600 : FontWeight.normal,
|
||||
color: isSelected
|
||||
? AppColors.accent
|
||||
? const Color(0xFF7C6DED)
|
||||
: Theme.of(context).colorScheme.onSurface.withOpacity(0.6),
|
||||
),
|
||||
textAlign: TextAlign.center,
|
||||
|
||||
+14
-181
@@ -1,189 +1,16 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:intl/date_symbol_data_local.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:uuid/uuid.dart';
|
||||
import 'app/app.dart';
|
||||
import 'core/services/haptic_service.dart';
|
||||
import 'data/database/app_database.dart' hide Account, Transaction;
|
||||
import 'data/repositories/account_repository.dart';
|
||||
import 'data/repositories/transaction_repository.dart';
|
||||
import 'data/database/app_database.dart';
|
||||
import 'features/dashboard/provider.dart';
|
||||
import 'shared/models/account.dart';
|
||||
import 'shared/models/transaction.dart';
|
||||
|
||||
Future<void> seedTestData(AppDatabase database) async {
|
||||
final accountRepo = AccountRepository(database);
|
||||
final transactionRepo = TransactionRepository(database);
|
||||
|
||||
final existingAccounts = await accountRepo.getAll();
|
||||
if (existingAccounts.length > 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
final now = DateTime.now();
|
||||
final uuid = const Uuid();
|
||||
|
||||
final cashId = await accountRepo.add(
|
||||
Account(
|
||||
id: 0,
|
||||
name: 'Cash',
|
||||
isMain: false,
|
||||
sortOrder: 1,
|
||||
currency: 'USD',
|
||||
createdAt: now,
|
||||
),
|
||||
);
|
||||
|
||||
final cardId = await accountRepo.add(
|
||||
Account(
|
||||
id: 0,
|
||||
name: 'Card',
|
||||
isMain: false,
|
||||
sortOrder: 2,
|
||||
currency: 'USD',
|
||||
createdAt: now,
|
||||
),
|
||||
);
|
||||
|
||||
final savingsId = await accountRepo.add(
|
||||
Account(
|
||||
id: 0,
|
||||
name: 'Savings',
|
||||
isMain: false,
|
||||
sortOrder: 3,
|
||||
currency: 'USD',
|
||||
createdAt: now,
|
||||
),
|
||||
);
|
||||
|
||||
final transactions = [
|
||||
Transaction(
|
||||
id: uuid.v4(),
|
||||
amount: 3500.0,
|
||||
category: 'Salary',
|
||||
type: TransactionType.income,
|
||||
date: now.subtract(const Duration(days: 28)),
|
||||
note: 'Monthly salary',
|
||||
accountId: cardId,
|
||||
),
|
||||
Transaction(
|
||||
id: uuid.v4(),
|
||||
amount: 85.50,
|
||||
category: 'Groceries',
|
||||
type: TransactionType.expense,
|
||||
date: now.subtract(const Duration(days: 27)),
|
||||
note: 'Weekly shopping',
|
||||
accountId: cardId,
|
||||
),
|
||||
Transaction(
|
||||
id: uuid.v4(),
|
||||
amount: 45.00,
|
||||
category: 'Transportation',
|
||||
type: TransactionType.expense,
|
||||
date: now.subtract(const Duration(days: 25)),
|
||||
accountId: cashId,
|
||||
),
|
||||
Transaction(
|
||||
id: uuid.v4(),
|
||||
amount: 120.00,
|
||||
category: 'Utilities',
|
||||
type: TransactionType.expense,
|
||||
date: now.subtract(const Duration(days: 22)),
|
||||
note: 'Electricity bill',
|
||||
accountId: cardId,
|
||||
),
|
||||
Transaction(
|
||||
id: uuid.v4(),
|
||||
amount: 200.0,
|
||||
category: 'Freelance',
|
||||
type: TransactionType.income,
|
||||
date: now.subtract(const Duration(days: 20)),
|
||||
note: 'Side project',
|
||||
accountId: cashId,
|
||||
),
|
||||
Transaction(
|
||||
id: uuid.v4(),
|
||||
amount: 500.0,
|
||||
category: 'Savings',
|
||||
type: TransactionType.expense,
|
||||
date: now.subtract(const Duration(days: 18)),
|
||||
note: 'Monthly savings',
|
||||
accountId: savingsId,
|
||||
),
|
||||
Transaction(
|
||||
id: uuid.v4(),
|
||||
amount: 65.25,
|
||||
category: 'Dining',
|
||||
type: TransactionType.expense,
|
||||
date: now.subtract(const Duration(days: 15)),
|
||||
accountId: cardId,
|
||||
),
|
||||
Transaction(
|
||||
id: uuid.v4(),
|
||||
amount: 30.00,
|
||||
category: 'Entertainment',
|
||||
type: TransactionType.expense,
|
||||
date: now.subtract(const Duration(days: 12)),
|
||||
note: 'Movie tickets',
|
||||
accountId: cashId,
|
||||
),
|
||||
Transaction(
|
||||
id: uuid.v4(),
|
||||
amount: 95.00,
|
||||
category: 'Groceries',
|
||||
type: TransactionType.expense,
|
||||
date: now.subtract(const Duration(days: 10)),
|
||||
accountId: cardId,
|
||||
),
|
||||
Transaction(
|
||||
id: uuid.v4(),
|
||||
amount: 150.0,
|
||||
category: 'Bonus',
|
||||
type: TransactionType.income,
|
||||
date: now.subtract(const Duration(days: 8)),
|
||||
note: 'Performance bonus',
|
||||
accountId: cardId,
|
||||
),
|
||||
Transaction(
|
||||
id: uuid.v4(),
|
||||
amount: 75.00,
|
||||
category: 'Shopping',
|
||||
type: TransactionType.expense,
|
||||
date: now.subtract(const Duration(days: 6)),
|
||||
accountId: cardId,
|
||||
),
|
||||
Transaction(
|
||||
id: uuid.v4(),
|
||||
amount: 40.00,
|
||||
category: 'Transportation',
|
||||
type: TransactionType.expense,
|
||||
date: now.subtract(const Duration(days: 4)),
|
||||
accountId: cashId,
|
||||
),
|
||||
Transaction(
|
||||
id: uuid.v4(),
|
||||
amount: 55.80,
|
||||
category: 'Dining',
|
||||
type: TransactionType.expense,
|
||||
date: now.subtract(const Duration(days: 2)),
|
||||
note: 'Dinner with friends',
|
||||
accountId: cardId,
|
||||
),
|
||||
Transaction(
|
||||
id: uuid.v4(),
|
||||
amount: 100.0,
|
||||
category: 'Gift',
|
||||
type: TransactionType.income,
|
||||
date: now.subtract(const Duration(days: 1)),
|
||||
accountId: cashId,
|
||||
),
|
||||
];
|
||||
|
||||
for (final transaction in transactions) {
|
||||
await transactionRepo.add(transaction);
|
||||
}
|
||||
}
|
||||
import 'shared/services/onboarding_service.dart';
|
||||
import 'shared/services/billing_service.dart';
|
||||
import 'shared/services/premium_manager.dart';
|
||||
import 'shared/providers/billing_provider.dart';
|
||||
|
||||
void main() async {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
@@ -195,16 +22,22 @@ void main() async {
|
||||
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
await HapticService.init();
|
||||
OnboardingService(prefs);
|
||||
|
||||
final database = AppDatabase();
|
||||
|
||||
await seedTestData(database);
|
||||
|
||||
final billing = kDebugMode
|
||||
? DebugBillingService(prefs)
|
||||
: PlayBillingService();
|
||||
final premiumManager = PremiumManager(prefs, billing);
|
||||
await premiumManager.autoRestore();
|
||||
|
||||
runApp(
|
||||
ProviderScope(
|
||||
overrides: [
|
||||
sharedPreferencesProvider.overrideWithValue(prefs),
|
||||
appDatabaseProvider.overrideWithValue(database),
|
||||
billingServiceProvider.overrideWithValue(billing),
|
||||
],
|
||||
child: const App(),
|
||||
),
|
||||
|
||||
@@ -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,31 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'transaction.dart';
|
||||
|
||||
class AppCategory {
|
||||
final String key;
|
||||
final TransactionType type;
|
||||
final String labelEn;
|
||||
final String labelRu;
|
||||
final IconData icon;
|
||||
final Color color;
|
||||
final String iconName;
|
||||
final bool isCustom;
|
||||
final int? id;
|
||||
|
||||
const AppCategory({
|
||||
required this.key,
|
||||
required this.type,
|
||||
required this.labelEn,
|
||||
required this.labelRu,
|
||||
required this.icon,
|
||||
required this.color,
|
||||
required this.iconName,
|
||||
this.isCustom = false,
|
||||
this.id,
|
||||
});
|
||||
|
||||
String label(bool isRu) {
|
||||
final value = isRu ? labelRu : labelEn;
|
||||
return value.isEmpty ? key : value;
|
||||
}
|
||||
}
|
||||
@@ -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: const 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),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import '../services/backup_service.dart';
|
||||
import 'premium_provider.dart';
|
||||
|
||||
final backupServiceProvider = Provider<BackupService>((ref) {
|
||||
final token = ref.watch(purchaseTokenProvider) ?? '';
|
||||
return BackupService(token);
|
||||
});
|
||||
@@ -0,0 +1,12 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import '../../features/dashboard/provider.dart';
|
||||
import '../services/billing_service.dart';
|
||||
|
||||
final billingServiceProvider = Provider<BillingService>((ref) {
|
||||
if (kDebugMode) {
|
||||
final prefs = ref.watch(sharedPreferencesProvider);
|
||||
return DebugBillingService(prefs);
|
||||
}
|
||||
return PlayBillingService();
|
||||
});
|
||||
@@ -0,0 +1,180 @@
|
||||
import 'package:collection/collection.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import '../../core/constants.dart';
|
||||
import '../../core/utils/result.dart';
|
||||
import '../../data/database/app_database.dart';
|
||||
import '../../data/repositories/category_repository.dart';
|
||||
import '../../features/dashboard/provider.dart';
|
||||
import '../models/app_category.dart';
|
||||
import '../models/transaction.dart';
|
||||
import '../services/translation_service.dart';
|
||||
|
||||
final categoryRepositoryProvider = Provider<CategoryRepository>((ref) {
|
||||
return CategoryRepository(ref.watch(appDatabaseProvider));
|
||||
});
|
||||
|
||||
final customCategoriesProvider = StreamProvider<List<Category>>((ref) {
|
||||
return ref.watch(categoryRepositoryProvider).watchAll();
|
||||
});
|
||||
|
||||
final translationServiceProvider = Provider<TranslationService>((ref) {
|
||||
return TranslationService();
|
||||
});
|
||||
|
||||
final categoryActionsProvider = Provider<CategoryActions>((ref) {
|
||||
return CategoryActions(ref);
|
||||
});
|
||||
|
||||
class CategoryActions {
|
||||
final Ref _ref;
|
||||
|
||||
CategoryActions(this._ref);
|
||||
|
||||
CategoryRepository get _repo => _ref.read(categoryRepositoryProvider);
|
||||
|
||||
Future<Result<void>> create({
|
||||
required TransactionType type,
|
||||
required String labelEn,
|
||||
required String labelRu,
|
||||
required String iconName,
|
||||
required int colorValue,
|
||||
}) {
|
||||
return asyncResultOf(() async {
|
||||
final en = labelEn.trim();
|
||||
final ru = labelRu.trim();
|
||||
if (en.isEmpty && ru.isEmpty) {
|
||||
throw Exception('Category name is required');
|
||||
}
|
||||
final key = 'cat_${DateTime.now().microsecondsSinceEpoch}';
|
||||
await _repo.add(
|
||||
name: key,
|
||||
type: type.name,
|
||||
labelEn: en.isEmpty ? ru : en,
|
||||
labelRu: ru.isEmpty ? en : ru,
|
||||
iconName: iconName,
|
||||
colorValue: colorValue,
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
Future<Result<void>> edit({
|
||||
required int id,
|
||||
required TransactionType type,
|
||||
required String labelEn,
|
||||
required String labelRu,
|
||||
required String iconName,
|
||||
required int colorValue,
|
||||
}) {
|
||||
return asyncResultOf(() async {
|
||||
final en = labelEn.trim();
|
||||
final ru = labelRu.trim();
|
||||
if (en.isEmpty && ru.isEmpty) {
|
||||
throw Exception('Category name is required');
|
||||
}
|
||||
await _repo.updateFields(
|
||||
id,
|
||||
type: type.name,
|
||||
labelEn: en.isEmpty ? ru : en,
|
||||
labelRu: ru.isEmpty ? en : ru,
|
||||
iconName: iconName,
|
||||
colorValue: colorValue,
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
Future<Result<void>> remove(int id) {
|
||||
return asyncResultOf(() async {
|
||||
await _repo.delete(id);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
class CategoryCatalog {
|
||||
final List<AppCategory> all;
|
||||
|
||||
const CategoryCatalog(this.all);
|
||||
|
||||
List<AppCategory> forType(TransactionType type) =>
|
||||
all.where((c) => c.type == type).toList();
|
||||
|
||||
List<AppCategory> get custom => all.where((c) => c.isCustom).toList();
|
||||
|
||||
AppCategory? byKey(String key) =>
|
||||
all.firstWhereOrNull((c) => c.key == key);
|
||||
|
||||
IconData iconFor(String key) =>
|
||||
byKey(key)?.icon ?? Icons.category_rounded;
|
||||
|
||||
Color colorFor(String key, [Color? fallback]) =>
|
||||
byKey(key)?.color ?? fallback ?? const Color(0xFF7C6DED);
|
||||
|
||||
String labelFor(String key, bool isRu) {
|
||||
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;
|
||||
}
|
||||
|
||||
final categoryCatalogProvider = Provider<CategoryCatalog>((ref) {
|
||||
final custom = ref.watch(customCategoriesProvider).value ?? const [];
|
||||
final mapped = custom.map(_fromRow).toList();
|
||||
return CategoryCatalog([..._defaultCategories(), ...mapped]);
|
||||
});
|
||||
|
||||
List<AppCategory> _defaultCategories() {
|
||||
final result = <AppCategory>[];
|
||||
for (final key in AppCategories.expenseCategories) {
|
||||
result.add(_defaultCategory(key, TransactionType.expense));
|
||||
}
|
||||
for (final key in AppCategories.incomeCategories) {
|
||||
result.add(_defaultCategory(key, TransactionType.income));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
AppCategory _defaultCategory(String key, TransactionType type) {
|
||||
final iconName = AppCategories.iconNames[key] ?? 'category';
|
||||
return AppCategory(
|
||||
key: key,
|
||||
type: type,
|
||||
labelEn: key,
|
||||
labelRu: AppCategories.ruLabels[key] ?? key,
|
||||
icon: categoryIconByName(iconName),
|
||||
color: AppCategories.colors[key] ?? const Color(0xFF7C6DED),
|
||||
iconName: iconName,
|
||||
isCustom: false,
|
||||
);
|
||||
}
|
||||
|
||||
AppCategory _fromRow(Category row) {
|
||||
final type =
|
||||
row.type == 'income' ? TransactionType.income : TransactionType.expense;
|
||||
final labelEn = (row.labelEn != null && row.labelEn!.isNotEmpty)
|
||||
? row.labelEn!
|
||||
: row.name;
|
||||
final labelRu = (row.labelRu != null && row.labelRu!.isNotEmpty)
|
||||
? row.labelRu!
|
||||
: row.name;
|
||||
final colorValue = int.tryParse(row.color ?? '');
|
||||
final color = colorValue != null
|
||||
? Color(colorValue)
|
||||
: kCategoryColors[row.id % kCategoryColors.length];
|
||||
return AppCategory(
|
||||
key: row.name,
|
||||
type: type,
|
||||
labelEn: labelEn,
|
||||
labelRu: labelRu,
|
||||
icon: categoryIconByName(row.icon),
|
||||
color: color,
|
||||
iconName: row.icon ?? 'category',
|
||||
isCustom: true,
|
||||
id: row.id,
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import '../../features/dashboard/provider.dart';
|
||||
import '../models/user_model.dart';
|
||||
import '../services/premium_manager.dart';
|
||||
import 'billing_provider.dart';
|
||||
|
||||
class CurrentUserNotifier extends Notifier<UserModel> {
|
||||
@override
|
||||
UserModel build() {
|
||||
final prefs = ref.watch(sharedPreferencesProvider);
|
||||
final billing = ref.watch(billingServiceProvider);
|
||||
final manager = PremiumManager(prefs, billing);
|
||||
return UserModel(plan: manager.currentPlan);
|
||||
}
|
||||
|
||||
Future<void> setPlan(UserPlan plan) async {
|
||||
state = UserModel(plan: plan);
|
||||
}
|
||||
|
||||
Future<void> refreshFromPremium() async {
|
||||
final prefs = ref.read(sharedPreferencesProvider);
|
||||
final billing = ref.read(billingServiceProvider);
|
||||
final manager = PremiumManager(prefs, billing);
|
||||
state = UserModel(plan: manager.currentPlan);
|
||||
}
|
||||
}
|
||||
|
||||
final currentUserProvider = NotifierProvider<CurrentUserNotifier, UserModel>(
|
||||
CurrentUserNotifier.new,
|
||||
);
|
||||
@@ -0,0 +1,12 @@
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:google_sign_in/google_sign_in.dart';
|
||||
import '../services/google_auth_service.dart';
|
||||
|
||||
final googleAuthProvider = Provider<GoogleAuthService>((ref) {
|
||||
return GoogleAuthService();
|
||||
});
|
||||
|
||||
final googleCurrentUserProvider = StreamProvider<GoogleSignInAccount?>((ref) {
|
||||
final service = ref.watch(googleAuthProvider);
|
||||
return service.onCurrentUserChanged;
|
||||
});
|
||||
@@ -0,0 +1,18 @@
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:google_sign_in/google_sign_in.dart';
|
||||
import '../services/google_drive_service.dart';
|
||||
|
||||
final googleDriveServiceProvider = Provider<GoogleDriveService>((ref) {
|
||||
final signIn = GoogleSignIn(
|
||||
scopes: [
|
||||
'email',
|
||||
'https://www.googleapis.com/auth/drive.appdata',
|
||||
],
|
||||
);
|
||||
return GoogleDriveService(signIn);
|
||||
});
|
||||
|
||||
final googleDriveUserProvider = StreamProvider<GoogleSignInAccount?>((ref) {
|
||||
final service = ref.watch(googleDriveServiceProvider);
|
||||
return service.onUserChanged;
|
||||
});
|
||||
@@ -0,0 +1,8 @@
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import '../../features/dashboard/provider.dart';
|
||||
import '../services/onboarding_service.dart';
|
||||
|
||||
final onboardingServiceProvider = Provider<OnboardingService>((ref) {
|
||||
final prefs = ref.watch(sharedPreferencesProvider);
|
||||
return OnboardingService(prefs);
|
||||
});
|
||||
@@ -0,0 +1,22 @@
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import '../../features/dashboard/provider.dart';
|
||||
import '../models/user_model.dart';
|
||||
import '../services/premium_manager.dart';
|
||||
import 'billing_provider.dart';
|
||||
import 'current_user_provider.dart';
|
||||
|
||||
final premiumManagerProvider = Provider<PremiumManager>((ref) {
|
||||
final prefs = ref.watch(sharedPreferencesProvider);
|
||||
final billing = ref.watch(billingServiceProvider);
|
||||
return PremiumManager(prefs, billing);
|
||||
});
|
||||
|
||||
final isPremiumProvider = Provider<bool>((ref) {
|
||||
final user = ref.watch(currentUserProvider);
|
||||
return user.plan == UserPlan.vip;
|
||||
});
|
||||
|
||||
final purchaseTokenProvider = Provider<String?>((ref) {
|
||||
final manager = ref.watch(premiumManagerProvider);
|
||||
return manager.purchaseToken;
|
||||
});
|
||||
@@ -0,0 +1,72 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:typed_data';
|
||||
|
||||
class BackupData {
|
||||
final String ownerPurchaseToken;
|
||||
final DateTime createdAt;
|
||||
final Map<String, dynamic> payload;
|
||||
|
||||
const BackupData({
|
||||
required this.ownerPurchaseToken,
|
||||
required this.createdAt,
|
||||
required this.payload,
|
||||
});
|
||||
|
||||
Map<String, dynamic> toJson() => {
|
||||
'owner_purchase_token': ownerPurchaseToken,
|
||||
'created_at': createdAt.toIso8601String(),
|
||||
'payload': payload,
|
||||
};
|
||||
|
||||
factory BackupData.fromJson(Map<String, dynamic> json) {
|
||||
return BackupData(
|
||||
ownerPurchaseToken: json['owner_purchase_token'] as String? ?? '',
|
||||
createdAt: DateTime.tryParse(json['created_at'] as String? ?? '') ??
|
||||
DateTime.now(),
|
||||
payload: json['payload'] as Map<String, dynamic>? ?? {},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
enum BackupVerifyResult { ok, tokenMismatch, noToken, invalidFormat }
|
||||
|
||||
class BackupService {
|
||||
String _currentPurchaseToken;
|
||||
|
||||
BackupService(this._currentPurchaseToken);
|
||||
|
||||
void updatePurchaseToken(String token) {
|
||||
_currentPurchaseToken = token;
|
||||
}
|
||||
|
||||
String get currentPurchaseToken => _currentPurchaseToken;
|
||||
|
||||
Uint8List createBackup(Map<String, dynamic> payload) {
|
||||
final data = BackupData(
|
||||
ownerPurchaseToken: _currentPurchaseToken,
|
||||
createdAt: DateTime.now(),
|
||||
payload: payload,
|
||||
);
|
||||
final json = jsonEncode(data.toJson());
|
||||
return Uint8List.fromList(utf8.encode(json));
|
||||
}
|
||||
|
||||
(BackupVerifyResult, BackupData?) verifyAndParse(Uint8List raw) {
|
||||
try {
|
||||
final json = jsonDecode(utf8.decode(raw)) as Map<String, dynamic>;
|
||||
final data = BackupData.fromJson(json);
|
||||
|
||||
if (data.ownerPurchaseToken.isEmpty) {
|
||||
return (BackupVerifyResult.noToken, null);
|
||||
}
|
||||
|
||||
if (data.ownerPurchaseToken != _currentPurchaseToken) {
|
||||
return (BackupVerifyResult.tokenMismatch, null);
|
||||
}
|
||||
|
||||
return (BackupVerifyResult.ok, data);
|
||||
} catch (e) {
|
||||
return (BackupVerifyResult.invalidFormat, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,197 @@
|
||||
import 'dart:async';
|
||||
import 'package:in_app_purchase/in_app_purchase.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
class PurchaseResult {
|
||||
final bool success;
|
||||
final String? purchaseToken;
|
||||
final String? error;
|
||||
|
||||
const PurchaseResult({this.success = false, this.purchaseToken, this.error});
|
||||
|
||||
factory PurchaseResult.ok(String token) =>
|
||||
PurchaseResult(success: true, purchaseToken: token);
|
||||
|
||||
factory PurchaseResult.failed([String? error]) =>
|
||||
PurchaseResult(success: false, error: error);
|
||||
|
||||
factory PurchaseResult.cancelled() =>
|
||||
const PurchaseResult(success: false);
|
||||
}
|
||||
|
||||
abstract class BillingService {
|
||||
static const proProductId = 'casha_pro_lifetime';
|
||||
|
||||
Future<PurchaseResult> purchasePro();
|
||||
Future<PurchaseResult> restorePurchases();
|
||||
Future<PurchaseResult> queryPastPurchase();
|
||||
Future<void> dispose();
|
||||
}
|
||||
|
||||
class PlayBillingService implements BillingService {
|
||||
final InAppPurchase _inAppPurchase = InAppPurchase.instance;
|
||||
|
||||
@override
|
||||
Future<PurchaseResult> purchasePro() async {
|
||||
final available = await _inAppPurchase.isAvailable();
|
||||
if (!available) {
|
||||
return PurchaseResult.failed('Billing not available');
|
||||
}
|
||||
|
||||
final response = await _inAppPurchase.queryProductDetails(
|
||||
{BillingService.proProductId},
|
||||
);
|
||||
if (response.error != null) {
|
||||
return PurchaseResult.failed(response.error!.message);
|
||||
}
|
||||
if (response.productDetails.isEmpty) {
|
||||
return PurchaseResult.failed('Product not found');
|
||||
}
|
||||
|
||||
final product = response.productDetails.first;
|
||||
return _waitForPurchase(
|
||||
timeout: const Duration(minutes: 2),
|
||||
timeoutError: 'Purchase timed out',
|
||||
start: () async {
|
||||
final started = await _inAppPurchase.buyNonConsumable(
|
||||
purchaseParam: PurchaseParam(productDetails: product),
|
||||
);
|
||||
if (!started) {
|
||||
throw StateError('Could not start purchase');
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<PurchaseResult> restorePurchases() async {
|
||||
final available = await _inAppPurchase.isAvailable();
|
||||
if (!available) {
|
||||
return PurchaseResult.failed('Billing not available');
|
||||
}
|
||||
|
||||
return _waitForPurchase(
|
||||
timeout: const Duration(seconds: 30),
|
||||
timeoutError: 'No purchases found',
|
||||
start: _inAppPurchase.restorePurchases,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<PurchaseResult> queryPastPurchase() => restorePurchases();
|
||||
|
||||
Future<PurchaseResult> _waitForPurchase({
|
||||
required Future<void> Function() start,
|
||||
required Duration timeout,
|
||||
required String timeoutError,
|
||||
}) async {
|
||||
final completer = Completer<PurchaseResult>();
|
||||
var handlingPurchase = false;
|
||||
late final StreamSubscription<List<PurchaseDetails>> subscription;
|
||||
late final Timer timeoutTimer;
|
||||
|
||||
void finish(PurchaseResult result) {
|
||||
if (!completer.isCompleted) {
|
||||
completer.complete(result);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> handlePurchase(PurchaseDetails purchase) async {
|
||||
if (purchase.productID != BillingService.proProductId) return;
|
||||
|
||||
switch (purchase.status) {
|
||||
case PurchaseStatus.pending:
|
||||
return;
|
||||
case PurchaseStatus.purchased:
|
||||
case PurchaseStatus.restored:
|
||||
if (handlingPurchase) return;
|
||||
handlingPurchase = true;
|
||||
try {
|
||||
final token = purchase.verificationData.serverVerificationData;
|
||||
if (token.isEmpty) {
|
||||
finish(PurchaseResult.failed('Purchase verification data is empty'));
|
||||
return;
|
||||
}
|
||||
if (purchase.pendingCompletePurchase) {
|
||||
await _inAppPurchase.completePurchase(purchase);
|
||||
}
|
||||
finish(PurchaseResult.ok(token));
|
||||
} catch (error) {
|
||||
finish(PurchaseResult.failed(error.toString()));
|
||||
} finally {
|
||||
handlingPurchase = false;
|
||||
}
|
||||
case PurchaseStatus.error:
|
||||
finish(PurchaseResult.failed(purchase.error?.message));
|
||||
case PurchaseStatus.canceled:
|
||||
finish(PurchaseResult.cancelled());
|
||||
}
|
||||
}
|
||||
|
||||
subscription = _inAppPurchase.purchaseStream.listen(
|
||||
(purchases) {
|
||||
for (final purchase in purchases) {
|
||||
unawaited(handlePurchase(purchase));
|
||||
}
|
||||
},
|
||||
onError: (Object error) {
|
||||
finish(PurchaseResult.failed(error.toString()));
|
||||
},
|
||||
);
|
||||
timeoutTimer = Timer(
|
||||
timeout,
|
||||
() => finish(PurchaseResult.failed(timeoutError)),
|
||||
);
|
||||
|
||||
try {
|
||||
await start();
|
||||
} catch (error) {
|
||||
finish(PurchaseResult.failed(error.toString()));
|
||||
}
|
||||
|
||||
final result = await completer.future;
|
||||
timeoutTimer.cancel();
|
||||
await subscription.cancel();
|
||||
return result;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> dispose() async {}
|
||||
}
|
||||
|
||||
class DebugBillingService implements BillingService {
|
||||
static const _key = 'debug_purchase_token';
|
||||
final SharedPreferences _prefs;
|
||||
|
||||
DebugBillingService(this._prefs);
|
||||
|
||||
@override
|
||||
Future<PurchaseResult> purchasePro() async {
|
||||
await Future.delayed(const Duration(seconds: 1));
|
||||
final token = 'debug_token_${DateTime.now().millisecondsSinceEpoch}';
|
||||
await _prefs.setString(_key, token);
|
||||
return PurchaseResult.ok(token);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<PurchaseResult> restorePurchases() async {
|
||||
await Future.delayed(const Duration(seconds: 1));
|
||||
final token = _prefs.getString(_key);
|
||||
if (token != null) {
|
||||
return PurchaseResult.ok(token);
|
||||
}
|
||||
return const PurchaseResult();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<PurchaseResult> queryPastPurchase() async {
|
||||
final token = _prefs.getString(_key);
|
||||
if (token != null) {
|
||||
return PurchaseResult.ok(token);
|
||||
}
|
||||
return const PurchaseResult();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> dispose() async {}
|
||||
}
|
||||
@@ -97,6 +97,7 @@ class ExchangeRateService {
|
||||
|
||||
final fromRate = currentRates[from] ?? 1.0;
|
||||
final toRate = currentRates[to] ?? 1.0;
|
||||
if (fromRate == 0) return amount;
|
||||
|
||||
final amountInUsd = amount / fromRate;
|
||||
return amountInUsd * toRate;
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
import 'dart:async';
|
||||
import 'package:google_sign_in/google_sign_in.dart';
|
||||
|
||||
class GoogleAuthService {
|
||||
final GoogleSignIn _googleSignIn;
|
||||
|
||||
GoogleAuthService() : _googleSignIn = GoogleSignIn(scopes: [
|
||||
'email',
|
||||
'https://www.googleapis.com/auth/drive.appdata',
|
||||
]);
|
||||
|
||||
GoogleSignInAccount? get currentUser => _googleSignIn.currentUser;
|
||||
|
||||
Stream<GoogleSignInAccount?> get onCurrentUserChanged =>
|
||||
_googleSignIn.onCurrentUserChanged;
|
||||
|
||||
Future<void> signIn() async {
|
||||
await _googleSignIn.signIn();
|
||||
}
|
||||
|
||||
Future<void> signOut() async {
|
||||
await _googleSignIn.signOut();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,147 @@
|
||||
import 'dart:typed_data';
|
||||
import 'package:googleapis/drive/v3.dart' as drive;
|
||||
import 'package:google_sign_in/google_sign_in.dart';
|
||||
import 'package:extension_google_sign_in_as_googleapis_auth/extension_google_sign_in_as_googleapis_auth.dart';
|
||||
|
||||
class DriveBackupResult {
|
||||
final bool success;
|
||||
final String? error;
|
||||
final String? fileId;
|
||||
final DateTime? modifiedTime;
|
||||
|
||||
const DriveBackupResult({this.success = false, this.error, this.fileId, this.modifiedTime});
|
||||
|
||||
factory DriveBackupResult.ok(String fileId, DateTime modifiedTime) =>
|
||||
DriveBackupResult(success: true, fileId: fileId, modifiedTime: modifiedTime);
|
||||
|
||||
factory DriveBackupResult.failed(String error) =>
|
||||
DriveBackupResult(success: false, error: error);
|
||||
}
|
||||
|
||||
class GoogleDriveService {
|
||||
static const _fileName = 'casha_backup.json';
|
||||
static const _appDataFolder = 'appDataFolder';
|
||||
|
||||
final GoogleSignIn _googleSignIn;
|
||||
|
||||
GoogleDriveService(this._googleSignIn);
|
||||
|
||||
GoogleSignInAccount? get currentUser => _googleSignIn.currentUser;
|
||||
Stream<GoogleSignInAccount?> get onUserChanged => _googleSignIn.onCurrentUserChanged;
|
||||
|
||||
Future<void> signIn() async {
|
||||
await _googleSignIn.signIn();
|
||||
}
|
||||
|
||||
Future<void> signOut() async {
|
||||
await _googleSignIn.signOut();
|
||||
}
|
||||
|
||||
Future<drive.DriveApi?> _getDriveApi() async {
|
||||
if (_googleSignIn.currentUser == null) return null;
|
||||
final httpClient = await _googleSignIn.authenticatedClient();
|
||||
if (httpClient == null) return null;
|
||||
return drive.DriveApi(httpClient);
|
||||
}
|
||||
|
||||
Future<String?> _findExistingFile(drive.DriveApi api) async {
|
||||
final list = await api.files.list(
|
||||
spaces: _appDataFolder,
|
||||
q: "name = '$_fileName' and trashed = false",
|
||||
$fields: 'files(id, name, modifiedTime)',
|
||||
);
|
||||
return list.files?.isNotEmpty == true ? list.files!.first.id : null;
|
||||
}
|
||||
|
||||
Future<DriveBackupResult> uploadBackup(Uint8List data) async {
|
||||
final api = await _getDriveApi();
|
||||
if (api == null) {
|
||||
return DriveBackupResult.failed('Not authenticated');
|
||||
}
|
||||
|
||||
try {
|
||||
final existingId = await _findExistingFile(api);
|
||||
|
||||
final media = drive.Media(
|
||||
Stream<List<int>>.fromIterable([data.toList()]),
|
||||
data.length,
|
||||
);
|
||||
|
||||
if (existingId != null) {
|
||||
final file = drive.File(
|
||||
name: _fileName,
|
||||
modifiedTime: DateTime.now(),
|
||||
);
|
||||
final updated = await api.files.update(
|
||||
file,
|
||||
existingId,
|
||||
uploadMedia: media,
|
||||
$fields: 'id, modifiedTime',
|
||||
);
|
||||
return DriveBackupResult.ok(
|
||||
updated.id!,
|
||||
updated.modifiedTime!,
|
||||
);
|
||||
} else {
|
||||
final file = drive.File(
|
||||
name: _fileName,
|
||||
parents: [_appDataFolder],
|
||||
modifiedTime: DateTime.now(),
|
||||
);
|
||||
final created = await api.files.create(
|
||||
file,
|
||||
uploadMedia: media,
|
||||
$fields: 'id, modifiedTime',
|
||||
);
|
||||
return DriveBackupResult.ok(
|
||||
created.id!,
|
||||
created.modifiedTime!,
|
||||
);
|
||||
}
|
||||
} catch (e) {
|
||||
return DriveBackupResult.failed(e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
Future<Uint8List?> downloadBackup() async {
|
||||
final api = await _getDriveApi();
|
||||
if (api == null) return null;
|
||||
|
||||
try {
|
||||
final fileId = await _findExistingFile(api);
|
||||
if (fileId == null) return null;
|
||||
|
||||
final media = await api.files.get(
|
||||
fileId,
|
||||
downloadOptions: drive.DownloadOptions.fullMedia,
|
||||
) as drive.Media;
|
||||
|
||||
final bytes = <int>[];
|
||||
await for (final chunk in media.stream) {
|
||||
bytes.addAll(chunk);
|
||||
}
|
||||
return Uint8List.fromList(bytes);
|
||||
} catch (e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Future<DateTime?> getLastBackupTime() async {
|
||||
final api = await _getDriveApi();
|
||||
if (api == null) return null;
|
||||
|
||||
try {
|
||||
final list = await api.files.list(
|
||||
spaces: _appDataFolder,
|
||||
q: "name = '$_fileName' and trashed = false",
|
||||
$fields: 'files(id, name, modifiedTime)',
|
||||
);
|
||||
if (list.files?.isNotEmpty == true) {
|
||||
return list.files!.first.modifiedTime;
|
||||
}
|
||||
return null;
|
||||
} catch (e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
class OnboardingService {
|
||||
static const _key = 'onboarding_completed';
|
||||
static bool _shownInSession = false;
|
||||
static SharedPreferences? _staticPrefs;
|
||||
|
||||
final SharedPreferences _prefs;
|
||||
|
||||
OnboardingService(this._prefs) {
|
||||
_staticPrefs = _prefs;
|
||||
}
|
||||
|
||||
static bool get shouldShowOnboarding {
|
||||
if (kDebugMode) {
|
||||
return !_shownInSession;
|
||||
}
|
||||
return !(_staticPrefs?.getBool(_key) ?? false);
|
||||
}
|
||||
|
||||
static void markCompleted() {
|
||||
_shownInSession = true;
|
||||
}
|
||||
|
||||
bool get shouldShowOnboardingInstance => shouldShowOnboarding;
|
||||
|
||||
Future<void> completeOnboarding() async {
|
||||
_shownInSession = true;
|
||||
if (!kDebugMode) {
|
||||
await _prefs.setBool(_key, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import '../models/user_model.dart';
|
||||
import 'billing_service.dart';
|
||||
|
||||
class PremiumManager {
|
||||
static const _keyIsPremium = 'is_premium';
|
||||
static const _keyPurchaseToken = 'purchase_token';
|
||||
|
||||
final SharedPreferences _prefs;
|
||||
final BillingService _billing;
|
||||
|
||||
PremiumManager(this._prefs, this._billing);
|
||||
|
||||
bool get isPremium => _prefs.getBool(_keyIsPremium) ?? false;
|
||||
String? get purchaseToken => _prefs.getString(_keyPurchaseToken);
|
||||
|
||||
Future<void> _setPremium(bool value, String? token) async {
|
||||
await _prefs.setBool(_keyIsPremium, value);
|
||||
if (token != null) {
|
||||
await _prefs.setString(_keyPurchaseToken, token);
|
||||
} else if (!value) {
|
||||
await _prefs.remove(_keyPurchaseToken);
|
||||
}
|
||||
}
|
||||
|
||||
Future<PurchaseResult> purchase() async {
|
||||
if (isPremium) {
|
||||
return PurchaseResult.ok(purchaseToken ?? 'existing');
|
||||
}
|
||||
final result = await _billing.purchasePro();
|
||||
if (result.success && result.purchaseToken != null) {
|
||||
await _setPremium(true, result.purchaseToken);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
Future<PurchaseResult> restore() async {
|
||||
final result = await _billing.restorePurchases();
|
||||
if (result.success && result.purchaseToken != null) {
|
||||
await _setPremium(true, result.purchaseToken);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
Future<void> autoRestore() async {
|
||||
if (isPremium) return;
|
||||
final result = await _billing.queryPastPurchase();
|
||||
if (result.success && result.purchaseToken != null) {
|
||||
await _setPremium(true, result.purchaseToken);
|
||||
}
|
||||
}
|
||||
|
||||
UserPlan get currentPlan => isPremium ? UserPlan.vip : UserPlan.free;
|
||||
|
||||
Future<void> clear() async {
|
||||
await _setPremium(false, null);
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,6 @@ const _uuid = Uuid();
|
||||
|
||||
class StorageService {
|
||||
static const _transactionsKey = 'transactions';
|
||||
static const _budgetKey = 'monthly_budget';
|
||||
static const _currencyKey = 'currency_symbol';
|
||||
static const _themeKey = 'is_dark_mode';
|
||||
|
||||
@@ -90,23 +89,6 @@ class StorageService {
|
||||
});
|
||||
}
|
||||
|
||||
double? loadBudget() {
|
||||
return _prefs.getDouble(_budgetKey);
|
||||
}
|
||||
|
||||
Future<Result<void>> saveBudget(double? budget) async {
|
||||
return asyncResultOf(() async {
|
||||
if (budget == null) {
|
||||
await _prefs.remove(_budgetKey);
|
||||
} else {
|
||||
if (budget < 0) {
|
||||
throw Exception('Budget cannot be negative');
|
||||
}
|
||||
await _prefs.setDouble(_budgetKey, budget);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
String loadCurrency() {
|
||||
return _prefs.getString(_currencyKey) ?? '\$';
|
||||
}
|
||||
|
||||
@@ -0,0 +1,107 @@
|
||||
import 'dart:convert';
|
||||
import 'package:http/http.dart' as http;
|
||||
|
||||
enum TranslateDirection { ruToEn, enToRu }
|
||||
|
||||
class TranslationResult {
|
||||
final String text;
|
||||
final bool fromCache;
|
||||
|
||||
const TranslationResult(this.text, {this.fromCache = false});
|
||||
}
|
||||
|
||||
class TranslationService {
|
||||
static const Map<String, String> _ruToEn = {
|
||||
'еда': 'Food',
|
||||
'продукты': 'Groceries',
|
||||
'транспорт': 'Transport',
|
||||
'покупки': 'Shopping',
|
||||
'здоровье': 'Health',
|
||||
'развлечения': 'Entertainment',
|
||||
'жильё': 'Housing',
|
||||
'жилье': 'Housing',
|
||||
'аренда': 'Rent',
|
||||
'образование': 'Education',
|
||||
'путешествия': 'Travel',
|
||||
'зарплата': 'Salary',
|
||||
'фриланс': 'Freelance',
|
||||
'инвестиции': 'Investment',
|
||||
'подарок': 'Gift',
|
||||
'подарки': 'Gifts',
|
||||
'возврат': 'Refund',
|
||||
'другое': 'Other',
|
||||
'коммунальные': 'Utilities',
|
||||
'одежда': 'Clothing',
|
||||
'спорт': 'Sports',
|
||||
'красота': 'Beauty',
|
||||
'питомцы': 'Pets',
|
||||
'животные': 'Pets',
|
||||
'бизнес': 'Business',
|
||||
'накопления': 'Savings',
|
||||
'кафе': 'Cafe',
|
||||
'кофе': 'Coffee',
|
||||
'ресторан': 'Restaurant',
|
||||
'связь': 'Communication',
|
||||
'интернет': 'Internet',
|
||||
'налоги': 'Taxes',
|
||||
'страховка': 'Insurance',
|
||||
'медицина': 'Medicine',
|
||||
'дети': 'Children',
|
||||
'хобби': 'Hobby',
|
||||
'музыка': 'Music',
|
||||
'игры': 'Games',
|
||||
'книги': 'Books',
|
||||
'топливо': 'Fuel',
|
||||
'такси': 'Taxi',
|
||||
};
|
||||
|
||||
static final Map<String, String> _enToRu = {
|
||||
for (final entry in _ruToEn.entries) entry.value.toLowerCase(): entry.key,
|
||||
};
|
||||
|
||||
String? dictionaryLookup(String input, TranslateDirection direction) {
|
||||
final normalized = input.trim().toLowerCase();
|
||||
if (normalized.isEmpty) return null;
|
||||
final map = direction == TranslateDirection.ruToEn ? _ruToEn : _enToRu;
|
||||
final hit = map[normalized];
|
||||
if (hit == null) return null;
|
||||
return _capitalize(hit);
|
||||
}
|
||||
|
||||
Future<TranslationResult?> translate(
|
||||
String input,
|
||||
TranslateDirection direction,
|
||||
) async {
|
||||
final trimmed = input.trim();
|
||||
if (trimmed.isEmpty) return null;
|
||||
|
||||
final cached = dictionaryLookup(trimmed, direction);
|
||||
if (cached != null) {
|
||||
return TranslationResult(cached, fromCache: true);
|
||||
}
|
||||
|
||||
final pair = direction == TranslateDirection.ruToEn ? 'ru|en' : 'en|ru';
|
||||
final uri = Uri.parse(
|
||||
'https://api.mymemory.translated.net/get'
|
||||
'?q=${Uri.encodeQueryComponent(trimmed)}&langpair=$pair',
|
||||
);
|
||||
|
||||
try {
|
||||
final response =
|
||||
await http.get(uri).timeout(const Duration(seconds: 8));
|
||||
if (response.statusCode != 200) return null;
|
||||
final decoded = jsonDecode(response.body) as Map<String, dynamic>;
|
||||
final data = decoded['responseData'] as Map<String, dynamic>?;
|
||||
final translated = data?['translatedText'] as String?;
|
||||
if (translated == null || translated.trim().isEmpty) return null;
|
||||
return TranslationResult(_capitalize(translated.trim()));
|
||||
} catch (_) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
String _capitalize(String value) {
|
||||
if (value.isEmpty) return value;
|
||||
return value[0].toUpperCase() + value.substring(1);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import '../../core/services/card_color_service.dart';
|
||||
|
||||
Gradient buildCardGradient(Color primary, Color secondary, GradientType type) {
|
||||
final colorDark = Color.lerp(secondary, Colors.black, 0.3)!;
|
||||
|
||||
switch (type) {
|
||||
case GradientType.linear:
|
||||
return LinearGradient(
|
||||
begin: Alignment.topLeft,
|
||||
end: Alignment.bottomRight,
|
||||
colors: [primary, secondary, colorDark],
|
||||
stops: const [0.0, 0.6, 1.0],
|
||||
);
|
||||
case GradientType.linearReverse:
|
||||
return LinearGradient(
|
||||
begin: Alignment.topRight,
|
||||
end: Alignment.bottomLeft,
|
||||
colors: [primary, secondary, colorDark],
|
||||
stops: const [0.0, 0.6, 1.0],
|
||||
);
|
||||
case GradientType.radial:
|
||||
return RadialGradient(
|
||||
center: Alignment.center,
|
||||
radius: 1.4,
|
||||
colors: [primary, secondary, colorDark],
|
||||
stops: const [0.0, 0.6, 1.0],
|
||||
);
|
||||
case GradientType.sweep:
|
||||
return SweepGradient(
|
||||
center: Alignment.center,
|
||||
startAngle: 0.0,
|
||||
endAngle: 3.14159 * 2,
|
||||
colors: [primary, secondary, colorDark, secondary, primary],
|
||||
stops: const [0.0, 0.25, 0.5, 0.75, 1.0],
|
||||
);
|
||||
case GradientType.solid:
|
||||
return LinearGradient(
|
||||
colors: [primary, primary, primary],
|
||||
stops: const [0.0, 0.5, 1.0],
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,360 @@
|
||||
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';
|
||||
import '../../core/services/haptic_service.dart';
|
||||
import '../providers/backup_provider.dart';
|
||||
import '../providers/google_drive_provider.dart';
|
||||
import '../providers/premium_provider.dart';
|
||||
import 'error_snackbar.dart';
|
||||
import '../services/backup_service.dart';
|
||||
|
||||
class BackupScreen extends ConsumerStatefulWidget {
|
||||
const BackupScreen({super.key});
|
||||
|
||||
@override
|
||||
ConsumerState<BackupScreen> createState() => _BackupScreenState();
|
||||
}
|
||||
|
||||
class _BackupScreenState extends ConsumerState<BackupScreen> {
|
||||
bool _backingUp = false;
|
||||
bool _restoring = false;
|
||||
DateTime? _lastBackupTime;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_loadLastBackupTime();
|
||||
}
|
||||
|
||||
Future<void> _loadLastBackupTime() async {
|
||||
final service = ref.read(googleDriveServiceProvider);
|
||||
final time = await service.getLastBackupTime();
|
||||
if (mounted) {
|
||||
setState(() => _lastBackupTime = time);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _handleBackup() async {
|
||||
final s = ref.read(stringsProvider);
|
||||
final driveService = ref.read(googleDriveServiceProvider);
|
||||
|
||||
if (driveService.currentUser == null) {
|
||||
showErrorSnackbar(context, s.backupRequiresSignIn);
|
||||
return;
|
||||
}
|
||||
|
||||
HapticService.light();
|
||||
setState(() => _backingUp = true);
|
||||
|
||||
try {
|
||||
final backupService = ref.read(backupServiceProvider);
|
||||
final payload = <String, dynamic>{
|
||||
'version': 1,
|
||||
'exported_at': DateTime.now().toIso8601String(),
|
||||
};
|
||||
final data = backupService.createBackup(payload);
|
||||
final result = await driveService.uploadBackup(data);
|
||||
|
||||
if (result.success) {
|
||||
setState(() => _lastBackupTime = result.modifiedTime);
|
||||
HapticService.medium();
|
||||
if (mounted) {
|
||||
showSuccessSnackbar(context, s.backupSuccess);
|
||||
}
|
||||
} else {
|
||||
if (mounted) {
|
||||
showErrorSnackbar(context, result.error ?? s.backupRestoreFailed);
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
if (mounted) {
|
||||
showErrorSnackbar(context, e.toString());
|
||||
}
|
||||
} finally {
|
||||
if (mounted) setState(() => _backingUp = false);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _handleRestore() async {
|
||||
final s = ref.read(stringsProvider);
|
||||
final driveService = ref.read(googleDriveServiceProvider);
|
||||
|
||||
if (driveService.currentUser == null) {
|
||||
showErrorSnackbar(context, s.backupRequiresSignIn);
|
||||
return;
|
||||
}
|
||||
|
||||
HapticService.light();
|
||||
setState(() => _restoring = true);
|
||||
|
||||
try {
|
||||
final raw = await driveService.downloadBackup();
|
||||
if (raw == null) {
|
||||
if (mounted) {
|
||||
showWarningSnackbar(context, s.backupNoFileFound);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
final backupService = ref.read(backupServiceProvider);
|
||||
final (result, data) = backupService.verifyAndParse(raw);
|
||||
|
||||
switch (result) {
|
||||
case BackupVerifyResult.ok:
|
||||
HapticService.medium();
|
||||
if (mounted) {
|
||||
showSuccessSnackbar(context, s.backupRestoreSuccess);
|
||||
}
|
||||
case BackupVerifyResult.tokenMismatch:
|
||||
if (mounted) {
|
||||
showErrorSnackbar(context, s.backupTokenMismatch);
|
||||
}
|
||||
case BackupVerifyResult.noToken:
|
||||
if (mounted) {
|
||||
showErrorSnackbar(context, s.backupNoToken);
|
||||
}
|
||||
case BackupVerifyResult.invalidFormat:
|
||||
if (mounted) {
|
||||
showErrorSnackbar(context, s.backupInvalidFormat);
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
if (mounted) {
|
||||
showErrorSnackbar(context, e.toString());
|
||||
}
|
||||
} finally {
|
||||
if (mounted) setState(() => _restoring = false);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final s = ref.watch(stringsProvider);
|
||||
final isPremium = ref.watch(isPremiumProvider);
|
||||
final driveUserAsync = ref.watch(googleDriveUserProvider);
|
||||
final driveUser = driveUserAsync.value;
|
||||
final colorScheme = Theme.of(context).colorScheme;
|
||||
|
||||
return Scaffold(
|
||||
body: SafeArea(
|
||||
child: Column(
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(8, 4, 16, 0),
|
||||
child: Row(
|
||||
children: [
|
||||
IconButton(
|
||||
icon: const Icon(Icons.arrow_back_rounded),
|
||||
onPressed: () => context.pop(),
|
||||
),
|
||||
Text(
|
||||
s.backupTitle,
|
||||
style: Theme.of(context).textTheme.titleLarge?.copyWith(
|
||||
fontWeight: FontWeight.w800,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: SingleChildScrollView(
|
||||
padding: const EdgeInsets.all(20),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
if (!isPremium) ...[
|
||||
_buildLockedState(context, s, colorScheme),
|
||||
] else ...[
|
||||
_buildSyncStatus(context, s, colorScheme, driveUser),
|
||||
const SizedBox(height: 20),
|
||||
_buildBackupActions(context, s, colorScheme, driveUser),
|
||||
const SizedBox(height: 20),
|
||||
_buildLastBackup(context, s, colorScheme),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildLockedState(
|
||||
BuildContext context,
|
||||
AppStrings s,
|
||||
ColorScheme colorScheme,
|
||||
) {
|
||||
return Container(
|
||||
width: double.infinity,
|
||||
padding: const EdgeInsets.all(24),
|
||||
decoration: BoxDecoration(
|
||||
color: colorScheme.surface,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
border: Border.all(color: colorScheme.outlineVariant),
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
Icon(Icons.lock_outline_rounded, size: 48, color: colorScheme.primary),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
s.backupRequiresPremium,
|
||||
style: Theme.of(context).textTheme.titleMedium?.copyWith(
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
FilledButton(
|
||||
onPressed: () => context.push('/pro'),
|
||||
child: Text(s.proBuy),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildSyncStatus(
|
||||
BuildContext context,
|
||||
AppStrings s,
|
||||
ColorScheme colorScheme,
|
||||
dynamic driveUser,
|
||||
) {
|
||||
return Container(
|
||||
width: double.infinity,
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
color: colorScheme.surface,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
border: Border.all(color: colorScheme.outlineVariant),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Icon(
|
||||
driveUser != null
|
||||
? Icons.cloud_done_rounded
|
||||
: Icons.cloud_off_rounded,
|
||||
color: driveUser != null ? colorScheme.primary : colorScheme.onSurface.withOpacity(0.4),
|
||||
size: 24,
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Text(
|
||||
driveUser != null
|
||||
? s.proSyncEnabled
|
||||
: s.backupRequiresSignIn,
|
||||
style: Theme.of(context).textTheme.titleMedium?.copyWith(
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
if (driveUser != null) ...[
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
driveUser.email,
|
||||
style: Theme.of(context).textTheme.bodySmall?.copyWith(
|
||||
color: colorScheme.onSurface.withOpacity(0.6),
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildBackupActions(
|
||||
BuildContext context,
|
||||
AppStrings s,
|
||||
ColorScheme colorScheme,
|
||||
dynamic driveUser,
|
||||
) {
|
||||
final disabled = driveUser == null;
|
||||
return Column(
|
||||
children: [
|
||||
SizedBox(
|
||||
width: double.infinity,
|
||||
child: FilledButton.icon(
|
||||
onPressed: (disabled || _backingUp) ? null : _handleBackup,
|
||||
icon: _backingUp
|
||||
? SizedBox(
|
||||
width: 18,
|
||||
height: 18,
|
||||
child: CircularProgressIndicator(
|
||||
strokeWidth: 2,
|
||||
color: colorScheme.onPrimary,
|
||||
),
|
||||
)
|
||||
: const Icon(Icons.backup_outlined),
|
||||
label: Text(_backingUp ? s.backupCreating : s.backupCreate),
|
||||
style: FilledButton.styleFrom(
|
||||
padding: const EdgeInsets.symmetric(vertical: 14),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
SizedBox(
|
||||
width: double.infinity,
|
||||
child: OutlinedButton.icon(
|
||||
onPressed: (disabled || _restoring) ? null : _handleRestore,
|
||||
icon: _restoring
|
||||
? SizedBox(
|
||||
width: 18,
|
||||
height: 18,
|
||||
child: CircularProgressIndicator(
|
||||
strokeWidth: 2,
|
||||
color: colorScheme.primary,
|
||||
),
|
||||
)
|
||||
: const Icon(Icons.restore_rounded),
|
||||
label: Text(_restoring ? s.backupRestoring : s.backupRestore),
|
||||
style: OutlinedButton.styleFrom(
|
||||
padding: const EdgeInsets.symmetric(vertical: 14),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildLastBackup(
|
||||
BuildContext context,
|
||||
AppStrings s,
|
||||
ColorScheme colorScheme,
|
||||
) {
|
||||
return Row(
|
||||
children: [
|
||||
Icon(
|
||||
Icons.schedule_rounded,
|
||||
size: 18,
|
||||
color: colorScheme.onSurface.withOpacity(0.5),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Text(
|
||||
'${s.backupLastBackup}: ${_lastBackupTime != null ? _formatDate(_lastBackupTime!) : s.backupNever}',
|
||||
style: Theme.of(context).textTheme.bodySmall?.copyWith(
|
||||
color: colorScheme.onSurface.withOpacity(0.5),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
String _formatDate(DateTime dt) {
|
||||
final d = dt.toLocal();
|
||||
return '${d.day.toString().padLeft(2, '0')}.${d.month.toString().padLeft(2, '0')}.${d.year} ${d.hour.toString().padLeft(2, '0')}:${d.minute.toString().padLeft(2, '0')}';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,528 @@
|
||||
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';
|
||||
import '../../core/services/haptic_service.dart';
|
||||
import '../providers/current_user_provider.dart';
|
||||
import '../providers/premium_provider.dart';
|
||||
import 'error_snackbar.dart';
|
||||
|
||||
class ProScreen extends ConsumerStatefulWidget {
|
||||
const ProScreen({super.key});
|
||||
|
||||
@override
|
||||
ConsumerState<ProScreen> createState() => _ProScreenState();
|
||||
}
|
||||
|
||||
class _ProScreenState extends ConsumerState<ProScreen>
|
||||
with SingleTickerProviderStateMixin {
|
||||
bool _purchasing = false;
|
||||
bool _restoring = false;
|
||||
bool _resetting = false;
|
||||
bool _showSuccess = false;
|
||||
String _successTitle = '';
|
||||
late final AnimationController _successController;
|
||||
late final Animation<double> _successScale;
|
||||
|
||||
static const _gradientColors = [
|
||||
Color(0xFF5B4DCC),
|
||||
Color(0xFF7C6DED),
|
||||
Color(0xFF9D8FF5),
|
||||
];
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_successController = AnimationController(
|
||||
vsync: this,
|
||||
duration: const Duration(milliseconds: 400),
|
||||
);
|
||||
_successScale = Tween<double>(begin: 0.0, end: 1.0).animate(
|
||||
CurvedAnimation(
|
||||
parent: _successController,
|
||||
curve: Curves.elasticOut,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_successController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _showSuccessOverlay(String title) {
|
||||
setState(() {
|
||||
_successTitle = title;
|
||||
_showSuccess = true;
|
||||
});
|
||||
_successController.forward(from: 0.0);
|
||||
}
|
||||
|
||||
void _dismissSuccessOverlay() {
|
||||
_successController.stop();
|
||||
if (mounted) {
|
||||
setState(() => _showSuccess = false);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final s = ref.watch(stringsProvider);
|
||||
final isPremium = ref.watch(isPremiumProvider);
|
||||
final colorScheme = Theme.of(context).colorScheme;
|
||||
|
||||
return Stack(
|
||||
children: [
|
||||
Scaffold(
|
||||
body: SafeArea(
|
||||
child: Column(
|
||||
children: [
|
||||
_buildHeader(context),
|
||||
Expanded(
|
||||
child: SingleChildScrollView(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 20),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const SizedBox(height: 4),
|
||||
_buildHeroBanner(context, s, isPremium),
|
||||
const SizedBox(height: 20),
|
||||
_buildFeatureList(context, s, colorScheme),
|
||||
const SizedBox(height: 16),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
_buildBottomBar(context, s, colorScheme, isPremium),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
if (_showSuccess) _buildSuccessOverlay(context, s, colorScheme),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildHeader(BuildContext context) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.fromLTRB(8, 4, 16, 0),
|
||||
child: Row(
|
||||
children: [
|
||||
IconButton(
|
||||
icon: const Icon(Icons.arrow_back_rounded),
|
||||
onPressed: () => context.pop(),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildHeroBanner(
|
||||
BuildContext context,
|
||||
AppStrings s,
|
||||
bool isVip,
|
||||
) {
|
||||
return Container(
|
||||
width: double.infinity,
|
||||
padding: const EdgeInsets.symmetric(vertical: 36, horizontal: 20),
|
||||
decoration: BoxDecoration(
|
||||
gradient: const LinearGradient(
|
||||
begin: Alignment.topLeft,
|
||||
end: Alignment.bottomRight,
|
||||
colors: _gradientColors,
|
||||
),
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
s.proTitle,
|
||||
style: Theme.of(context).textTheme.displaySmall?.copyWith(
|
||||
fontWeight: FontWeight.w900,
|
||||
color: Colors.white,
|
||||
letterSpacing: -0.5,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 6),
|
||||
Text(
|
||||
isVip ? s.proActive : s.proSubtitle,
|
||||
style: Theme.of(context).textTheme.titleMedium?.copyWith(
|
||||
color: Colors.white.withOpacity(0.9),
|
||||
fontWeight: isVip ? FontWeight.w700 : FontWeight.w500,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildSuccessOverlay(
|
||||
BuildContext context,
|
||||
AppStrings s,
|
||||
ColorScheme colorScheme,
|
||||
) {
|
||||
return GestureDetector(
|
||||
onTap: _dismissSuccessOverlay,
|
||||
child: Container(
|
||||
color: Colors.black54,
|
||||
child: Center(
|
||||
child: GestureDetector(
|
||||
onTap: _dismissSuccessOverlay,
|
||||
child: AnimatedBuilder(
|
||||
animation: _successController,
|
||||
builder: (context, child) {
|
||||
return Transform.scale(
|
||||
scale: _successScale.value,
|
||||
child: child,
|
||||
);
|
||||
},
|
||||
child: Container(
|
||||
padding: const EdgeInsets.all(32),
|
||||
margin: const EdgeInsets.symmetric(horizontal: 40),
|
||||
decoration: BoxDecoration(
|
||||
color: colorScheme.surface,
|
||||
borderRadius: BorderRadius.circular(24),
|
||||
),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
color: colorScheme.primary.withOpacity(0.15),
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
child: Icon(
|
||||
Icons.check_circle_rounded,
|
||||
color: colorScheme.primary,
|
||||
size: 64,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
Text(
|
||||
_successTitle,
|
||||
style: Theme.of(context).textTheme.titleLarge?.copyWith(
|
||||
fontWeight: FontWeight.w800,
|
||||
color: colorScheme.onSurface,
|
||||
),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
Text(
|
||||
s.proTapToClose,
|
||||
style: Theme.of(context).textTheme.bodySmall?.copyWith(
|
||||
color: colorScheme.onSurface.withOpacity(0.5),
|
||||
),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildFeatureList(
|
||||
BuildContext context,
|
||||
AppStrings s,
|
||||
ColorScheme colorScheme,
|
||||
) {
|
||||
final features = [
|
||||
(Icons.analytics_rounded, s.proFeatureAnalytics, s.proFeatureAnalyticsDesc),
|
||||
(Icons.palette_rounded, s.proFeatureCustomization, s.proFeatureCustomizationDesc),
|
||||
(Icons.fingerprint_rounded, s.proFeatureBiometric, s.proFeatureBiometricDesc),
|
||||
(Icons.account_balance_wallet_rounded, s.proFeatureAccounts, s.proFeatureAccountsDesc),
|
||||
];
|
||||
|
||||
return Column(
|
||||
children: features.map((f) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(bottom: 14),
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Container(
|
||||
padding: const EdgeInsets.all(10),
|
||||
decoration: BoxDecoration(
|
||||
color: colorScheme.primary.withOpacity(0.1),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: Icon(
|
||||
f.$1,
|
||||
color: colorScheme.primary,
|
||||
size: 22,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 14),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
f.$2,
|
||||
style: Theme.of(context).textTheme.titleSmall?.copyWith(
|
||||
fontWeight: FontWeight.w700,
|
||||
color: colorScheme.onSurface,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
f.$3,
|
||||
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
|
||||
color: colorScheme.onSurface.withOpacity(0.6),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}).toList(),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildBottomBar(
|
||||
BuildContext context,
|
||||
AppStrings s,
|
||||
ColorScheme colorScheme,
|
||||
bool isVip,
|
||||
) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.fromLTRB(20, 12, 20, 24),
|
||||
decoration: BoxDecoration(
|
||||
color: Theme.of(context).scaffoldBackgroundColor,
|
||||
border: Border(
|
||||
top: BorderSide(
|
||||
color: colorScheme.outlineVariant.withOpacity(0.3),
|
||||
width: 1,
|
||||
),
|
||||
),
|
||||
),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
if (!isVip) ...[
|
||||
SizedBox(
|
||||
width: double.infinity,
|
||||
child: FilledButton(
|
||||
onPressed: _purchasing ? null : _handlePurchase,
|
||||
style: FilledButton.styleFrom(
|
||||
padding: const EdgeInsets.symmetric(vertical: 16),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
),
|
||||
child: _purchasing
|
||||
? SizedBox(
|
||||
width: 20,
|
||||
height: 20,
|
||||
child: CircularProgressIndicator(
|
||||
strokeWidth: 2,
|
||||
color: colorScheme.onPrimary,
|
||||
),
|
||||
)
|
||||
: Text(
|
||||
s.proBuy,
|
||||
style: const TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w700,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
SizedBox(
|
||||
width: double.infinity,
|
||||
child: TextButton(
|
||||
onPressed: _restoring ? null : _handleRestore,
|
||||
child: _restoring
|
||||
? SizedBox(
|
||||
width: 16,
|
||||
height: 16,
|
||||
child: CircularProgressIndicator(
|
||||
strokeWidth: 2,
|
||||
color: colorScheme.primary,
|
||||
),
|
||||
)
|
||||
: Text(s.proRestorePurchases),
|
||||
),
|
||||
),
|
||||
] else ...[
|
||||
Container(
|
||||
width: double.infinity,
|
||||
padding: const EdgeInsets.symmetric(vertical: 12, horizontal: 16),
|
||||
decoration: BoxDecoration(
|
||||
color: colorScheme.primary.withOpacity(0.08),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
border: Border.all(
|
||||
color: colorScheme.primary.withOpacity(0.2),
|
||||
width: 1,
|
||||
),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(
|
||||
Icons.verified_rounded,
|
||||
color: colorScheme.primary,
|
||||
size: 20,
|
||||
),
|
||||
const SizedBox(width: 10),
|
||||
Expanded(
|
||||
child: Text(
|
||||
s.proActive,
|
||||
style: TextStyle(
|
||||
color: colorScheme.primary,
|
||||
fontWeight: FontWeight.w700,
|
||||
fontSize: 14,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
SizedBox(
|
||||
width: double.infinity,
|
||||
child: OutlinedButton.icon(
|
||||
onPressed: _resetting ? null : _handleResetData,
|
||||
icon: _resetting
|
||||
? SizedBox(
|
||||
width: 16,
|
||||
height: 16,
|
||||
child: CircularProgressIndicator(
|
||||
strokeWidth: 2,
|
||||
color: colorScheme.onSurface.withOpacity(0.5),
|
||||
),
|
||||
)
|
||||
: Icon(
|
||||
Icons.restart_alt_rounded,
|
||||
size: 18,
|
||||
color: colorScheme.onSurface.withOpacity(0.6),
|
||||
),
|
||||
label: Text(
|
||||
s.proResetData,
|
||||
style: TextStyle(
|
||||
fontSize: 13,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: colorScheme.onSurface.withOpacity(0.6),
|
||||
),
|
||||
),
|
||||
style: OutlinedButton.styleFrom(
|
||||
padding: const EdgeInsets.symmetric(vertical: 12),
|
||||
side: BorderSide(
|
||||
color: colorScheme.onSurface.withOpacity(0.15),
|
||||
),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _handlePurchase() async {
|
||||
HapticService.light();
|
||||
setState(() => _purchasing = true);
|
||||
try {
|
||||
final manager = ref.read(premiumManagerProvider);
|
||||
final result = await manager.purchase();
|
||||
if (result.success) {
|
||||
await ref.read(currentUserProvider.notifier).refreshFromPremium();
|
||||
if (mounted) {
|
||||
_showSuccessOverlay(ref.read(stringsProvider).proPurchaseSuccess);
|
||||
HapticService.medium();
|
||||
}
|
||||
} else {
|
||||
if (mounted) {
|
||||
showErrorSnackbar(context, result.error ?? ref.read(stringsProvider).proPurchaseFailed);
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
if (mounted) {
|
||||
showErrorSnackbar(context, e.toString());
|
||||
}
|
||||
} finally {
|
||||
if (mounted) setState(() => _purchasing = false);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _handleRestore() async {
|
||||
HapticService.light();
|
||||
setState(() => _restoring = true);
|
||||
try {
|
||||
final manager = ref.read(premiumManagerProvider);
|
||||
final result = await manager.restore();
|
||||
if (result.success) {
|
||||
await ref.read(currentUserProvider.notifier).refreshFromPremium();
|
||||
if (mounted) {
|
||||
_showSuccessOverlay(ref.read(stringsProvider).proRestoreSuccessTitle);
|
||||
HapticService.medium();
|
||||
}
|
||||
} else {
|
||||
if (mounted) {
|
||||
showWarningSnackbar(context, ref.read(stringsProvider).proRestoreNotFound);
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
if (mounted) {
|
||||
showErrorSnackbar(context, e.toString());
|
||||
}
|
||||
} finally {
|
||||
if (mounted) setState(() => _restoring = false);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _handleResetData() async {
|
||||
final s = ref.read(stringsProvider);
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (ctx) => AlertDialog(
|
||||
title: Text(s.proResetData),
|
||||
content: Text(s.proResetDataConfirm),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(ctx),
|
||||
child: Text(s.cancel),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () async {
|
||||
Navigator.pop(ctx);
|
||||
HapticService.light();
|
||||
setState(() => _resetting = true);
|
||||
try {
|
||||
final manager = ref.read(premiumManagerProvider);
|
||||
await manager.clear();
|
||||
await ref.read(currentUserProvider.notifier).refreshFromPremium();
|
||||
if (mounted) {
|
||||
showSuccessSnackbar(context, s.proResetDataSuccess);
|
||||
HapticService.medium();
|
||||
}
|
||||
} catch (e) {
|
||||
if (mounted) {
|
||||
showErrorSnackbar(context, e.toString());
|
||||
}
|
||||
} finally {
|
||||
if (mounted) setState(() => _resetting = false);
|
||||
}
|
||||
},
|
||||
style: TextButton.styleFrom(
|
||||
foregroundColor: const Color(0xFFE05C6B),
|
||||
),
|
||||
child: Text(s.proResetData),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,264 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import '../../core/l10n/locale_provider.dart';
|
||||
import '../../core/services/haptic_service.dart';
|
||||
import '../providers/premium_provider.dart';
|
||||
|
||||
class ProSubscriptionCard extends StatefulWidget {
|
||||
const ProSubscriptionCard({super.key});
|
||||
|
||||
@override
|
||||
State<ProSubscriptionCard> createState() =>
|
||||
_ProSubscriptionCardState();
|
||||
}
|
||||
|
||||
class _ProSubscriptionCardState extends State<ProSubscriptionCard>
|
||||
with SingleTickerProviderStateMixin {
|
||||
late final AnimationController _shimmerController;
|
||||
|
||||
static const _gradientColors = [
|
||||
Color(0xFF5B4DCC),
|
||||
Color(0xFF7C6DED),
|
||||
Color(0xFF9D8FF5),
|
||||
];
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_shimmerController = AnimationController(
|
||||
vsync: this,
|
||||
duration: const Duration(milliseconds: 2800),
|
||||
)..repeat();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_shimmerController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Consumer(
|
||||
builder: (context, ref, _) {
|
||||
final s = ref.watch(stringsProvider);
|
||||
final isPremium = ref.watch(isPremiumProvider);
|
||||
|
||||
return ClipRRect(
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
child: Stack(
|
||||
children: [
|
||||
Container(
|
||||
padding: const EdgeInsets.fromLTRB(20, 22, 20, 18),
|
||||
decoration: const BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
begin: Alignment.topLeft,
|
||||
end: Alignment.bottomRight,
|
||||
colors: _gradientColors,
|
||||
),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Container(
|
||||
padding: const EdgeInsets.all(10),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white.withOpacity(0.18),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
border: Border.all(
|
||||
color: Colors.white.withOpacity(0.25),
|
||||
width: 1,
|
||||
),
|
||||
),
|
||||
child: Icon(
|
||||
isPremium
|
||||
? Icons.verified_rounded
|
||||
: Icons.workspace_premium_rounded,
|
||||
color: Colors.white,
|
||||
size: 26,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 14),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
s.proTitle,
|
||||
style: Theme.of(context)
|
||||
.textTheme
|
||||
.titleLarge
|
||||
?.copyWith(
|
||||
fontWeight: FontWeight.w800,
|
||||
color: Colors.white,
|
||||
letterSpacing: -0.3,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 3),
|
||||
Text(
|
||||
isPremium ? s.proActive : s.proSubtitle,
|
||||
style: isPremium
|
||||
? Theme.of(context)
|
||||
.textTheme
|
||||
.bodyMedium
|
||||
?.copyWith(
|
||||
color: Colors.white.withOpacity(0.95),
|
||||
fontWeight: FontWeight.w600,
|
||||
)
|
||||
: Theme.of(context)
|
||||
.textTheme
|
||||
.bodySmall
|
||||
?.copyWith(
|
||||
color: Colors.white.withOpacity(0.75),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
if (isPremium)
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 10,
|
||||
vertical: 5,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white.withOpacity(0.2),
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
border: Border.all(
|
||||
color: Colors.white.withOpacity(0.3),
|
||||
width: 1,
|
||||
),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(
|
||||
Icons.check_circle_rounded,
|
||||
color: Colors.white.withOpacity(0.95),
|
||||
size: 14,
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
Text(
|
||||
'Pro',
|
||||
style: TextStyle(
|
||||
color: Colors.white.withOpacity(0.95),
|
||||
fontSize: 11,
|
||||
fontWeight: FontWeight.w700,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 18),
|
||||
SizedBox(
|
||||
width: double.infinity,
|
||||
child: _GlassButton(
|
||||
label: s.proAboutPro,
|
||||
icon: Icons.arrow_forward_rounded,
|
||||
onTap: () {
|
||||
HapticService.light();
|
||||
context.push('/pro');
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
Positioned.fill(
|
||||
child: IgnorePointer(
|
||||
child: AnimatedBuilder(
|
||||
animation: _shimmerController,
|
||||
builder: (context, _) {
|
||||
final t = _shimmerController.value;
|
||||
final startX = -1.5;
|
||||
final endX = 2.5;
|
||||
final x = startX + (endX - startX) * t;
|
||||
return ShaderMask(
|
||||
blendMode: BlendMode.srcOver,
|
||||
shaderCallback: (Rect bounds) {
|
||||
return LinearGradient(
|
||||
begin: Alignment(x, 0),
|
||||
end: Alignment(x + 0.5, 0),
|
||||
colors: [
|
||||
Colors.white.withOpacity(0),
|
||||
Colors.white.withOpacity(0.12),
|
||||
Colors.white.withOpacity(0),
|
||||
],
|
||||
stops: const [0.0, 0.5, 1.0],
|
||||
).createShader(bounds);
|
||||
},
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
border: Border.all(
|
||||
color: Colors.white.withOpacity(0.15),
|
||||
width: 1,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _GlassButton extends StatelessWidget {
|
||||
final String label;
|
||||
final IconData icon;
|
||||
final VoidCallback onTap;
|
||||
|
||||
const _GlassButton({
|
||||
required this.label,
|
||||
required this.icon,
|
||||
required this.onTap,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Material(
|
||||
color: Colors.white.withOpacity(0.15),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
child: InkWell(
|
||||
onTap: onTap,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(vertical: 12, horizontal: 16),
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
border: Border.all(
|
||||
color: Colors.white.withOpacity(0.25),
|
||||
width: 1,
|
||||
),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Text(
|
||||
label,
|
||||
style: const TextStyle(
|
||||
color: Colors.white,
|
||||
fontWeight: FontWeight.w700,
|
||||
fontSize: 14,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 6),
|
||||
Icon(icon, color: Colors.white, size: 18),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -5,10 +5,14 @@
|
||||
import FlutterMacOS
|
||||
import Foundation
|
||||
|
||||
import google_sign_in_ios
|
||||
import in_app_purchase_storekit
|
||||
import local_auth_darwin
|
||||
import shared_preferences_foundation
|
||||
|
||||
func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
|
||||
FLTGoogleSignInPlugin.register(with: registry.registrar(forPlugin: "FLTGoogleSignInPlugin"))
|
||||
InAppPurchasePlugin.register(with: registry.registrar(forPlugin: "InAppPurchasePlugin"))
|
||||
LocalAuthPlugin.register(with: registry.registrar(forPlugin: "LocalAuthPlugin"))
|
||||
SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin"))
|
||||
}
|
||||
|
||||
+112
@@ -1,6 +1,14 @@
|
||||
# Generated by pub
|
||||
# See https://dart.dev/tools/pub/glossary#lockfile
|
||||
packages:
|
||||
_discoveryapis_commons:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: _discoveryapis_commons
|
||||
sha256: "113c4100b90a5b70a983541782431b82168b3cae166ab130649c36eb3559d498"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.0.7"
|
||||
_fe_analyzer_shared:
|
||||
dependency: transitive
|
||||
description:
|
||||
@@ -241,6 +249,14 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.0.8"
|
||||
extension_google_sign_in_as_googleapis_auth:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: extension_google_sign_in_as_googleapis_auth
|
||||
sha256: "0dcb17e399f62e897ac78f0a402a3cb6ab9313ced8b2bf131f684d317e05c9ab"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.0.13"
|
||||
fake_async:
|
||||
dependency: transitive
|
||||
description:
|
||||
@@ -376,6 +392,70 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "8.1.0"
|
||||
google_identity_services_web:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: google_identity_services_web
|
||||
sha256: "5d187c46dc59e02646e10fe82665fc3884a9b71bc1c90c2b8b749316d33ee454"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.3.3+1"
|
||||
google_sign_in:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: google_sign_in
|
||||
sha256: d0a2c3bcb06e607bb11e4daca48bd4b6120f0bbc4015ccebbe757d24ea60ed2a
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "6.3.0"
|
||||
google_sign_in_android:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: google_sign_in_android
|
||||
sha256: d5e23c56a4b84b6427552f1cf3f98f716db3b1d1a647f16b96dbb5b93afa2805
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "6.2.1"
|
||||
google_sign_in_ios:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: google_sign_in_ios
|
||||
sha256: "102005f498ce18442e7158f6791033bbc15ad2dcc0afa4cf4752e2722a516c96"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "5.9.0"
|
||||
google_sign_in_platform_interface:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: google_sign_in_platform_interface
|
||||
sha256: "5f6f79cf139c197261adb6ac024577518ae48fdff8e53205c5373b5f6430a8aa"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.5.0"
|
||||
google_sign_in_web:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: google_sign_in_web
|
||||
sha256: "460547beb4962b7623ac0fb8122d6b8268c951cf0b646dd150d60498430e4ded"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.12.4+4"
|
||||
googleapis:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: googleapis
|
||||
sha256: "864f222aed3f2ff00b816c675edf00a39e2aaf373d728d8abec30b37bee1a81c"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "13.2.0"
|
||||
googleapis_auth:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: googleapis_auth
|
||||
sha256: befd71383a955535060acde8792e7efc11d2fccd03dd1d3ec434e85b68775938
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.6.0"
|
||||
graphs:
|
||||
dependency: transitive
|
||||
description:
|
||||
@@ -432,6 +512,38 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "4.9.1"
|
||||
in_app_purchase:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: in_app_purchase
|
||||
sha256: "0e9510b80b0074e89ab0a8e0fc901439b779dc9ae575ab8d419253c6e1627716"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "3.3.0"
|
||||
in_app_purchase_android:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: in_app_purchase_android
|
||||
sha256: eb8f551039481d1b265f12fa54f5ab5dd4f13ec5444a468b85a3793517a37fda
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.5.1"
|
||||
in_app_purchase_platform_interface:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: in_app_purchase_platform_interface
|
||||
sha256: "0b0076cac8ce4fa7048f01e76af8b123aeb6a7c4e0dea2a5206d6664454f3e36"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.4.1"
|
||||
in_app_purchase_storekit:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: in_app_purchase_storekit
|
||||
sha256: "5f9d59c86c15f56429a4fdf09097c99d5b412510e1fcf80cf874fc9638fab369"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.4.10"
|
||||
intl:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
|
||||
@@ -25,6 +25,11 @@ dependencies:
|
||||
drift: ^2.14.1
|
||||
sqlite3_flutter_libs: ^0.6.0+eol
|
||||
path: ^1.8.3
|
||||
google_sign_in: ^6.2.1
|
||||
in_app_purchase: ^3.2.0
|
||||
googleapis: ^13.2.0
|
||||
googleapis_auth: ^1.6.0
|
||||
extension_google_sign_in_as_googleapis_auth: ^2.0.12
|
||||
|
||||
flutter_launcher_icons:
|
||||
android: true
|
||||
|
||||
Reference in New Issue
Block a user