绑定设备+覆盖模式+控制显示bug+在线更新

This commit is contained in:
2026-09-01 08:59:20 +08:00
parent 0fa67a127b
commit 61bce2c1cf
49 changed files with 2424 additions and 720 deletions

View File

@@ -1,4 +1,5 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:get_it/get_it.dart';
import 'package:go_router/go_router.dart';
@@ -10,6 +11,8 @@ import 'package:maibu_satabot_v2/core/storage/user_storage.dart';
import 'package:maibu_satabot_v2/features/auth/presentation/bloc/auth_cubit.dart';
import 'package:maibu_satabot_v2/features/main_container/presentation/cubit/tab_config_cubit.dart';
import 'package:maibu_satabot_v2/features/v2/device_list/presentation/float_bar/cubit/float_bar_setting_cubit.dart';
import 'package:maibu_satabot_v2/core/update/update_cubit.dart';
import 'package:maibu_satabot_v2/core/update/update_state.dart';
/// 系统设置综合页面
class SystemSettingsPage extends StatefulWidget {
@@ -20,6 +23,25 @@ class SystemSettingsPage extends StatefulWidget {
}
class _SystemSettingsPageState extends State<SystemSettingsPage> {
String _currentVersion = '';
int _currentVersionCode = 0;
@override
void initState() {
super.initState();
_loadVersion();
}
Future<void> _loadVersion() async {
try {
final String versionString = await rootBundle.loadString('pubspec.yaml');
final versionMatch = RegExp(r'version:\s*(\d+\.\d+\.\d+)\+(\d+)').firstMatch(versionString);
setState(() {
_currentVersion = versionMatch?.group(1) ?? '1.0.0';
_currentVersionCode = int.tryParse(versionMatch?.group(2) ?? '1') ?? 1;
});
} catch (_) {}
}
@override
Widget build(BuildContext context) {
return Scaffold(
@@ -52,6 +74,9 @@ class _SystemSettingsPageState extends State<SystemSettingsPage> {
// 语言设置
_buildLanguageSection(),
const SizedBox(height: 12),
// 版本更新
_buildUpdateSection(),
const SizedBox(height: 12),
// 退出登录
_buildLogoutButton(context),
const SizedBox(height: 20),
@@ -297,6 +322,105 @@ class _SystemSettingsPageState extends State<SystemSettingsPage> {
);
}
/// 版本更新
Widget _buildUpdateSection() {
return Container(
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
color: context.appColors.cardBackground,
borderRadius: BorderRadius.circular(12),
boxShadow: [
BoxShadow(
color: context.appColors.cardShadow,
blurRadius: 8,
offset: Offset(0, 2),
),
],
),
child: BlocConsumer<UpdateCubit, UpdateState>(
listener: (context, state) {
if (state is UpdateUpToDate) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: const Text('当前已是最新版本'),
backgroundColor: context.appColors.success,
duration: const Duration(seconds: 2),
),
);
}
},
builder: (context, state) {
final isChecking = state is UpdateChecking;
return Row(
children: [
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'版本更新',
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold,
color: context.appColors.textPrimary,
),
),
const SizedBox(height: 4),
Text(
'当前版本: $_currentVersion ($_currentVersionCode)',
style: TextStyle(
fontSize: 13,
color: context.appColors.textTertiary,
),
),
const SizedBox(height: 2),
Text(
isChecking ? '正在检查更新...' : '点击检查是否有新版本',
style: TextStyle(
fontSize: 13,
color: context.appColors.textTertiary,
),
),
],
),
),
if (isChecking)
const SizedBox(
width: 24,
height: 24,
child: CircularProgressIndicator(strokeWidth: 2),
)
else
GestureDetector(
onTap: () {
context.read<UpdateCubit>().checkUpdate();
},
child: Container(
padding: const EdgeInsets.symmetric(
horizontal: 16,
vertical: 8,
),
decoration: BoxDecoration(
color: const Color(0xFF165DFF),
borderRadius: BorderRadius.circular(8),
),
child: const Text(
'检查更新',
style: TextStyle(
fontSize: 14,
color: Colors.white,
fontWeight: FontWeight.w500,
),
),
),
),
],
);
},
),
);
}
/// 退出登录按钮
Widget _buildLogoutButton(BuildContext context) {
return GestureDetector(