mirror of
https://github.com/koloideal/Casha.git
synced 2026-08-08 17:51:14 +03:00
first google play release for internal testing
This commit is contained in:
Binary file not shown.
|
Before Width: | Height: | Size: 351 KiB |
@@ -332,6 +332,19 @@ class AppStrings {
|
|||||||
_ru ? 'Предыдущие покупки не найдены' : 'No previous purchases found';
|
_ru ? 'Предыдущие покупки не найдены' : 'No previous purchases found';
|
||||||
String get proTapToClose =>
|
String get proTapToClose =>
|
||||||
_ru ? 'Нажмите чтобы закрыть' : 'Tap anywhere to close';
|
_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 backupTitle => _ru ? 'Резервная копия' : 'Backup';
|
||||||
String get backupCreate => _ru ? 'Создать резервную копию' : 'Create Backup';
|
String get backupCreate => _ru ? 'Создать резервную копию' : 'Create Backup';
|
||||||
String get backupRestore => _ru ? 'Восстановить из копии' : 'Restore Backup';
|
String get backupRestore => _ru ? 'Восстановить из копии' : 'Restore Backup';
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||||
|
import '../../shared/models/account.dart';
|
||||||
import '../../shared/models/transaction.dart';
|
import '../../shared/models/transaction.dart';
|
||||||
import '../dashboard/provider.dart';
|
import '../dashboard/provider.dart';
|
||||||
import '../settings/provider.dart';
|
import '../settings/provider.dart';
|
||||||
@@ -35,81 +36,88 @@ class _StatsTimeFilterNotifier extends Notifier<StatsTimeFilter> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
String _statsTargetCurrency(Ref ref) {
|
String _resolveTargetCurrency(
|
||||||
final index = ref.watch(activeAccountIndexProvider);
|
int activeIndex,
|
||||||
final accountsAsync = ref.watch(accountsProvider);
|
List<Account> accounts,
|
||||||
final globalCurrency = ref.watch(currencyProvider).code;
|
String globalCurrency,
|
||||||
|
) {
|
||||||
if (index > 0) {
|
if (activeIndex > 0 && activeIndex <= accounts.length) {
|
||||||
final accounts = accountsAsync.value ?? [];
|
return accounts[activeIndex - 1].currency;
|
||||||
if (index <= accounts.length) {
|
|
||||||
return accounts[index - 1].currency;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return globalCurrency;
|
return globalCurrency;
|
||||||
}
|
}
|
||||||
|
|
||||||
CurrencyInfo _statsCurrencyInfo(Ref ref) {
|
List<Transaction> _filterScopedTransactions(
|
||||||
final code = _statsTargetCurrency(ref);
|
List<Transaction> txs,
|
||||||
return CurrencyInfo(currencyMap[code]?.symbol ?? '\$', code);
|
StatsTimeFilter timeFilter,
|
||||||
}
|
) {
|
||||||
|
|
||||||
List<Transaction> _statsScopedTransactions(Ref ref) {
|
|
||||||
final txs = ref.watch(accountFilteredTransactionsProvider);
|
|
||||||
final timeFilter = ref.watch(statsTimeFilterProvider);
|
|
||||||
var filtered = txs.where((t) => t.category != 'Transfer');
|
var filtered = txs.where((t) => t.category != 'Transfer');
|
||||||
|
|
||||||
if (timeFilter == StatsTimeFilter.month) {
|
if (timeFilter == StatsTimeFilter.month) {
|
||||||
final now = DateTime.now();
|
final now = DateTime.now();
|
||||||
filtered = filtered.where(
|
filtered = filtered.where(
|
||||||
(t) => t.date.year == now.year && t.date.month == now.month,
|
(t) => t.date.year == now.year && t.date.month == now.month,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return filtered.toList();
|
return filtered.toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
double _convertAmount(Ref ref, Transaction t) {
|
|
||||||
final exchange = ref.watch(exchangeRateServiceProvider);
|
|
||||||
return exchange.convert(
|
|
||||||
t.amount,
|
|
||||||
t.currencyCode,
|
|
||||||
_statsTargetCurrency(ref),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
final statsCurrencyProvider = Provider<CurrencyInfo>((ref) {
|
final statsCurrencyProvider = Provider<CurrencyInfo>((ref) {
|
||||||
return _statsCurrencyInfo(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 statsScopedTransactionsProvider = Provider<List<Transaction>>((ref) {
|
||||||
return _statsScopedTransactions(ref);
|
final txs = ref.watch(accountFilteredTransactionsProvider);
|
||||||
});
|
final timeFilter = ref.watch(statsTimeFilterProvider);
|
||||||
|
return _filterScopedTransactions(txs, timeFilter);
|
||||||
|
});
|
||||||
|
|
||||||
final statsIncomeTotalProvider = Provider<double>((ref) {
|
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
|
return ref
|
||||||
.watch(statsScopedTransactionsProvider)
|
.watch(statsScopedTransactionsProvider)
|
||||||
.where((t) => t.type == TransactionType.income)
|
.where((t) => t.type == TransactionType.income)
|
||||||
.fold(0.0, (sum, t) => sum + _convertAmount(ref, t));
|
.fold(0.0, (sum, t) => sum + exchange.convert(t.amount, t.currencyCode, target));
|
||||||
});
|
});
|
||||||
|
|
||||||
final statsExpenseTotalProvider = Provider<double>((ref) {
|
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
|
return ref
|
||||||
.watch(statsScopedTransactionsProvider)
|
.watch(statsScopedTransactionsProvider)
|
||||||
.where((t) => t.type == TransactionType.expense)
|
.where((t) => t.type == TransactionType.expense)
|
||||||
.fold(0.0, (sum, t) => sum + _convertAmount(ref, t));
|
.fold(0.0, (sum, t) => sum + exchange.convert(t.amount, t.currencyCode, target));
|
||||||
});
|
});
|
||||||
|
|
||||||
final statsSummaryProvider = Provider<StatsSummary>((ref) {
|
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);
|
final transactions = ref.watch(statsScopedTransactionsProvider);
|
||||||
|
|
||||||
var income = 0.0;
|
var income = 0.0;
|
||||||
var expense = 0.0;
|
var expense = 0.0;
|
||||||
var incomeCount = 0;
|
var incomeCount = 0;
|
||||||
var expenseCount = 0;
|
var expenseCount = 0;
|
||||||
|
|
||||||
for (final transaction in transactions) {
|
for (final transaction in transactions) {
|
||||||
final amount = _convertAmount(ref, transaction);
|
final amount = exchange.convert(transaction.amount, transaction.currencyCode, target);
|
||||||
if (transaction.type == TransactionType.income) {
|
if (transaction.type == TransactionType.income) {
|
||||||
income += amount;
|
income += amount;
|
||||||
incomeCount++;
|
incomeCount++;
|
||||||
@@ -128,22 +136,34 @@ final statsExpenseTotalProvider = Provider<double>((ref) {
|
|||||||
averageIncome: incomeCount == 0 ? 0 : income / incomeCount,
|
averageIncome: incomeCount == 0 ? 0 : income / incomeCount,
|
||||||
averageExpense: expenseCount == 0 ? 0 : expense / expenseCount,
|
averageExpense: expenseCount == 0 ? 0 : expense / expenseCount,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
final categoryExpenseProvider = Provider<Map<String, double>>((ref) {
|
final categoryExpenseProvider = Provider<Map<String, 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);
|
||||||
final map = <String, double>{};
|
final map = <String, double>{};
|
||||||
for (final t in ref.watch(statsScopedTransactionsProvider)) {
|
for (final t in ref.watch(statsScopedTransactionsProvider)) {
|
||||||
if (t.type != TransactionType.expense) continue;
|
if (t.type != TransactionType.expense) continue;
|
||||||
map[t.category] = (map[t.category] ?? 0) + _convertAmount(ref, t);
|
map[t.category] = (map[t.category] ?? 0) + exchange.convert(t.amount, t.currencyCode, target);
|
||||||
}
|
}
|
||||||
return map;
|
return map;
|
||||||
});
|
});
|
||||||
|
|
||||||
final categoryIncomeProvider = Provider<Map<String, double>>((ref) {
|
final categoryIncomeProvider = Provider<Map<String, 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);
|
||||||
final map = <String, double>{};
|
final map = <String, double>{};
|
||||||
for (final t in ref.watch(statsScopedTransactionsProvider)) {
|
for (final t in ref.watch(statsScopedTransactionsProvider)) {
|
||||||
if (t.type != TransactionType.income) continue;
|
if (t.type != TransactionType.income) continue;
|
||||||
map[t.category] = (map[t.category] ?? 0) + _convertAmount(ref, t);
|
map[t.category] = (map[t.category] ?? 0) + exchange.convert(t.amount, t.currencyCode, target);
|
||||||
}
|
}
|
||||||
return map;
|
return map;
|
||||||
});
|
});
|
||||||
@@ -151,7 +171,11 @@ final categoryIncomeProvider = Provider<Map<String, double>>((ref) {
|
|||||||
final monthlyBreakdownProvider = Provider<List<MonthlyData>>((ref) {
|
final monthlyBreakdownProvider = Provider<List<MonthlyData>>((ref) {
|
||||||
final txs = ref.watch(accountFilteredTransactionsProvider);
|
final txs = ref.watch(accountFilteredTransactionsProvider);
|
||||||
final exchange = ref.watch(exchangeRateServiceProvider);
|
final exchange = ref.watch(exchangeRateServiceProvider);
|
||||||
final target = _statsTargetCurrency(ref);
|
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 now = DateTime.now();
|
||||||
final months = <MonthlyData>[];
|
final months = <MonthlyData>[];
|
||||||
|
|
||||||
@@ -177,7 +201,11 @@ final monthlyBreakdownProvider = Provider<List<MonthlyData>>((ref) {
|
|||||||
final monthlyIncomeBreakdownProvider = Provider<List<MonthlyData>>((ref) {
|
final monthlyIncomeBreakdownProvider = Provider<List<MonthlyData>>((ref) {
|
||||||
final txs = ref.watch(accountFilteredTransactionsProvider);
|
final txs = ref.watch(accountFilteredTransactionsProvider);
|
||||||
final exchange = ref.watch(exchangeRateServiceProvider);
|
final exchange = ref.watch(exchangeRateServiceProvider);
|
||||||
final target = _statsTargetCurrency(ref);
|
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 now = DateTime.now();
|
||||||
final months = <MonthlyData>[];
|
final months = <MonthlyData>[];
|
||||||
|
|
||||||
|
|||||||
@@ -63,9 +63,7 @@ class _AccountEditorOverlayState extends State<AccountEditorOverlay> {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
dash.setState(() {
|
dash.tempAccountName = _nameController.text;
|
||||||
dash.tempAccountName = _nameController.text;
|
|
||||||
});
|
|
||||||
dash.overlayEntry?.markNeedsBuild();
|
dash.overlayEntry?.markNeedsBuild();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -411,9 +409,7 @@ class _AccountEditorOverlayState extends State<AccountEditorOverlay> {
|
|||||||
onTap: () {
|
onTap: () {
|
||||||
setState(() {
|
setState(() {
|
||||||
_selectedCurrency = entry.$1;
|
_selectedCurrency = entry.$1;
|
||||||
dash.setState(() {
|
dash.tempAccountCurrency = entry.$1;
|
||||||
dash.tempAccountCurrency = entry.$1;
|
|
||||||
});
|
|
||||||
dash.overlayEntry?.markNeedsBuild();
|
dash.overlayEntry?.markNeedsBuild();
|
||||||
_showCurrencyDropdown = false;
|
_showCurrencyDropdown = false;
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -57,16 +57,14 @@ class AccountColorPanel extends StatelessWidget {
|
|||||||
);
|
);
|
||||||
|
|
||||||
void onHSVChanged(HSVColor hsv) {
|
void onHSVChanged(HSVColor hsv) {
|
||||||
|
if (dashboardState.editingPrimary) {
|
||||||
|
dashboardState.tempPrimaryHSV = hsv;
|
||||||
|
dashboardState.tempPrimary = hsv.toColor();
|
||||||
|
} else {
|
||||||
|
dashboardState.tempSecondaryHSV = hsv;
|
||||||
|
dashboardState.tempSecondary = hsv.toColor();
|
||||||
|
}
|
||||||
setPanelState(() {});
|
setPanelState(() {});
|
||||||
dashboardState.setState(() {
|
|
||||||
if (dashboardState.editingPrimary) {
|
|
||||||
dashboardState.tempPrimaryHSV = hsv;
|
|
||||||
dashboardState.tempPrimary = hsv.toColor();
|
|
||||||
} else {
|
|
||||||
dashboardState.tempSecondaryHSV = hsv;
|
|
||||||
dashboardState.tempSecondary = hsv.toColor();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
dashboardState.overlayEntry?.markNeedsBuild();
|
dashboardState.overlayEntry?.markNeedsBuild();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -106,18 +104,16 @@ class AccountColorPanel extends StatelessWidget {
|
|||||||
: dashboardState.tempPrimary,
|
: dashboardState.tempPrimary,
|
||||||
isDimmed: isSolid,
|
isDimmed: isSolid,
|
||||||
onTap: () {
|
onTap: () {
|
||||||
dashboardState.setState(() {
|
if (isSolid)
|
||||||
if (isSolid)
|
if (Theme.of(dashboardContext).brightness ==
|
||||||
if (Theme.of(dashboardContext).brightness ==
|
Brightness.dark) {
|
||||||
Brightness.dark) {
|
dashboardState.tempDarkGradientType =
|
||||||
dashboardState.tempDarkGradientType =
|
GradientType.linear;
|
||||||
CardColorService.defaultGradientDark;
|
} else {
|
||||||
} else {
|
dashboardState.tempLightGradientType =
|
||||||
dashboardState.tempLightGradientType =
|
GradientType.linear;
|
||||||
CardColorService.defaultGradientLight;
|
}
|
||||||
}
|
dashboardState.editingPrimary = true;
|
||||||
dashboardState.editingPrimary = true;
|
|
||||||
});
|
|
||||||
setPanelState(() {});
|
setPanelState(() {});
|
||||||
dashboardState.overlayEntry?.markNeedsBuild();
|
dashboardState.overlayEntry?.markNeedsBuild();
|
||||||
},
|
},
|
||||||
@@ -132,18 +128,16 @@ class AccountColorPanel extends StatelessWidget {
|
|||||||
color: dashboardState.tempSecondary,
|
color: dashboardState.tempSecondary,
|
||||||
isDimmed: isSolid,
|
isDimmed: isSolid,
|
||||||
onTap: () {
|
onTap: () {
|
||||||
dashboardState.setState(() {
|
if (isSolid)
|
||||||
if (isSolid)
|
if (Theme.of(dashboardContext).brightness ==
|
||||||
if (Theme.of(dashboardContext).brightness ==
|
Brightness.dark) {
|
||||||
Brightness.dark) {
|
dashboardState.tempDarkGradientType =
|
||||||
dashboardState.tempDarkGradientType =
|
GradientType.linear;
|
||||||
CardColorService.defaultGradientDark;
|
} else {
|
||||||
} else {
|
dashboardState.tempLightGradientType =
|
||||||
dashboardState.tempLightGradientType =
|
GradientType.linear;
|
||||||
CardColorService.defaultGradientLight;
|
}
|
||||||
}
|
dashboardState.editingPrimary = false;
|
||||||
dashboardState.editingPrimary = false;
|
|
||||||
});
|
|
||||||
setPanelState(() {});
|
setPanelState(() {});
|
||||||
dashboardState.overlayEntry?.markNeedsBuild();
|
dashboardState.overlayEntry?.markNeedsBuild();
|
||||||
},
|
},
|
||||||
@@ -164,17 +158,15 @@ class AccountColorPanel extends StatelessWidget {
|
|||||||
onTap: isSolid
|
onTap: isSolid
|
||||||
? null
|
? null
|
||||||
: () {
|
: () {
|
||||||
dashboardState.setState(() {
|
if (Theme.of(dashboardContext).brightness ==
|
||||||
if (Theme.of(dashboardContext).brightness ==
|
Brightness.dark) {
|
||||||
Brightness.dark) {
|
dashboardState.tempDarkGradientType =
|
||||||
dashboardState.tempDarkGradientType =
|
GradientType.solid;
|
||||||
GradientType.solid;
|
} else {
|
||||||
} else {
|
dashboardState.tempLightGradientType =
|
||||||
dashboardState.tempLightGradientType =
|
GradientType.solid;
|
||||||
GradientType.solid;
|
}
|
||||||
}
|
dashboardState.editingPrimary = true;
|
||||||
dashboardState.editingPrimary = true;
|
|
||||||
});
|
|
||||||
setPanelState(() {});
|
setPanelState(() {});
|
||||||
dashboardState.overlayEntry?.markNeedsBuild();
|
dashboardState.overlayEntry?.markNeedsBuild();
|
||||||
},
|
},
|
||||||
@@ -292,10 +284,7 @@ class AccountColorPanel extends StatelessWidget {
|
|||||||
children: [
|
children: [
|
||||||
GestureDetector(
|
GestureDetector(
|
||||||
onTap: () {
|
onTap: () {
|
||||||
dashboardState.setState(
|
dashboardState.editingPrimary = true;
|
||||||
() => dashboardState.editingPrimary =
|
|
||||||
true,
|
|
||||||
);
|
|
||||||
setPanelState(() {});
|
setPanelState(() {});
|
||||||
dashboardState.overlayEntry
|
dashboardState.overlayEntry
|
||||||
?.markNeedsBuild();
|
?.markNeedsBuild();
|
||||||
@@ -350,11 +339,7 @@ class AccountColorPanel extends StatelessWidget {
|
|||||||
if (!isSolid)
|
if (!isSolid)
|
||||||
GestureDetector(
|
GestureDetector(
|
||||||
onTap: () {
|
onTap: () {
|
||||||
dashboardState.setState(
|
dashboardState.editingPrimary = false;
|
||||||
() =>
|
|
||||||
dashboardState.editingPrimary =
|
|
||||||
false,
|
|
||||||
);
|
|
||||||
setPanelState(() {});
|
setPanelState(() {});
|
||||||
dashboardState.overlayEntry
|
dashboardState.overlayEntry
|
||||||
?.markNeedsBuild();
|
?.markNeedsBuild();
|
||||||
@@ -420,13 +405,8 @@ class AccountColorPanel extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
SizedBox(height: layout.controlSpacing),
|
SizedBox(height: layout.controlSpacing),
|
||||||
IgnorePointer(
|
Row(
|
||||||
ignoring: isSolid,
|
children: GradientType.values
|
||||||
child: AnimatedOpacity(
|
|
||||||
duration: const Duration(milliseconds: 200),
|
|
||||||
opacity: isSolid ? 0.3 : 1.0,
|
|
||||||
child: Row(
|
|
||||||
children: GradientType.values
|
|
||||||
.where((t) => t != GradientType.solid)
|
.where((t) => t != GradientType.solid)
|
||||||
.map((type) {
|
.map((type) {
|
||||||
final isSelected = activeGradientType == type;
|
final isSelected = activeGradientType == type;
|
||||||
@@ -452,19 +432,15 @@ class AccountColorPanel extends StatelessWidget {
|
|||||||
padding: const EdgeInsets.only(right: 6),
|
padding: const EdgeInsets.only(right: 6),
|
||||||
child: GestureDetector(
|
child: GestureDetector(
|
||||||
onTap: () {
|
onTap: () {
|
||||||
dashboardState.setState(
|
if (Theme.of(dashboardContext)
|
||||||
() {
|
.brightness ==
|
||||||
if (Theme.of(dashboardContext)
|
Brightness.dark) {
|
||||||
.brightness ==
|
dashboardState.tempDarkGradientType =
|
||||||
Brightness.dark) {
|
type;
|
||||||
dashboardState.tempDarkGradientType =
|
} else {
|
||||||
type;
|
dashboardState.tempLightGradientType =
|
||||||
} else {
|
type;
|
||||||
dashboardState.tempLightGradientType =
|
}
|
||||||
type;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
);
|
|
||||||
setPanelState(() {});
|
setPanelState(() {});
|
||||||
dashboardState.overlayEntry
|
dashboardState.overlayEntry
|
||||||
?.markNeedsBuild();
|
?.markNeedsBuild();
|
||||||
@@ -526,10 +502,8 @@ class AccountColorPanel extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
})
|
})
|
||||||
.toList(),
|
.toList(),
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
SizedBox(height: layout.controlSpacing),
|
SizedBox(height: layout.controlSpacing),
|
||||||
Row(
|
Row(
|
||||||
@@ -546,19 +520,17 @@ class AccountColorPanel extends StatelessWidget {
|
|||||||
final defS = isDarkTheme
|
final defS = isDarkTheme
|
||||||
? CardColorService.defaultSecondary
|
? CardColorService.defaultSecondary
|
||||||
: CardColorService.defaultSecondaryLight;
|
: CardColorService.defaultSecondaryLight;
|
||||||
dashboardState.setState(() {
|
dashboardState.tempPrimary = defP;
|
||||||
dashboardState.tempPrimary = defP;
|
dashboardState.tempSecondary = defS;
|
||||||
dashboardState.tempSecondary = defS;
|
dashboardState.tempPrimaryHSV = HSVColor.fromColor(
|
||||||
dashboardState.tempPrimaryHSV = HSVColor.fromColor(
|
defP,
|
||||||
defP,
|
);
|
||||||
);
|
dashboardState.tempSecondaryHSV =
|
||||||
dashboardState.tempSecondaryHSV =
|
HSVColor.fromColor(defS);
|
||||||
HSVColor.fromColor(defS);
|
|
||||||
dashboardState.tempLightGradientType =
|
dashboardState.tempLightGradientType =
|
||||||
CardColorService.defaultGradientLight;
|
CardColorService.defaultGradientLight;
|
||||||
dashboardState.tempDarkGradientType =
|
dashboardState.tempDarkGradientType =
|
||||||
CardColorService.defaultGradientDark;
|
CardColorService.defaultGradientDark;
|
||||||
});
|
|
||||||
setPanelState(() {});
|
setPanelState(() {});
|
||||||
dashboardState.overlayEntry?.markNeedsBuild();
|
dashboardState.overlayEntry?.markNeedsBuild();
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -186,16 +186,14 @@ class _FullScreenBlurOverlayState extends State<FullScreenBlurOverlay> {
|
|||||||
);
|
);
|
||||||
|
|
||||||
void onHSVChanged(HSVColor hsv) {
|
void onHSVChanged(HSVColor hsv) {
|
||||||
|
if (dash.editingPrimary) {
|
||||||
|
dash.tempPrimaryHSV = hsv;
|
||||||
|
dash.tempPrimary = hsv.toColor();
|
||||||
|
} else {
|
||||||
|
dash.tempSecondaryHSV = hsv;
|
||||||
|
dash.tempSecondary = hsv.toColor();
|
||||||
|
}
|
||||||
setPanelState(() {});
|
setPanelState(() {});
|
||||||
dash.setState(() {
|
|
||||||
if (dash.editingPrimary) {
|
|
||||||
dash.tempPrimaryHSV = hsv;
|
|
||||||
dash.tempPrimary = hsv.toColor();
|
|
||||||
} else {
|
|
||||||
dash.tempSecondaryHSV = hsv;
|
|
||||||
dash.tempSecondary = hsv.toColor();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
dash.overlayEntry?.markNeedsBuild();
|
dash.overlayEntry?.markNeedsBuild();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -233,19 +231,17 @@ class _FullScreenBlurOverlayState extends State<FullScreenBlurOverlay> {
|
|||||||
: dash.tempPrimary,
|
: dash.tempPrimary,
|
||||||
isDimmed: isSolid,
|
isDimmed: isSolid,
|
||||||
onTap: () {
|
onTap: () {
|
||||||
dash.setState(() {
|
if (isSolid) {
|
||||||
if (isSolid) {
|
if (Theme.of(widget.context).brightness ==
|
||||||
if (Theme.of(widget.context).brightness ==
|
Brightness.dark) {
|
||||||
Brightness.dark) {
|
dash.tempDarkGradientType =
|
||||||
dash.tempDarkGradientType =
|
GradientType.linear;
|
||||||
CardColorService.defaultGradientDark;
|
} else {
|
||||||
} else {
|
dash.tempLightGradientType =
|
||||||
dash.tempLightGradientType =
|
GradientType.linear;
|
||||||
CardColorService.defaultGradientLight;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
dash.editingPrimary = true;
|
}
|
||||||
});
|
dash.editingPrimary = true;
|
||||||
setPanelState(() {});
|
setPanelState(() {});
|
||||||
dash.overlayEntry?.markNeedsBuild();
|
dash.overlayEntry?.markNeedsBuild();
|
||||||
},
|
},
|
||||||
@@ -259,19 +255,17 @@ class _FullScreenBlurOverlayState extends State<FullScreenBlurOverlay> {
|
|||||||
color: dash.tempSecondary,
|
color: dash.tempSecondary,
|
||||||
isDimmed: isSolid,
|
isDimmed: isSolid,
|
||||||
onTap: () {
|
onTap: () {
|
||||||
dash.setState(() {
|
if (isSolid) {
|
||||||
if (isSolid) {
|
if (Theme.of(widget.context).brightness ==
|
||||||
if (Theme.of(widget.context).brightness ==
|
Brightness.dark) {
|
||||||
Brightness.dark) {
|
dash.tempDarkGradientType =
|
||||||
dash.tempDarkGradientType =
|
GradientType.linear;
|
||||||
CardColorService.defaultGradientDark;
|
} else {
|
||||||
} else {
|
dash.tempLightGradientType =
|
||||||
dash.tempLightGradientType =
|
GradientType.linear;
|
||||||
CardColorService.defaultGradientLight;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
dash.editingPrimary = false;
|
}
|
||||||
});
|
dash.editingPrimary = false;
|
||||||
setPanelState(() {});
|
setPanelState(() {});
|
||||||
dash.overlayEntry?.markNeedsBuild();
|
dash.overlayEntry?.markNeedsBuild();
|
||||||
},
|
},
|
||||||
@@ -291,17 +285,15 @@ class _FullScreenBlurOverlayState extends State<FullScreenBlurOverlay> {
|
|||||||
onTap: isSolid
|
onTap: isSolid
|
||||||
? null
|
? null
|
||||||
: () {
|
: () {
|
||||||
dash.setState(() {
|
if (Theme.of(widget.context).brightness ==
|
||||||
if (Theme.of(widget.context).brightness ==
|
Brightness.dark) {
|
||||||
Brightness.dark) {
|
dash.tempDarkGradientType =
|
||||||
dash.tempDarkGradientType =
|
GradientType.solid;
|
||||||
GradientType.solid;
|
} else {
|
||||||
} else {
|
dash.tempLightGradientType =
|
||||||
dash.tempLightGradientType =
|
GradientType.solid;
|
||||||
GradientType.solid;
|
}
|
||||||
}
|
dash.editingPrimary = true;
|
||||||
dash.editingPrimary = true;
|
|
||||||
});
|
|
||||||
setPanelState(() {});
|
setPanelState(() {});
|
||||||
dash.overlayEntry?.markNeedsBuild();
|
dash.overlayEntry?.markNeedsBuild();
|
||||||
},
|
},
|
||||||
@@ -418,9 +410,7 @@ class _FullScreenBlurOverlayState extends State<FullScreenBlurOverlay> {
|
|||||||
children: [
|
children: [
|
||||||
GestureDetector(
|
GestureDetector(
|
||||||
onTap: () {
|
onTap: () {
|
||||||
dash.setState(
|
dash.editingPrimary = true;
|
||||||
() => dash.editingPrimary = true,
|
|
||||||
);
|
|
||||||
setPanelState(() {});
|
setPanelState(() {});
|
||||||
dash.overlayEntry?.markNeedsBuild();
|
dash.overlayEntry?.markNeedsBuild();
|
||||||
},
|
},
|
||||||
@@ -471,9 +461,7 @@ class _FullScreenBlurOverlayState extends State<FullScreenBlurOverlay> {
|
|||||||
if (!isSolid)
|
if (!isSolid)
|
||||||
GestureDetector(
|
GestureDetector(
|
||||||
onTap: () {
|
onTap: () {
|
||||||
dash.setState(
|
dash.editingPrimary = false;
|
||||||
() => dash.editingPrimary = false,
|
|
||||||
);
|
|
||||||
setPanelState(() {});
|
setPanelState(() {});
|
||||||
dash.overlayEntry?.markNeedsBuild();
|
dash.overlayEntry?.markNeedsBuild();
|
||||||
},
|
},
|
||||||
@@ -532,13 +520,8 @@ class _FullScreenBlurOverlayState extends State<FullScreenBlurOverlay> {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
SizedBox(height: layout.controlSpacing),
|
SizedBox(height: layout.controlSpacing),
|
||||||
IgnorePointer(
|
Row(
|
||||||
ignoring: isSolid,
|
children: GradientType.values
|
||||||
child: AnimatedOpacity(
|
|
||||||
duration: const Duration(milliseconds: 200),
|
|
||||||
opacity: isSolid ? 0.3 : 1.0,
|
|
||||||
child: Row(
|
|
||||||
children: GradientType.values
|
|
||||||
.where((t) => t != GradientType.solid)
|
.where((t) => t != GradientType.solid)
|
||||||
.map((type) {
|
.map((type) {
|
||||||
final isSelected = activeGradientType == type;
|
final isSelected = activeGradientType == type;
|
||||||
@@ -564,14 +547,12 @@ class _FullScreenBlurOverlayState extends State<FullScreenBlurOverlay> {
|
|||||||
padding: const EdgeInsets.only(right: 6),
|
padding: const EdgeInsets.only(right: 6),
|
||||||
child: GestureDetector(
|
child: GestureDetector(
|
||||||
onTap: () {
|
onTap: () {
|
||||||
dash.setState(() {
|
if (Theme.of(widget.context).brightness ==
|
||||||
if (Theme.of(widget.context).brightness ==
|
Brightness.dark) {
|
||||||
Brightness.dark) {
|
dash.tempDarkGradientType = type;
|
||||||
dash.tempDarkGradientType = type;
|
} else {
|
||||||
} else {
|
dash.tempLightGradientType = type;
|
||||||
dash.tempLightGradientType = type;
|
}
|
||||||
}
|
|
||||||
});
|
|
||||||
setPanelState(() {});
|
setPanelState(() {});
|
||||||
dash.overlayEntry?.markNeedsBuild();
|
dash.overlayEntry?.markNeedsBuild();
|
||||||
},
|
},
|
||||||
@@ -632,10 +613,8 @@ class _FullScreenBlurOverlayState extends State<FullScreenBlurOverlay> {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
})
|
})
|
||||||
.toList(),
|
.toList(),
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
SizedBox(height: layout.controlSpacing),
|
SizedBox(height: layout.controlSpacing),
|
||||||
Row(
|
Row(
|
||||||
@@ -652,16 +631,14 @@ class _FullScreenBlurOverlayState extends State<FullScreenBlurOverlay> {
|
|||||||
final defS = isDarkTheme
|
final defS = isDarkTheme
|
||||||
? CardColorService.defaultSecondary
|
? CardColorService.defaultSecondary
|
||||||
: CardColorService.defaultSecondaryLight;
|
: CardColorService.defaultSecondaryLight;
|
||||||
dash.setState(() {
|
dash.tempPrimary = defP;
|
||||||
dash.tempPrimary = defP;
|
dash.tempSecondary = defS;
|
||||||
dash.tempSecondary = defS;
|
dash.tempPrimaryHSV = HSVColor.fromColor(defP);
|
||||||
dash.tempPrimaryHSV = HSVColor.fromColor(defP);
|
dash.tempSecondaryHSV = HSVColor.fromColor(defS);
|
||||||
dash.tempSecondaryHSV = HSVColor.fromColor(defS);
|
dash.tempLightGradientType =
|
||||||
dash.tempLightGradientType =
|
CardColorService.defaultGradientLight;
|
||||||
CardColorService.defaultGradientLight;
|
dash.tempDarkGradientType =
|
||||||
dash.tempDarkGradientType =
|
CardColorService.defaultGradientDark;
|
||||||
CardColorService.defaultGradientDark;
|
|
||||||
});
|
|
||||||
setPanelState(() {});
|
setPanelState(() {});
|
||||||
dash.overlayEntry?.markNeedsBuild();
|
dash.overlayEntry?.markNeedsBuild();
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -2,9 +2,7 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||||
import '../../../core/constants.dart';
|
import '../../../core/constants.dart';
|
||||||
import '../../../core/l10n/locale_provider.dart';
|
import '../../../core/l10n/locale_provider.dart';
|
||||||
import '../../../core/services/haptic_service.dart';
|
|
||||||
import '../../../shared/providers/current_user_provider.dart';
|
import '../../../shared/providers/current_user_provider.dart';
|
||||||
import '../../../shared/models/user_model.dart';
|
|
||||||
|
|
||||||
class PremiumSection extends ConsumerWidget {
|
class PremiumSection extends ConsumerWidget {
|
||||||
const PremiumSection({super.key});
|
const PremiumSection({super.key});
|
||||||
@@ -66,16 +64,6 @@ class PremiumSection extends ConsumerWidget {
|
|||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
Switch(
|
|
||||||
value: user.isVip,
|
|
||||||
onChanged: (value) async {
|
|
||||||
HapticService.light();
|
|
||||||
await ref.read(currentUserProvider.notifier).setPlan(
|
|
||||||
value ? UserPlan.vip : UserPlan.free,
|
|
||||||
);
|
|
||||||
},
|
|
||||||
activeThumbColor: const Color(0xFF7C6DED),
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
import 'package:flutter/foundation.dart';
|
|
||||||
import 'package:in_app_purchase/in_app_purchase.dart';
|
import 'package:in_app_purchase/in_app_purchase.dart';
|
||||||
import 'package:shared_preferences/shared_preferences.dart';
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
|
|
||||||
@@ -15,6 +14,9 @@ class PurchaseResult {
|
|||||||
|
|
||||||
factory PurchaseResult.failed([String? error]) =>
|
factory PurchaseResult.failed([String? error]) =>
|
||||||
PurchaseResult(success: false, error: error);
|
PurchaseResult(success: false, error: error);
|
||||||
|
|
||||||
|
factory PurchaseResult.cancelled() =>
|
||||||
|
const PurchaseResult(success: false);
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract class BillingService {
|
abstract class BillingService {
|
||||||
@@ -23,24 +25,11 @@ abstract class BillingService {
|
|||||||
Future<PurchaseResult> purchasePro();
|
Future<PurchaseResult> purchasePro();
|
||||||
Future<PurchaseResult> restorePurchases();
|
Future<PurchaseResult> restorePurchases();
|
||||||
Future<PurchaseResult> queryPastPurchase();
|
Future<PurchaseResult> queryPastPurchase();
|
||||||
Future<void> completePurchase(String purchaseToken);
|
|
||||||
Stream<List<PurchaseDetails>> get purchaseStream;
|
|
||||||
Future<void> dispose();
|
Future<void> dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
class PlayBillingService implements BillingService {
|
class PlayBillingService implements BillingService {
|
||||||
final InAppPurchase _inAppPurchase = InAppPurchase.instance;
|
final InAppPurchase _inAppPurchase = InAppPurchase.instance;
|
||||||
late final StreamSubscription<List<PurchaseDetails>> _sub;
|
|
||||||
final _controller = StreamController<List<PurchaseDetails>>.broadcast();
|
|
||||||
|
|
||||||
PlayBillingService() {
|
|
||||||
_sub = _inAppPurchase.purchaseStream.listen((purchases) {
|
|
||||||
_controller.add(purchases);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
Stream<List<PurchaseDetails>> get purchaseStream => _controller.stream;
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<PurchaseResult> purchasePro() async {
|
Future<PurchaseResult> purchasePro() async {
|
||||||
@@ -52,51 +41,26 @@ class PlayBillingService implements BillingService {
|
|||||||
final response = await _inAppPurchase.queryProductDetails(
|
final response = await _inAppPurchase.queryProductDetails(
|
||||||
{BillingService.proProductId},
|
{BillingService.proProductId},
|
||||||
);
|
);
|
||||||
|
if (response.error != null) {
|
||||||
|
return PurchaseResult.failed(response.error!.message);
|
||||||
|
}
|
||||||
if (response.productDetails.isEmpty) {
|
if (response.productDetails.isEmpty) {
|
||||||
return PurchaseResult.failed('Product not found');
|
return PurchaseResult.failed('Product not found');
|
||||||
}
|
}
|
||||||
|
|
||||||
final product = response.productDetails.first;
|
final product = response.productDetails.first;
|
||||||
final purchaseParam = PurchaseParam(productDetails: product);
|
return _waitForPurchase(
|
||||||
|
timeout: const Duration(minutes: 2),
|
||||||
final started = await _inAppPurchase.buyNonConsumable(
|
timeoutError: 'Purchase timed out',
|
||||||
purchaseParam: purchaseParam,
|
start: () async {
|
||||||
);
|
final started = await _inAppPurchase.buyNonConsumable(
|
||||||
if (!started) {
|
purchaseParam: PurchaseParam(productDetails: product),
|
||||||
return PurchaseResult.failed('Could not start purchase');
|
);
|
||||||
}
|
if (!started) {
|
||||||
|
throw StateError('Could not start purchase');
|
||||||
final completer = Completer<PurchaseResult>();
|
|
||||||
late StreamSubscription sub;
|
|
||||||
sub = purchaseStream.timeout(
|
|
||||||
const Duration(seconds: 60),
|
|
||||||
onTimeout: (sink) {
|
|
||||||
if (!completer.isCompleted) {
|
|
||||||
completer.complete(PurchaseResult.failed('Purchase timed out'));
|
|
||||||
}
|
}
|
||||||
sub.cancel();
|
|
||||||
},
|
},
|
||||||
).listen((purchases) {
|
);
|
||||||
for (final p in purchases) {
|
|
||||||
if (p.productID == BillingService.proProductId &&
|
|
||||||
p.status == PurchaseStatus.purchased) {
|
|
||||||
if (!completer.isCompleted) {
|
|
||||||
completer.complete(PurchaseResult.ok(p.verificationData.serverVerificationData));
|
|
||||||
}
|
|
||||||
sub.cancel();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (p.status == PurchaseStatus.error) {
|
|
||||||
if (!completer.isCompleted) {
|
|
||||||
completer.complete(PurchaseResult.failed(p.error?.message));
|
|
||||||
}
|
|
||||||
sub.cancel();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return completer.future;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -106,102 +70,101 @@ class PlayBillingService implements BillingService {
|
|||||||
return PurchaseResult.failed('Billing not available');
|
return PurchaseResult.failed('Billing not available');
|
||||||
}
|
}
|
||||||
|
|
||||||
await _inAppPurchase.restorePurchases();
|
return _waitForPurchase(
|
||||||
|
timeout: const Duration(seconds: 30),
|
||||||
final completer = Completer<PurchaseResult>();
|
timeoutError: 'No purchases found',
|
||||||
late StreamSubscription sub;
|
start: _inAppPurchase.restorePurchases,
|
||||||
sub = purchaseStream.timeout(
|
|
||||||
const Duration(seconds: 15),
|
|
||||||
onTimeout: (sink) {
|
|
||||||
if (!completer.isCompleted) {
|
|
||||||
completer.complete(PurchaseResult.failed('Restore timed out'));
|
|
||||||
}
|
|
||||||
sub.cancel();
|
|
||||||
},
|
|
||||||
).listen((purchases) {
|
|
||||||
for (final p in purchases) {
|
|
||||||
if (p.productID == BillingService.proProductId &&
|
|
||||||
(p.status == PurchaseStatus.restored ||
|
|
||||||
p.status == PurchaseStatus.purchased)) {
|
|
||||||
if (!completer.isCompleted) {
|
|
||||||
completer.complete(PurchaseResult.ok(p.verificationData.serverVerificationData));
|
|
||||||
}
|
|
||||||
sub.cancel();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return completer.future;
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
Future<PurchaseResult> queryPastPurchase() async {
|
|
||||||
final available = await _inAppPurchase.isAvailable();
|
|
||||||
if (!available) {
|
|
||||||
return const PurchaseResult();
|
|
||||||
}
|
|
||||||
|
|
||||||
final response = await _inAppPurchase.queryProductDetails(
|
|
||||||
{BillingService.proProductId},
|
|
||||||
);
|
);
|
||||||
if (response.productDetails.isEmpty) {
|
}
|
||||||
return const PurchaseResult();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<PurchaseResult> queryPastPurchase() => restorePurchases();
|
||||||
|
|
||||||
|
Future<PurchaseResult> _waitForPurchase({
|
||||||
|
required Future<void> Function() start,
|
||||||
|
required Duration timeout,
|
||||||
|
required String timeoutError,
|
||||||
|
}) async {
|
||||||
final completer = Completer<PurchaseResult>();
|
final completer = Completer<PurchaseResult>();
|
||||||
late StreamSubscription sub;
|
var handlingPurchase = false;
|
||||||
sub = purchaseStream.timeout(
|
late final StreamSubscription<List<PurchaseDetails>> subscription;
|
||||||
const Duration(seconds: 10),
|
late final Timer timeoutTimer;
|
||||||
onTimeout: (sink) {
|
|
||||||
if (!completer.isCompleted) {
|
void finish(PurchaseResult result) {
|
||||||
completer.complete(const PurchaseResult());
|
if (!completer.isCompleted) {
|
||||||
}
|
completer.complete(result);
|
||||||
sub.cancel();
|
|
||||||
},
|
|
||||||
).listen((purchases) {
|
|
||||||
for (final p in purchases) {
|
|
||||||
if (p.productID == BillingService.proProductId &&
|
|
||||||
(p.status == PurchaseStatus.restored ||
|
|
||||||
p.status == PurchaseStatus.purchased)) {
|
|
||||||
if (!completer.isCompleted) {
|
|
||||||
completer.complete(PurchaseResult.ok(p.verificationData.serverVerificationData));
|
|
||||||
}
|
|
||||||
sub.cancel();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
|
||||||
await _inAppPurchase.restorePurchases();
|
|
||||||
|
|
||||||
return completer.future;
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
Future<void> completePurchase(String purchaseToken) async {
|
|
||||||
if (kDebugMode) {
|
|
||||||
print('completePurchase: $purchaseToken');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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
|
@override
|
||||||
Future<void> dispose() async {
|
Future<void> dispose() async {}
|
||||||
await _sub.cancel();
|
|
||||||
await _controller.close();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class DebugBillingService implements BillingService {
|
class DebugBillingService implements BillingService {
|
||||||
static const _key = 'debug_purchase_token';
|
static const _key = 'debug_purchase_token';
|
||||||
final SharedPreferences _prefs;
|
final SharedPreferences _prefs;
|
||||||
final _controller = StreamController<List<PurchaseDetails>>.broadcast();
|
|
||||||
|
|
||||||
DebugBillingService(this._prefs);
|
DebugBillingService(this._prefs);
|
||||||
|
|
||||||
@override
|
|
||||||
Stream<List<PurchaseDetails>> get purchaseStream => _controller.stream;
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<PurchaseResult> purchasePro() async {
|
Future<PurchaseResult> purchasePro() async {
|
||||||
await Future.delayed(const Duration(seconds: 1));
|
await Future.delayed(const Duration(seconds: 1));
|
||||||
@@ -230,10 +193,5 @@ class DebugBillingService implements BillingService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> completePurchase(String purchaseToken) async {}
|
Future<void> dispose() async {}
|
||||||
|
|
||||||
@override
|
|
||||||
Future<void> dispose() async {
|
|
||||||
await _controller.close();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,7 +30,6 @@ class PremiumManager {
|
|||||||
final result = await _billing.purchasePro();
|
final result = await _billing.purchasePro();
|
||||||
if (result.success && result.purchaseToken != null) {
|
if (result.success && result.purchaseToken != null) {
|
||||||
await _setPremium(true, result.purchaseToken);
|
await _setPremium(true, result.purchaseToken);
|
||||||
await _billing.completePurchase(result.purchaseToken!);
|
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -39,7 +38,6 @@ class PremiumManager {
|
|||||||
final result = await _billing.restorePurchases();
|
final result = await _billing.restorePurchases();
|
||||||
if (result.success && result.purchaseToken != null) {
|
if (result.success && result.purchaseToken != null) {
|
||||||
await _setPremium(true, result.purchaseToken);
|
await _setPremium(true, result.purchaseToken);
|
||||||
await _billing.completePurchase(result.purchaseToken!);
|
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -49,7 +47,6 @@ class PremiumManager {
|
|||||||
final result = await _billing.queryPastPurchase();
|
final result = await _billing.queryPastPurchase();
|
||||||
if (result.success && result.purchaseToken != null) {
|
if (result.success && result.purchaseToken != null) {
|
||||||
await _setPremium(true, result.purchaseToken);
|
await _setPremium(true, result.purchaseToken);
|
||||||
await _billing.completePurchase(result.purchaseToken!);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+167
-186
@@ -5,7 +5,6 @@ import '../../core/l10n/app_strings.dart';
|
|||||||
import '../../core/l10n/locale_provider.dart';
|
import '../../core/l10n/locale_provider.dart';
|
||||||
import '../../core/services/haptic_service.dart';
|
import '../../core/services/haptic_service.dart';
|
||||||
import '../providers/current_user_provider.dart';
|
import '../providers/current_user_provider.dart';
|
||||||
import '../providers/google_drive_provider.dart';
|
|
||||||
import '../providers/premium_provider.dart';
|
import '../providers/premium_provider.dart';
|
||||||
import 'error_snackbar.dart';
|
import 'error_snackbar.dart';
|
||||||
|
|
||||||
@@ -20,14 +19,16 @@ class _ProScreenState extends ConsumerState<ProScreen>
|
|||||||
with SingleTickerProviderStateMixin {
|
with SingleTickerProviderStateMixin {
|
||||||
bool _purchasing = false;
|
bool _purchasing = false;
|
||||||
bool _restoring = false;
|
bool _restoring = false;
|
||||||
|
bool _resetting = false;
|
||||||
bool _showSuccess = false;
|
bool _showSuccess = false;
|
||||||
|
String _successTitle = '';
|
||||||
late final AnimationController _successController;
|
late final AnimationController _successController;
|
||||||
late final Animation<double> _successScale;
|
late final Animation<double> _successScale;
|
||||||
|
|
||||||
static const _gradientColors = [
|
static const _gradientColors = [
|
||||||
Color(0xFF1B5E20),
|
Color(0xFF5B4DCC),
|
||||||
Color(0xFF2E7D32),
|
Color(0xFF7C6DED),
|
||||||
Color(0xFF4CAF8C),
|
Color(0xFF9D8FF5),
|
||||||
];
|
];
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -51,8 +52,11 @@ class _ProScreenState extends ConsumerState<ProScreen>
|
|||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
void _showSuccessOverlay() {
|
void _showSuccessOverlay(String title) {
|
||||||
setState(() => _showSuccess = true);
|
setState(() {
|
||||||
|
_successTitle = title;
|
||||||
|
_showSuccess = true;
|
||||||
|
});
|
||||||
_successController.forward(from: 0.0);
|
_successController.forward(from: 0.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -67,8 +71,6 @@ class _ProScreenState extends ConsumerState<ProScreen>
|
|||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final s = ref.watch(stringsProvider);
|
final s = ref.watch(stringsProvider);
|
||||||
final isPremium = ref.watch(isPremiumProvider);
|
final isPremium = ref.watch(isPremiumProvider);
|
||||||
final driveUserAsync = ref.watch(googleDriveUserProvider);
|
|
||||||
final driveUser = driveUserAsync.value;
|
|
||||||
final colorScheme = Theme.of(context).colorScheme;
|
final colorScheme = Theme.of(context).colorScheme;
|
||||||
|
|
||||||
return Stack(
|
return Stack(
|
||||||
@@ -77,7 +79,7 @@ class _ProScreenState extends ConsumerState<ProScreen>
|
|||||||
body: SafeArea(
|
body: SafeArea(
|
||||||
child: Column(
|
child: Column(
|
||||||
children: [
|
children: [
|
||||||
_buildHeader(context, s, colorScheme),
|
_buildHeader(context),
|
||||||
Expanded(
|
Expanded(
|
||||||
child: SingleChildScrollView(
|
child: SingleChildScrollView(
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 20),
|
padding: const EdgeInsets.symmetric(horizontal: 20),
|
||||||
@@ -85,13 +87,10 @@ class _ProScreenState extends ConsumerState<ProScreen>
|
|||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
const SizedBox(height: 4),
|
const SizedBox(height: 4),
|
||||||
_buildHeroBanner(context, s, colorScheme, isPremium),
|
_buildHeroBanner(context, s, isPremium),
|
||||||
const SizedBox(height: 20),
|
const SizedBox(height: 20),
|
||||||
_buildFeatureList(context, s, colorScheme),
|
_buildFeatureList(context, s, colorScheme),
|
||||||
const SizedBox(height: 16),
|
const SizedBox(height: 16),
|
||||||
if (isPremium) ...[
|
|
||||||
_buildProActiveSection(context, s, colorScheme, driveUser),
|
|
||||||
],
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -106,11 +105,7 @@ class _ProScreenState extends ConsumerState<ProScreen>
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildHeader(
|
Widget _buildHeader(BuildContext context) {
|
||||||
BuildContext context,
|
|
||||||
AppStrings s,
|
|
||||||
ColorScheme colorScheme,
|
|
||||||
) {
|
|
||||||
return Padding(
|
return Padding(
|
||||||
padding: const EdgeInsets.fromLTRB(8, 4, 16, 0),
|
padding: const EdgeInsets.fromLTRB(8, 4, 16, 0),
|
||||||
child: Row(
|
child: Row(
|
||||||
@@ -127,7 +122,6 @@ class _ProScreenState extends ConsumerState<ProScreen>
|
|||||||
Widget _buildHeroBanner(
|
Widget _buildHeroBanner(
|
||||||
BuildContext context,
|
BuildContext context,
|
||||||
AppStrings s,
|
AppStrings s,
|
||||||
ColorScheme colorScheme,
|
|
||||||
bool isVip,
|
bool isVip,
|
||||||
) {
|
) {
|
||||||
return Container(
|
return Container(
|
||||||
@@ -209,7 +203,7 @@ class _ProScreenState extends ConsumerState<ProScreen>
|
|||||||
),
|
),
|
||||||
const SizedBox(height: 20),
|
const SizedBox(height: 20),
|
||||||
Text(
|
Text(
|
||||||
s.proPurchaseSuccess,
|
_successTitle,
|
||||||
style: Theme.of(context).textTheme.titleLarge?.copyWith(
|
style: Theme.of(context).textTheme.titleLarge?.copyWith(
|
||||||
fontWeight: FontWeight.w800,
|
fontWeight: FontWeight.w800,
|
||||||
color: colorScheme.onSurface,
|
color: colorScheme.onSurface,
|
||||||
@@ -240,7 +234,6 @@ class _ProScreenState extends ConsumerState<ProScreen>
|
|||||||
ColorScheme colorScheme,
|
ColorScheme colorScheme,
|
||||||
) {
|
) {
|
||||||
final features = [
|
final features = [
|
||||||
(Icons.cloud_sync_rounded, s.proFeatureCloudSync, s.proFeatureCloudSyncDesc),
|
|
||||||
(Icons.analytics_rounded, s.proFeatureAnalytics, s.proFeatureAnalyticsDesc),
|
(Icons.analytics_rounded, s.proFeatureAnalytics, s.proFeatureAnalyticsDesc),
|
||||||
(Icons.palette_rounded, s.proFeatureCustomization, s.proFeatureCustomizationDesc),
|
(Icons.palette_rounded, s.proFeatureCustomization, s.proFeatureCustomizationDesc),
|
||||||
(Icons.fingerprint_rounded, s.proFeatureBiometric, s.proFeatureBiometricDesc),
|
(Icons.fingerprint_rounded, s.proFeatureBiometric, s.proFeatureBiometricDesc),
|
||||||
@@ -295,116 +288,12 @@ class _ProScreenState extends ConsumerState<ProScreen>
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildProActiveSection(
|
|
||||||
BuildContext context,
|
|
||||||
AppStrings s,
|
|
||||||
ColorScheme colorScheme,
|
|
||||||
dynamic googleUser,
|
|
||||||
) {
|
|
||||||
return Container(
|
|
||||||
padding: const EdgeInsets.all(16),
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: colorScheme.surface,
|
|
||||||
borderRadius: BorderRadius.circular(16),
|
|
||||||
border: Border.all(
|
|
||||||
color: colorScheme.primary.withOpacity(0.2),
|
|
||||||
width: 1,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
child: Column(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
children: [
|
|
||||||
if (googleUser != null) ...[
|
|
||||||
Row(
|
|
||||||
children: [
|
|
||||||
Icon(Icons.email_outlined, size: 18, color: colorScheme.onSurface.withOpacity(0.5)),
|
|
||||||
const SizedBox(width: 8),
|
|
||||||
Expanded(
|
|
||||||
child: Text(
|
|
||||||
googleUser.email,
|
|
||||||
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
|
|
||||||
color: colorScheme.onSurface,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
const SizedBox(height: 12),
|
|
||||||
Row(
|
|
||||||
children: [
|
|
||||||
Icon(Icons.sync_rounded, size: 18, color: colorScheme.primary),
|
|
||||||
const SizedBox(width: 8),
|
|
||||||
Expanded(
|
|
||||||
child: Text(
|
|
||||||
s.proSyncEnabled,
|
|
||||||
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
|
|
||||||
color: colorScheme.onSurface,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
Icon(Icons.check_circle_rounded, color: colorScheme.primary, size: 20),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
const SizedBox(height: 8),
|
|
||||||
Row(
|
|
||||||
children: [
|
|
||||||
Icon(Icons.backup_outlined, size: 18, color: colorScheme.onSurface.withOpacity(0.5)),
|
|
||||||
const SizedBox(width: 8),
|
|
||||||
Text(
|
|
||||||
'${s.proLastBackup}: —',
|
|
||||||
style: Theme.of(context).textTheme.bodySmall?.copyWith(
|
|
||||||
color: colorScheme.onSurface.withOpacity(0.5),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
const SizedBox(height: 16),
|
|
||||||
Row(
|
|
||||||
children: [
|
|
||||||
Expanded(
|
|
||||||
child: OutlinedButton.icon(
|
|
||||||
onPressed: _handleGoogleSignOut,
|
|
||||||
icon: Icon(Icons.logout_rounded, color: colorScheme.error),
|
|
||||||
label: Text(s.proSignOut),
|
|
||||||
style: OutlinedButton.styleFrom(
|
|
||||||
foregroundColor: colorScheme.error,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
] else ...[
|
|
||||||
Text(
|
|
||||||
s.proSignInForSync,
|
|
||||||
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
|
|
||||||
color: colorScheme.onSurface.withOpacity(0.7),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox(height: 16),
|
|
||||||
SizedBox(
|
|
||||||
width: double.infinity,
|
|
||||||
child: OutlinedButton.icon(
|
|
||||||
onPressed: _handleGoogleSignIn,
|
|
||||||
icon: Icon(Icons.login_rounded, color: colorScheme.primary),
|
|
||||||
label: Text(s.proSignInGoogle),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Widget _buildBottomBar(
|
Widget _buildBottomBar(
|
||||||
BuildContext context,
|
BuildContext context,
|
||||||
AppStrings s,
|
AppStrings s,
|
||||||
ColorScheme colorScheme,
|
ColorScheme colorScheme,
|
||||||
bool isVip,
|
bool isVip,
|
||||||
) {
|
) {
|
||||||
if (isVip) {
|
|
||||||
return const SizedBox.shrink();
|
|
||||||
}
|
|
||||||
|
|
||||||
return Container(
|
return Container(
|
||||||
padding: const EdgeInsets.fromLTRB(20, 12, 20, 24),
|
padding: const EdgeInsets.fromLTRB(20, 12, 20, 24),
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
@@ -419,51 +308,124 @@ class _ProScreenState extends ConsumerState<ProScreen>
|
|||||||
child: Column(
|
child: Column(
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
children: [
|
children: [
|
||||||
SizedBox(
|
if (!isVip) ...[
|
||||||
width: double.infinity,
|
SizedBox(
|
||||||
child: FilledButton(
|
width: double.infinity,
|
||||||
onPressed: _purchasing ? null : _handlePurchase,
|
child: FilledButton(
|
||||||
style: FilledButton.styleFrom(
|
onPressed: _purchasing ? null : _handlePurchase,
|
||||||
padding: const EdgeInsets.symmetric(vertical: 16),
|
style: FilledButton.styleFrom(
|
||||||
shape: RoundedRectangleBorder(
|
padding: const EdgeInsets.symmetric(vertical: 16),
|
||||||
borderRadius: BorderRadius.circular(12),
|
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: _purchasing
|
child: Row(
|
||||||
? SizedBox(
|
children: [
|
||||||
width: 20,
|
Icon(
|
||||||
height: 20,
|
Icons.verified_rounded,
|
||||||
child: CircularProgressIndicator(
|
color: colorScheme.primary,
|
||||||
strokeWidth: 2,
|
size: 20,
|
||||||
color: colorScheme.onPrimary,
|
),
|
||||||
),
|
const SizedBox(width: 10),
|
||||||
)
|
Expanded(
|
||||||
: Text(
|
child: Text(
|
||||||
s.proBuy,
|
s.proActive,
|
||||||
style: const TextStyle(
|
style: TextStyle(
|
||||||
fontSize: 16,
|
color: colorScheme.primary,
|
||||||
fontWeight: FontWeight.w700,
|
fontWeight: FontWeight.w700,
|
||||||
|
fontSize: 14,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
const SizedBox(height: 10),
|
||||||
const SizedBox(height: 8),
|
SizedBox(
|
||||||
SizedBox(
|
width: double.infinity,
|
||||||
width: double.infinity,
|
child: OutlinedButton.icon(
|
||||||
child: TextButton(
|
onPressed: _resetting ? null : _handleResetData,
|
||||||
onPressed: _restoring ? null : _handleRestore,
|
icon: _resetting
|
||||||
child: _restoring
|
? SizedBox(
|
||||||
? SizedBox(
|
width: 16,
|
||||||
width: 16,
|
height: 16,
|
||||||
height: 16,
|
child: CircularProgressIndicator(
|
||||||
child: CircularProgressIndicator(
|
strokeWidth: 2,
|
||||||
strokeWidth: 2,
|
color: colorScheme.onSurface.withOpacity(0.5),
|
||||||
color: colorScheme.primary,
|
),
|
||||||
|
)
|
||||||
|
: Icon(
|
||||||
|
Icons.restart_alt_rounded,
|
||||||
|
size: 18,
|
||||||
|
color: colorScheme.onSurface.withOpacity(0.6),
|
||||||
),
|
),
|
||||||
)
|
label: Text(
|
||||||
: Text(s.proRestorePurchases),
|
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),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
],
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
@@ -478,7 +440,7 @@ class _ProScreenState extends ConsumerState<ProScreen>
|
|||||||
if (result.success) {
|
if (result.success) {
|
||||||
await ref.read(currentUserProvider.notifier).refreshFromPremium();
|
await ref.read(currentUserProvider.notifier).refreshFromPremium();
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
_showSuccessOverlay();
|
_showSuccessOverlay(ref.read(stringsProvider).proPurchaseSuccess);
|
||||||
HapticService.medium();
|
HapticService.medium();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -504,7 +466,7 @@ class _ProScreenState extends ConsumerState<ProScreen>
|
|||||||
if (result.success) {
|
if (result.success) {
|
||||||
await ref.read(currentUserProvider.notifier).refreshFromPremium();
|
await ref.read(currentUserProvider.notifier).refreshFromPremium();
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
_showSuccessOverlay();
|
_showSuccessOverlay(ref.read(stringsProvider).proRestoreSuccessTitle);
|
||||||
HapticService.medium();
|
HapticService.medium();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -521,27 +483,46 @@ class _ProScreenState extends ConsumerState<ProScreen>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _handleGoogleSignIn() async {
|
Future<void> _handleResetData() async {
|
||||||
HapticService.light();
|
final s = ref.read(stringsProvider);
|
||||||
try {
|
showDialog(
|
||||||
final service = ref.read(googleDriveServiceProvider);
|
context: context,
|
||||||
await service.signIn();
|
builder: (ctx) => AlertDialog(
|
||||||
} catch (e) {
|
title: Text(s.proResetData),
|
||||||
if (mounted) {
|
content: Text(s.proResetDataConfirm),
|
||||||
showErrorSnackbar(context, e.toString());
|
actions: [
|
||||||
}
|
TextButton(
|
||||||
}
|
onPressed: () => Navigator.pop(ctx),
|
||||||
}
|
child: Text(s.cancel),
|
||||||
|
),
|
||||||
Future<void> _handleGoogleSignOut() async {
|
TextButton(
|
||||||
HapticService.light();
|
onPressed: () async {
|
||||||
try {
|
Navigator.pop(ctx);
|
||||||
final service = ref.read(googleDriveServiceProvider);
|
HapticService.light();
|
||||||
await service.signOut();
|
setState(() => _resetting = true);
|
||||||
} catch (e) {
|
try {
|
||||||
if (mounted) {
|
final manager = ref.read(premiumManagerProvider);
|
||||||
showErrorSnackbar(context, e.toString());
|
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),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,169 +3,258 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|||||||
import 'package:go_router/go_router.dart';
|
import 'package:go_router/go_router.dart';
|
||||||
import '../../core/l10n/locale_provider.dart';
|
import '../../core/l10n/locale_provider.dart';
|
||||||
import '../../core/services/haptic_service.dart';
|
import '../../core/services/haptic_service.dart';
|
||||||
import '../providers/google_drive_provider.dart';
|
|
||||||
import '../providers/premium_provider.dart';
|
import '../providers/premium_provider.dart';
|
||||||
|
|
||||||
class ProSubscriptionCard extends ConsumerWidget {
|
class ProSubscriptionCard extends ConsumerStatefulWidget {
|
||||||
const ProSubscriptionCard({super.key});
|
const ProSubscriptionCard({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
ConsumerState<ProSubscriptionCard> createState() =>
|
||||||
|
_ProSubscriptionCardState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _ProSubscriptionCardState extends ConsumerState<ProSubscriptionCard>
|
||||||
|
with SingleTickerProviderStateMixin {
|
||||||
|
late final AnimationController _shimmerController;
|
||||||
|
|
||||||
static const _gradientColors = [
|
static const _gradientColors = [
|
||||||
Color(0xFF1B5E20),
|
Color(0xFF5B4DCC),
|
||||||
Color(0xFF2E7D32),
|
Color(0xFF7C6DED),
|
||||||
Color(0xFF4CAF8C),
|
Color(0xFF9D8FF5),
|
||||||
];
|
];
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
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) {
|
||||||
final s = ref.watch(stringsProvider);
|
final s = ref.watch(stringsProvider);
|
||||||
final isPremium = ref.watch(isPremiumProvider);
|
final isPremium = ref.watch(isPremiumProvider);
|
||||||
final driveUserAsync = ref.watch(googleDriveUserProvider);
|
|
||||||
final driveUser = driveUserAsync.value;
|
|
||||||
|
|
||||||
return Container(
|
return ClipRRect(
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 24),
|
borderRadius: BorderRadius.circular(20),
|
||||||
decoration: BoxDecoration(
|
child: Stack(
|
||||||
gradient: const LinearGradient(
|
|
||||||
begin: Alignment.topLeft,
|
|
||||||
end: Alignment.bottomRight,
|
|
||||||
colors: _gradientColors,
|
|
||||||
),
|
|
||||||
borderRadius: BorderRadius.circular(16),
|
|
||||||
),
|
|
||||||
child: Column(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
children: [
|
children: [
|
||||||
Row(
|
Container(
|
||||||
children: [
|
padding: const EdgeInsets.fromLTRB(20, 22, 20, 18),
|
||||||
Container(
|
decoration: const BoxDecoration(
|
||||||
padding: const EdgeInsets.all(12),
|
gradient: LinearGradient(
|
||||||
decoration: BoxDecoration(
|
begin: Alignment.topLeft,
|
||||||
color: Colors.white.withOpacity(0.15),
|
end: Alignment.bottomRight,
|
||||||
borderRadius: BorderRadius.circular(12),
|
colors: _gradientColors,
|
||||||
),
|
|
||||||
child: Icon(
|
|
||||||
isPremium
|
|
||||||
? Icons.verified_rounded
|
|
||||||
: Icons.workspace_premium_rounded,
|
|
||||||
color: Colors.white,
|
|
||||||
size: 28,
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
const SizedBox(width: 14),
|
),
|
||||||
Expanded(
|
child: Column(
|
||||||
child: Column(
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
children: [
|
||||||
|
Row(
|
||||||
children: [
|
children: [
|
||||||
Text(
|
Container(
|
||||||
s.proTitle,
|
padding: const EdgeInsets.all(10),
|
||||||
style:
|
decoration: BoxDecoration(
|
||||||
Theme.of(context).textTheme.titleLarge?.copyWith(
|
color: Colors.white.withOpacity(0.18),
|
||||||
fontWeight: FontWeight.w900,
|
borderRadius: BorderRadius.circular(12),
|
||||||
color: Colors.white,
|
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(height: 4),
|
const SizedBox(width: 14),
|
||||||
Text(
|
Expanded(
|
||||||
isPremium ? s.proActive : s.proSubtitle,
|
child: Column(
|
||||||
style: isPremium
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
? Theme.of(context).textTheme.bodyMedium?.copyWith(
|
children: [
|
||||||
color: Colors.white.withOpacity(0.9),
|
Text(
|
||||||
fontWeight: FontWeight.w600,
|
s.proTitle,
|
||||||
)
|
style: Theme.of(context)
|
||||||
: Theme.of(context).textTheme.bodySmall?.copyWith(
|
.textTheme
|
||||||
color: Colors.white.withOpacity(0.7),
|
.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,
|
||||||
const SizedBox(height: 16),
|
child: _GlassButton(
|
||||||
if (!isPremium) ...[
|
label: s.proAboutPro,
|
||||||
Row(
|
icon: Icons.arrow_forward_rounded,
|
||||||
children: [
|
onTap: () {
|
||||||
Expanded(
|
|
||||||
child: OutlinedButton(
|
|
||||||
onPressed: () {
|
|
||||||
HapticService.light();
|
HapticService.light();
|
||||||
context.push('/pro');
|
context.push('/pro');
|
||||||
},
|
},
|
||||||
style: OutlinedButton.styleFrom(
|
|
||||||
foregroundColor: Colors.white,
|
|
||||||
side: BorderSide(
|
|
||||||
color: Colors.white.withOpacity(0.4), width: 1.5),
|
|
||||||
padding: const EdgeInsets.symmetric(vertical: 12),
|
|
||||||
shape: RoundedRectangleBorder(
|
|
||||||
borderRadius: BorderRadius.circular(12),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
child: Text(
|
|
||||||
s.proAboutPro,
|
|
||||||
style: const TextStyle(
|
|
||||||
fontWeight: FontWeight.w700, fontSize: 15),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
] else ...[
|
),
|
||||||
Row(
|
Positioned.fill(
|
||||||
children: [
|
child: IgnorePointer(
|
||||||
Expanded(
|
child: AnimatedBuilder(
|
||||||
child: OutlinedButton.icon(
|
animation: _shimmerController,
|
||||||
onPressed: () {
|
builder: (context, _) {
|
||||||
HapticService.light();
|
final t = _shimmerController.value;
|
||||||
context.push('/backup');
|
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);
|
||||||
},
|
},
|
||||||
icon: Icon(
|
child: Container(
|
||||||
driveUser != null
|
decoration: BoxDecoration(
|
||||||
? Icons.cloud_done_rounded
|
borderRadius: BorderRadius.circular(20),
|
||||||
: Icons.cloud_sync_rounded,
|
border: Border.all(
|
||||||
color: Colors.white,
|
color: Colors.white.withOpacity(0.15),
|
||||||
size: 20,
|
width: 1,
|
||||||
),
|
),
|
||||||
label: Text(s.backupSyncWithDrive),
|
|
||||||
style: OutlinedButton.styleFrom(
|
|
||||||
foregroundColor: Colors.white,
|
|
||||||
side: BorderSide(
|
|
||||||
color: Colors.white.withOpacity(0.4), width: 1.5),
|
|
||||||
padding: const EdgeInsets.symmetric(vertical: 12),
|
|
||||||
shape: RoundedRectangleBorder(
|
|
||||||
borderRadius: BorderRadius.circular(12),
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
);
|
||||||
),
|
},
|
||||||
],
|
|
||||||
),
|
|
||||||
if (driveUser == null) ...[
|
|
||||||
const SizedBox(height: 10),
|
|
||||||
SizedBox(
|
|
||||||
width: double.infinity,
|
|
||||||
child: OutlinedButton.icon(
|
|
||||||
onPressed: () {
|
|
||||||
HapticService.light();
|
|
||||||
ref.read(googleDriveServiceProvider).signIn();
|
|
||||||
},
|
|
||||||
icon: const Icon(Icons.login_rounded,
|
|
||||||
color: Colors.white, size: 18),
|
|
||||||
label: Text(s.proSignInGoogle),
|
|
||||||
style: OutlinedButton.styleFrom(
|
|
||||||
foregroundColor: Colors.white,
|
|
||||||
side: BorderSide(
|
|
||||||
color: Colors.white.withOpacity(0.3), width: 1),
|
|
||||||
padding: const EdgeInsets.symmetric(vertical: 10),
|
|
||||||
shape: RoundedRectangleBorder(
|
|
||||||
borderRadius: BorderRadius.circular(12),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
],
|
),
|
||||||
],
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user