11import 'package:flutter/material.dart' ;
2+ import 'package:flutter_localizations/flutter_localizations.dart' ;
3+ import 'package:flutter_gen/gen_l10n/app_localizations.dart' ;
24import 'package:provider/provider.dart' ;
5+
36import 'package:vpn_client/pages/apps/apps_page.dart' ;
47import 'package:vpn_client/pages/main/main_page.dart' ;
5- import 'package:vpn_client/pages/servers/servers_page.dart' ;
68import 'package:vpn_client/pages/settings/settings_page.dart' ;
7- import 'package:vpn_client/pages/speed/speed_page.dart' ;
8- import 'package:vpn_client/providers/vpn_provider.dart' ;
9+ import 'package:vpn_client/pages/servers/servers_page.dart' ;
910import 'package:vpn_client/theme_provider.dart' ;
11+ import 'package:vpn_client/vpn_state.dart' ;
1012
1113import 'design/colors.dart' ;
1214import 'nav_bar.dart' ;
1315
1416void main () {
15- runApp (MultiProvider (providers: [ChangeNotifierProvider (create: (_) => ThemeProvider ()), ChangeNotifierProvider (create: (_) => VPNProvider ())], child: const App ()));
17+ runApp (
18+ MultiProvider (
19+ providers: [
20+ ChangeNotifierProvider (create: (_) => ThemeProvider ()),
21+ ChangeNotifierProvider (create: (_) => VpnState ()),
22+ ],
23+ child: const App (),
24+ ),
25+ );
1626}
1727
1828class App extends StatelessWidget {
@@ -22,13 +32,54 @@ class App extends StatelessWidget {
2232 Widget build (BuildContext context) {
2333 final themeProvider = Provider .of <ThemeProvider >(context);
2434
35+ // If you want to override it manually, do it here (or leave as null to use system):
36+ // final Locale? manualLocale = const Locale('ru'); // ← override example
37+ final Locale ? manualLocale = null ; // ← use system by default
38+
2539 return MaterialApp (
2640 debugShowCheckedModeBanner: false ,
2741 title: 'VPN Client' ,
2842 theme: lightTheme,
2943 darkTheme: darkTheme,
44+ locale: manualLocale,
45+ localeResolutionCallback: (locale, supportedLocales) {
46+ if (locale == null ) return const Locale ('en' );
47+
48+ // Check for exact match
49+ for (var supportedLocale in supportedLocales) {
50+ if (supportedLocale.languageCode == locale.languageCode &&
51+ (supportedLocale.countryCode == null ||
52+ supportedLocale.countryCode == locale.countryCode)) {
53+ return supportedLocale;
54+ }
55+ }
56+
57+ // If Chinese variants are not supported, fallback to zh
58+ if (locale.languageCode == 'zh' ) {
59+ return supportedLocales.contains (const Locale ('zh' ))
60+ ? const Locale ('zh' )
61+ : const Locale ('en' );
62+ }
63+
64+ // Fallback to 'en' if not found
65+ return const Locale ('en' );
66+ },
67+
3068 themeMode: themeProvider.themeMode,
3169 home: const MainScreen (),
70+
71+ localizationsDelegates: const [
72+ AppLocalizations .delegate,
73+ GlobalMaterialLocalizations .delegate,
74+ GlobalWidgetsLocalizations .delegate,
75+ GlobalCupertinoLocalizations .delegate,
76+ ],
77+ supportedLocales: const [
78+ Locale ('en' ),
79+ Locale ('ru' ),
80+ Locale ('th' ),
81+ Locale ('zh' ),
82+ ],
3283 );
3384 }
3485}
@@ -51,7 +102,7 @@ class _MainScreenState extends State<MainScreen> {
51102 const AppsPage (),
52103 ServersPage (onNavBarTap: _handleNavBarTap),
53104 const MainPage (),
54- const SpeedPage ( ),
105+ const PlaceholderPage (text : 'Speed Page' ),
55106 const SettingsPage (),
56107 ];
57108 }
@@ -69,8 +120,17 @@ class _MainScreenState extends State<MainScreen> {
69120 bottomNavigationBar: NavBar (
70121 initialIndex: _currentIndex,
71122 onItemTapped: _handleNavBarTap,
72- selectedColor: Theme .of (context).colorScheme.primary,
73123 ),
74124 );
75125 }
76126}
127+
128+ class PlaceholderPage extends StatelessWidget {
129+ final String text;
130+ const PlaceholderPage ({super .key, required this .text});
131+
132+ @override
133+ Widget build (BuildContext context) {
134+ return Center (child: Text (text));
135+ }
136+ }
0 commit comments