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:
Misaka_Company
2026-05-11 16:24:16 +08:00
parent 3f70049292
commit cdc64bf82f
10 changed files with 611 additions and 137 deletions

View File

@@ -1,9 +1,8 @@
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/scanner_service.dart';
import 'package:pad_scanner/services/code_parser.dart';
import 'package:pad_scanner/services/api_service.dart';
import 'package:pad_scanner/pages/settings_page.dart';
class RegistrationPage extends StatefulWidget {
const RegistrationPage({super.key});
@@ -107,8 +106,8 @@ class _RegistrationPageState extends State<RegistrationPage> {
Future<void> _submit() async {
if (!_canSubmit) return;
final prefs = await SharedPreferences.getInstance();
final baseUrl = prefs.getString('api_url') ?? '';
final configService = AppConfigService();
final baseUrl = await configService.getString('api_url') ?? '';
if (baseUrl.isEmpty) {
_showFeedback('未配置 API 地址,请前往设置', isError: true);
return;
@@ -143,8 +142,7 @@ class _RegistrationPageState extends State<RegistrationPage> {
_locationCode = null;
_locationType = null;
}
_successMessage =
_isLocked ? '货位已锁定,请扫描下一张执行卡' : '上架成功';
_successMessage = _isLocked ? '货位已锁定,请扫描下一张执行卡' : '上架成功';
});
_showFeedback('上架成功', isError: false);
Future.delayed(const Duration(milliseconds: 1500), () {
@@ -222,8 +220,10 @@ class _RegistrationPageState extends State<RegistrationPage> {
const SizedBox(height: 4),
Text('登记时间:${info?["registered_at"] ?? "未知"}'),
const SizedBox(height: 12),
const Text('请核查实物,确认是否操作错误。',
style: TextStyle(fontWeight: FontWeight.bold)),
const Text(
'请核查实物,确认是否操作错误。',
style: TextStyle(fontWeight: FontWeight.bold),
),
],
),
actions: [
@@ -275,17 +275,7 @@ class _RegistrationPageState extends State<RegistrationPage> {
child: Row(
children: [
const Text('锁定货位', style: TextStyle(fontSize: 13)),
Switch(
value: _isLocked,
onChanged: _toggleLock,
),
IconButton(
icon: const Icon(Icons.settings),
onPressed: () => Navigator.push(
context,
MaterialPageRoute(builder: (_) => const SettingsPage()),
),
),
Switch(value: _isLocked, onChanged: _toggleLock),
],
),
),
@@ -297,8 +287,7 @@ class _RegistrationPageState extends State<RegistrationPage> {
if (_snackbarMessage != null)
Container(
width: double.infinity,
padding:
const EdgeInsets.symmetric(vertical: 10, horizontal: 16),
padding: const EdgeInsets.symmetric(vertical: 10, horizontal: 16),
color: _snackbarColor,
child: Text(
_snackbarMessage!,
@@ -316,17 +305,24 @@ class _RegistrationPageState extends State<RegistrationPage> {
// ---- 目标货位 (上方) ----
Row(
children: [
const Text('目标货位',
style: TextStyle(
fontSize: 14, fontWeight: FontWeight.w500)),
const Text(
'目标货位',
style: TextStyle(
fontSize: 14,
fontWeight: FontWeight.w500,
),
),
if (_locationCode != null) ...[
const SizedBox(width: 8),
Container(
padding: const EdgeInsets.symmetric(
horizontal: 6, vertical: 2),
horizontal: 6,
vertical: 2,
),
decoration: BoxDecoration(
color: _locationLabelColor(_locationType)
.withValues(alpha: 0.15),
color: _locationLabelColor(
_locationType,
).withValues(alpha: 0.15),
borderRadius: BorderRadius.circular(4),
),
child: Text(
@@ -345,7 +341,9 @@ class _RegistrationPageState extends State<RegistrationPage> {
Container(
width: double.infinity,
padding: const EdgeInsets.symmetric(
horizontal: 12, vertical: 14),
horizontal: 12,
vertical: 14,
),
decoration: BoxDecoration(
border: Border.all(
color: _locationCode != null
@@ -370,8 +368,11 @@ class _RegistrationPageState extends State<RegistrationPage> {
),
),
if (_isLocked)
const Icon(Icons.lock,
color: Colors.orange, size: 20),
const Icon(
Icons.lock,
color: Colors.orange,
size: 20,
),
],
),
),
@@ -381,14 +382,20 @@ class _RegistrationPageState extends State<RegistrationPage> {
// ---- 总排号 (下方) ----
Row(
children: [
const Text('总排号',
style: TextStyle(
fontSize: 14, fontWeight: FontWeight.w500)),
const Text(
'总排号',
style: TextStyle(
fontSize: 14,
fontWeight: FontWeight.w500,
),
),
if (_isLocked && _zongpaiNos.isNotEmpty) ...[
const SizedBox(width: 8),
Container(
padding: const EdgeInsets.symmetric(
horizontal: 6, vertical: 2),
horizontal: 6,
vertical: 2,
),
decoration: BoxDecoration(
color: Colors.blue.withValues(alpha: 0.15),
borderRadius: BorderRadius.circular(4),
@@ -415,14 +422,15 @@ class _RegistrationPageState extends State<RegistrationPage> {
width: double.infinity,
padding: const EdgeInsets.all(14),
decoration: BoxDecoration(
border: Border.all(
color: Colors.grey.shade400),
border: Border.all(color: Colors.grey.shade400),
borderRadius: BorderRadius.circular(8),
),
child: const Text(
'',
style: TextStyle(
fontSize: 20, color: Colors.grey),
fontSize: 20,
color: Colors.grey,
),
),
)
: ListView.separated(
@@ -431,36 +439,32 @@ class _RegistrationPageState extends State<RegistrationPage> {
const SizedBox(height: 6),
itemBuilder: (context, index) {
return Dismissible(
key: ValueKey(
'${_zongpaiNos[index]}-$index'),
direction:
DismissDirection.endToStart,
onDismissed: (_) =>
_removeZongpai(index),
key: ValueKey('${_zongpaiNos[index]}-$index'),
direction: DismissDirection.endToStart,
onDismissed: (_) => _removeZongpai(index),
background: Container(
alignment:
Alignment.centerRight,
padding: const EdgeInsets.only(
right: 16),
alignment: Alignment.centerRight,
padding: const EdgeInsets.only(right: 16),
decoration: BoxDecoration(
color: Colors.red.shade100,
borderRadius:
BorderRadius.circular(8),
borderRadius: BorderRadius.circular(8),
),
child: const Icon(
Icons.delete,
color: Colors.red,
),
child: const Icon(Icons.delete,
color: Colors.red),
),
child: Container(
padding:
const EdgeInsets.symmetric(
horizontal: 12,
vertical: 12),
padding: const EdgeInsets.symmetric(
horizontal: 12,
vertical: 12,
),
decoration: BoxDecoration(
border: Border.all(
color: Colors.green,
width: 2),
borderRadius:
BorderRadius.circular(8),
color: Colors.green,
width: 2,
),
borderRadius: BorderRadius.circular(8),
),
child: Row(
children: [
@@ -469,21 +473,20 @@ class _RegistrationPageState extends State<RegistrationPage> {
_zongpaiNos[index],
style: const TextStyle(
fontSize: 20,
fontWeight:
FontWeight.bold,
fontWeight: FontWeight.bold,
color: Colors.black87,
),
),
),
IconButton(
icon: const Icon(
Icons.close,
size: 20),
Icons.close,
size: 20,
),
onPressed: () =>
_removeZongpai(index),
padding: EdgeInsets.zero,
constraints:
const BoxConstraints(),
constraints: const BoxConstraints(),
),
],
),
@@ -497,7 +500,9 @@ class _RegistrationPageState extends State<RegistrationPage> {
Container(
width: double.infinity,
padding: const EdgeInsets.symmetric(
horizontal: 12, vertical: 14),
horizontal: 12,
vertical: 14,
),
decoration: BoxDecoration(
border: Border.all(
color: _zongpaiNos.isNotEmpty
@@ -575,8 +580,8 @@ class _RegistrationPageState extends State<RegistrationPage> {
color: _isSubmitting
? Colors.orange
: _successMessage != null
? Colors.green
: Colors.blue,
? Colors.green
: Colors.blue,
shape: BoxShape.circle,
),
),