11import 'package:flutter/material.dart' ;
2+ import 'package:shared_preferences/shared_preferences.dart' ; // Add this import
23import 'package:vpn_client/localization_service.dart' ;
34import 'setting_info_card.dart' ;
45import 'support_service_card.dart' ;
6+ import 'package:vpn_client/utility/clean_scroll.dart' ;
57import 'action_button.dart' ;
68import 'reset_settings_dialog.dart' ;
79import 'snackbar_utils.dart' ;
@@ -22,6 +24,32 @@ class _SettingPageState extends State<SettingPage> {
2224 String _supportStatus = '1 me/vnp_client_support' ;
2325 String _userId = '2485926342' ;
2426
27+ @override
28+ void initState () {
29+ super .initState ();
30+ _loadSettings (); // Load saved state on page start
31+ }
32+
33+ Future <void > _loadSettings () async {
34+ final prefs = await SharedPreferences .getInstance ();
35+ setState (() {
36+ _isConnected = prefs.getBool ('isConnected' ) ?? true ;
37+ _connectionStatus =
38+ prefs.getString ('connectionStatus' ) ?? '1 me/vnp_client_bot' ;
39+ _supportStatus =
40+ prefs.getString ('supportStatus' ) ?? '1 me/vnp_client_support' ;
41+ _userId = prefs.getString ('userId' ) ?? '2485926342' ;
42+ });
43+ }
44+
45+ Future <void > _saveSettings () async {
46+ final prefs = await SharedPreferences .getInstance ();
47+ await prefs.setBool ('isConnected' , _isConnected);
48+ await prefs.setString ('connectionStatus' , _connectionStatus);
49+ await prefs.setString ('supportStatus' , _supportStatus);
50+ await prefs.setString ('userId' , _userId);
51+ }
52+
2553 @override
2654 Widget build (BuildContext context) {
2755 return Scaffold (
@@ -40,38 +68,37 @@ class _SettingPageState extends State<SettingPage> {
4068 centerTitle: true ,
4169 leading: const SizedBox (),
4270 ),
43- body: Padding (
44- padding: const EdgeInsets .symmetric (horizontal: 16.0 ),
45- child: Column (
46- crossAxisAlignment: CrossAxisAlignment .start,
47- children: [
48- const SizedBox (height: 20 ),
49-
50- SettingInfoCard (
51- isConnected: _isConnected,
52- connectionStatus: _connectionStatus,
53- supportStatus: _supportStatus,
54- userId: _userId,
55- ),
56-
57- const SizedBox (height: 20 ),
58-
59- SupportServiceCard (
60- onTap: () {
61- // Handle support service tap
62- },
63- ),
64-
65- const SizedBox (height: 30 ),
66-
67- Center (
68- child: ActionButton (
71+ body: ScrollConfiguration (
72+ behavior: NoGlowScrollBehavior (),
73+ child: SingleChildScrollView (
74+ physics: const ClampingScrollPhysics (),
75+ padding: const EdgeInsets .symmetric (horizontal: 16.0 ),
76+ child: Column (
77+ crossAxisAlignment: CrossAxisAlignment .start,
78+ children: [
79+ const SizedBox (height: 20 ),
80+ SettingInfoCard (
6981 isConnected: _isConnected,
70- onResetPressed: _showResetDialog,
71- onConnectPressed: _connectToBot,
82+ connectionStatus: _connectionStatus,
83+ supportStatus: _supportStatus,
84+ userId: _userId,
85+ ),
86+ const SizedBox (height: 20 ),
87+ SupportServiceCard (
88+ onTap: () {
89+ _connectToBot ();
90+ },
91+ ),
92+ const SizedBox (height: 30 ),
93+ Center (
94+ child: ActionButton (
95+ isConnected: _isConnected,
96+ onResetPressed: _showResetDialog,
97+ onConnectPressed: _connectToBot,
98+ ),
7299 ),
73- ) ,
74- ] ,
100+ ] ,
101+ ) ,
75102 ),
76103 ),
77104 );
@@ -89,14 +116,17 @@ class _SettingPageState extends State<SettingPage> {
89116 }
90117 }
91118
92- void _resetSettings () {
119+ void _resetSettings () async {
93120 setState (() {
94121 _isConnected = false ;
95122 _connectionStatus = '' ;
96123 _supportStatus = '' ;
97124 _userId = '' ;
98125 });
99126
127+ await _saveSettings (); // Save updated state persistently
128+
129+ if (! mounted) return ;
100130 SnackbarUtils .showResetSuccessSnackbar (context);
101131 }
102132
0 commit comments