feat: replace SharedPreferences with file-based AppConfigService and add HomePage navigation
- Implement AppConfigService using path_provider to store settings in a local JSON file,\n ensuring configuration survives app updates/reinstalls.\n - Replace shared_preferences with AppConfigService in HomePage, SettingsPage,\n and RegistrationPage.\n - Replace shared_preferences with AppConfigService in HomePage, SettingsPage,\n and RegistrationPage.\n - Add HomePage.dart as the main navigation hub with feature cards (Registration,\n Boxing, Shelf Query) and dynamic connection status bar.\n - Remove Settings entry from RegistrationPage; Settings are only accessible from\n the Home page. Use 'flutter analyze' to verify the code.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:pad_scanner/services/app_config_service.dart';
|
||||
import 'package:pad_scanner/services/api_service.dart';
|
||||
|
||||
class SettingsPage extends StatefulWidget {
|
||||
@@ -22,8 +22,8 @@ class _SettingsPageState extends State<SettingsPage> {
|
||||
}
|
||||
|
||||
Future<void> _loadUrl() async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
final url = prefs.getString('api_url') ?? '';
|
||||
final configService = AppConfigService();
|
||||
final url = await configService.getString('api_url') ?? '';
|
||||
_controller.text = url;
|
||||
}
|
||||
|
||||
@@ -34,8 +34,8 @@ class _SettingsPageState extends State<SettingsPage> {
|
||||
return;
|
||||
}
|
||||
setState(() => _saving = true);
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
await prefs.setString('api_url', url);
|
||||
final configService = AppConfigService();
|
||||
await configService.setString('api_url', url);
|
||||
setState(() => _saving = false);
|
||||
if (mounted) {
|
||||
_showSnackBar('设置已保存');
|
||||
@@ -52,10 +52,7 @@ class _SettingsPageState extends State<SettingsPage> {
|
||||
final ok = await _apiService.testConnection(url);
|
||||
setState(() => _testing = false);
|
||||
if (mounted) {
|
||||
_showSnackBar(
|
||||
ok ? '连接成功' : '连接失败,请检查地址和网络',
|
||||
isError: !ok,
|
||||
);
|
||||
_showSnackBar(ok ? '连接成功' : '连接失败,请检查地址和网络', isError: !ok);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user