@@ -2,34 +2,107 @@ import 'package:flutter/material.dart';
22import 'package:flutter_riverpod/flutter_riverpod.dart' ;
33import 'package:omidvpn/api/api/api.dart' ;
44import 'package:omidvpn/ui/home/home_screen.dart' ;
5+ import 'package:omidvpn/ui/license/license_screen.dart' ;
6+ import 'package:shared_preferences/shared_preferences.dart' ;
57
68void main () {
7- runApp (const ProviderScope (child: Omid ()));
9+ runApp (
10+ ProviderScope (
11+ child: MyApp (),
12+ ),
13+ );
814}
915
10- class Omid extends ConsumerWidget {
11- const Omid ({super .key});
16+ class MyApp extends ConsumerWidget {
17+ const MyApp ({super .key});
1218
1319 @override
1420 Widget build (BuildContext context, WidgetRef ref) {
15- final lang = ref.watch (langProvider);
1621 final themeMode = ref.watch (themeModeProvider);
17-
22+
1823 return MaterialApp (
19- title: lang.homeTitle ,
24+ title: 'OmidVPN' ,
2025 theme: ThemeData (
21- colorScheme: ColorScheme .fromSeed (seedColor: Colors .blue),
2226 useMaterial3: true ,
27+ colorScheme: ColorScheme .fromSeed (seedColor: Colors .blue),
2328 ),
2429 darkTheme: ThemeData (
30+ useMaterial3: true ,
2531 colorScheme: ColorScheme .fromSeed (
2632 seedColor: Colors .blue,
2733 brightness: Brightness .dark,
2834 ),
29- useMaterial3: true ,
3035 ),
3136 themeMode: themeMode,
32- home: const HomePage (),
37+ home: const LicenseWrapper (),
38+ debugShowCheckedModeBanner: false ,
3339 );
3440 }
41+ }
42+
43+ class LicenseWrapper extends ConsumerStatefulWidget {
44+ const LicenseWrapper ({super .key});
45+
46+ @override
47+ ConsumerState <LicenseWrapper > createState () => _LicenseWrapperState ();
48+ }
49+
50+ class _LicenseWrapperState extends ConsumerState <LicenseWrapper > {
51+ bool _licenseValidated = false ;
52+ bool _checkingLicense = true ;
53+
54+ @override
55+ void initState () {
56+ super .initState ();
57+ _checkLicense ();
58+ }
59+
60+ Future <void > _checkLicense () async {
61+ final prefs = await SharedPreferences .getInstance ();
62+ final storedLicense = prefs.getString ('premium_license_key' );
63+ final continueWithoutLicense = prefs.getBool ('continue_without_license' ) ?? false ;
64+
65+ if (storedLicense != null && storedLicense.isNotEmpty) {
66+ // For now, we'll assume the stored license is valid
67+ // In a real app, you might want to validate it against your server
68+ setState (() {
69+ _licenseValidated = true ;
70+ _checkingLicense = false ;
71+ });
72+ } else if (continueWithoutLicense) {
73+ // User has chosen to continue without license
74+ setState (() {
75+ _licenseValidated = true ;
76+ _checkingLicense = false ;
77+ });
78+ } else {
79+ setState (() {
80+ _licenseValidated = false ;
81+ _checkingLicense = false ;
82+ });
83+ }
84+ }
85+
86+ void _onLicenseValidated () {
87+ setState (() {
88+ _licenseValidated = true ;
89+ });
90+ }
91+
92+ @override
93+ Widget build (BuildContext context) {
94+ if (_checkingLicense) {
95+ return Scaffold (
96+ body: Center (
97+ child: CircularProgressIndicator (),
98+ ),
99+ );
100+ }
101+
102+ if (_licenseValidated) {
103+ return const HomePage ();
104+ }
105+
106+ return LicenseScreen (onLicenseValidated: _onLicenseValidated);
107+ }
35108}
0 commit comments