This commit is contained in:
2026-06-28 18:33:46 +03:00
parent 65ea30339d
commit 4727835402
22 changed files with 534 additions and 54 deletions
@@ -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;
}
+9
View File
@@ -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;
}
+55
View File
@@ -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),
),
),
),
],
),
),
);
}
}
+22
View File
@@ -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();
}
}
+92
View File
@@ -0,0 +1,92 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:go_router/go_router.dart';
import '../../core/l10n/app_strings.dart';
import '../../core/l10n/locale_provider.dart';
class PaywallScreen extends ConsumerWidget {
const PaywallScreen({super.key});
@override
Widget build(BuildContext context, WidgetRef ref) {
final s = AppStrings(ref.watch(localeProvider));
return Scaffold(
backgroundColor: Theme.of(context).scaffoldBackgroundColor,
appBar: AppBar(
backgroundColor: Theme.of(context).scaffoldBackgroundColor,
elevation: 0,
scrolledUnderElevation: 0,
leading: IconButton(
icon: const Icon(Icons.arrow_back_rounded),
onPressed: () => context.pop(),
),
),
body: SafeArea(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 24),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
padding: const EdgeInsets.all(24),
decoration: BoxDecoration(
color: const Color(0xFF7C6DED).withOpacity(0.12),
shape: BoxShape.circle,
),
child: const Icon(
Icons.workspace_premium_rounded,
size: 64,
color: Color(0xFF7C6DED),
),
),
const SizedBox(height: 24),
Text(
s.premium,
style: Theme.of(context).textTheme.headlineMedium?.copyWith(
fontWeight: FontWeight.w700,
),
),
const SizedBox(height: 12),
Text(
s.premiumDescription,
textAlign: TextAlign.center,
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
color: Theme.of(context)
.colorScheme
.onSurface
.withOpacity(0.6),
),
),
const SizedBox(height: 32),
_FeatureItem(icon: Icons.palette_rounded, label: s.premiumFeatureColors),
_FeatureItem(icon: Icons.height_rounded, label: s.premiumFeatureHeight),
_FeatureItem(icon: Icons.account_balance_wallet_rounded, label: s.premiumFeatureAccounts),
],
),
),
),
);
}
}
class _FeatureItem extends StatelessWidget {
final IconData icon;
final String label;
const _FeatureItem({required this.icon, required this.label});
@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.symmetric(vertical: 8),
child: Row(
children: [
Icon(icon, size: 20, color: const Color(0xFF7C6DED)),
const SizedBox(width: 12),
Text(label, style: Theme.of(context).textTheme.bodyMedium),
],
),
);
}
}
@@ -0,0 +1,32 @@
import 'package:flutter_riverpod/flutter_riverpod.dart';
import '../../features/dashboard/provider.dart';
import '../models/user_model.dart';
class CurrentUserNotifier extends Notifier<UserModel> {
static const _key = 'user_plan';
@override
UserModel build() {
final prefs = ref.watch(sharedPreferencesProvider);
final planName = prefs.getString(_key);
final plan = UserPlan.values.firstWhere(
(e) => e.name == planName,
orElse: () => UserPlan.free,
);
return UserModel(plan: plan);
}
Future<void> setPlan(UserPlan plan) async {
final prefs = ref.read(sharedPreferencesProvider);
state = UserModel(plan: plan);
await prefs.setString(_key, plan.name);
}
Future<void> toggleVip() async {
await setPlan(state.isVip ? UserPlan.free : UserPlan.vip);
}
}
final currentUserProvider = NotifierProvider<CurrentUserNotifier, UserModel>(
CurrentUserNotifier.new,
);