fix: 修复 release 构建失败(theme 未定义 / _refreshBackground 残留)
This commit is contained in:
6 files changed
+48
-11
No files matched your search
@@ -122,6 +122,7 @@ class ZVManagerAppState extends State<ZVManagerApp> {
|
|||||||
builder: (context, child) {
|
builder: (context, child) {
|
||||||
child ??= const SizedBox.shrink();
|
child ??= const SizedBox.shrink();
|
||||||
return BackgroundWidget(
|
return BackgroundWidget(
|
||||||
|
key: backgroundWidgetKey,
|
||||||
child: Stack(
|
child: Stack(
|
||||||
children: [
|
children: [
|
||||||
child,
|
child,
|
||||||
|
|||||||
@@ -40,6 +40,14 @@ class _Layer {
|
|||||||
Future<void> dispose() async => video?.dispose();
|
Future<void> dispose() async => video?.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// 背景层全局 Key。
|
||||||
|
///
|
||||||
|
/// 背景层挂在 `MaterialApp.builder` 顶层(见 `app.dart`),普通页面通过
|
||||||
|
/// `context` 拿不到它的 State;这个 Key 提供了稳定的访问入口,例如设置页
|
||||||
|
/// 切换「视频声音」开关后立即调整当前视频的音量。
|
||||||
|
final GlobalKey<BackgroundWidgetState> backgroundWidgetKey =
|
||||||
|
GlobalKey<BackgroundWidgetState>();
|
||||||
|
|
||||||
/// 全局壁纸背景。
|
/// 全局壁纸背景。
|
||||||
///
|
///
|
||||||
/// 原实现切壁纸会闪屏,原因有三条,这里逐一解决:
|
/// 原实现切壁纸会闪屏,原因有三条,这里逐一解决:
|
||||||
@@ -87,6 +95,10 @@ class BackgroundWidgetState extends State<BackgroundWidget>
|
|||||||
super.initState();
|
super.initState();
|
||||||
WidgetsBinding.instance.addObserver(this);
|
WidgetsBinding.instance.addObserver(this);
|
||||||
|
|
||||||
|
// spec 是背景层的数据源:启动预加载完成、或设置页切换壁纸时,
|
||||||
|
// 都由 main.dart 写入新值,这里监听并交叉淡入到新图层。
|
||||||
|
BackgroundWidget.spec.addListener(_onSpecChanged);
|
||||||
|
|
||||||
// 关键:不能在这里同步调用 _apply()。
|
// 关键:不能在这里同步调用 _apply()。
|
||||||
// _buildLayer() 内部要用 precacheImage(provider, context),
|
// _buildLayer() 内部要用 precacheImage(provider, context),
|
||||||
// 而 initState 阶段 context 尚未挂载到渲染树,precacheImage 会抛异常,
|
// 而 initState 阶段 context 尚未挂载到渲染树,precacheImage 会抛异常,
|
||||||
@@ -114,6 +126,22 @@ class BackgroundWidgetState extends State<BackgroundWidget>
|
|||||||
/// 外部入口:按 `spec` 最新值切换壁纸。
|
/// 外部入口:按 `spec` 最新值切换壁纸。
|
||||||
void refreshBackground() => _apply(BackgroundWidget.spec.value, animate: true);
|
void refreshBackground() => _apply(BackgroundWidget.spec.value, animate: true);
|
||||||
|
|
||||||
|
void _onSpecChanged() {
|
||||||
|
if (!mounted) return;
|
||||||
|
refreshBackground();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 外部入口:视频声音开关变化后立即应用,无需重建图层。
|
||||||
|
void applyVideoSound(bool enabled) {
|
||||||
|
final volume = enabled ? 1.0 : 0.0;
|
||||||
|
for (final layer in [_active, _incoming]) {
|
||||||
|
final video = layer?.video;
|
||||||
|
if (video != null && video.value.isInitialized) {
|
||||||
|
video.setVolume(volume);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static String _keyOf(BackgroundSpec s) => s.isEmpty ? 'none' : '${s.type}:${s.path}';
|
static String _keyOf(BackgroundSpec s) => s.isEmpty ? 'none' : '${s.type}:${s.path}';
|
||||||
|
|
||||||
Future<_Layer?> _buildLayer(BackgroundSpec spec) async {
|
Future<_Layer?> _buildLayer(BackgroundSpec spec) async {
|
||||||
@@ -226,6 +254,7 @@ class BackgroundWidgetState extends State<BackgroundWidget>
|
|||||||
@override
|
@override
|
||||||
void dispose() {
|
void dispose() {
|
||||||
_requestSeq++; // 让在途请求失效
|
_requestSeq++; // 让在途请求失效
|
||||||
|
BackgroundWidget.spec.removeListener(_onSpecChanged);
|
||||||
WidgetsBinding.instance.removeObserver(this);
|
WidgetsBinding.instance.removeObserver(this);
|
||||||
_active?.dispose();
|
_active?.dispose();
|
||||||
_incoming?.dispose();
|
_incoming?.dispose();
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:shared_preferences/shared_preferences.dart';
|
|
||||||
|
|
||||||
class UserAgreementDialog extends StatefulWidget {
|
class UserAgreementDialog extends StatefulWidget {
|
||||||
final VoidCallback onAgree;
|
final VoidCallback onAgree;
|
||||||
@@ -15,8 +14,8 @@ class _UserAgreementDialogState extends State<UserAgreementDialog> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return WillPopScope(
|
return PopScope(
|
||||||
onWillPop: () async => false,
|
canPop: false,
|
||||||
child: Dialog(
|
child: Dialog(
|
||||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(20)),
|
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(20)),
|
||||||
insetPadding: const EdgeInsets.symmetric(horizontal: 20),
|
insetPadding: const EdgeInsets.symmetric(horizontal: 20),
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
import 'dart:ui' show FontFeature;
|
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
/// 服务器卡片的数据状态。
|
/// 服务器卡片的数据状态。
|
||||||
@@ -252,6 +250,7 @@ class ServerCard extends StatelessWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildMetrics(BuildContext context, ColorScheme scheme) {
|
Widget _buildMetrics(BuildContext context, ColorScheme scheme) {
|
||||||
|
final theme = Theme.of(context);
|
||||||
final online = state == ServerCardState.online;
|
final online = state == ServerCardState.online;
|
||||||
|
|
||||||
if (state == ServerCardState.loading) {
|
if (state == ServerCardState.loading) {
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import 'package:path_provider/path_provider.dart';
|
|||||||
import '../../core/theme/app_theme.dart';
|
import '../../core/theme/app_theme.dart';
|
||||||
import '../../core/utils/update_service.dart';
|
import '../../core/utils/update_service.dart';
|
||||||
import '../../core/utils/background_service.dart';
|
import '../../core/utils/background_service.dart';
|
||||||
|
import '../../core/widgets/background_widget.dart';
|
||||||
import '../../providers/theme_provider.dart';
|
import '../../providers/theme_provider.dart';
|
||||||
import '../../providers/wallpaper_provider.dart';
|
import '../../providers/wallpaper_provider.dart';
|
||||||
|
|
||||||
@@ -161,7 +162,7 @@ class _SettingsPageState extends State<SettingsPage> {
|
|||||||
|
|
||||||
return destPath;
|
return destPath;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
print('保存失败: $e');
|
debugPrint('保存失败: $e');
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
const SnackBar(content: Text('保存失败,请重试')),
|
const SnackBar(content: Text('保存失败,请重试')),
|
||||||
@@ -255,7 +256,8 @@ class _SettingsPageState extends State<SettingsPage> {
|
|||||||
onChanged: (value) async {
|
onChanged: (value) async {
|
||||||
await BackgroundService.setVideoSound(value);
|
await BackgroundService.setVideoSound(value);
|
||||||
setState(() => _videoSoundEnabled = value);
|
setState(() => _videoSoundEnabled = value);
|
||||||
_refreshBackground();
|
// 立即应用到正在播放的背景视频,无需重建图层
|
||||||
|
backgroundWidgetKey.currentState?.applyVideoSound(value);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -109,16 +109,23 @@ void main() {
|
|||||||
),
|
),
|
||||||
));
|
));
|
||||||
|
|
||||||
|
// 在线态的状态圆点是无限循环动画,pumpAndSettle 永远不会结束。
|
||||||
|
// 这里改为推进固定时长,足够让弹出菜单的开/关动画走完。
|
||||||
|
Future<void> settleMenu() async {
|
||||||
|
await tester.pump();
|
||||||
|
await tester.pump(const Duration(milliseconds: 500));
|
||||||
|
}
|
||||||
|
|
||||||
await tester.tap(find.byIcon(Icons.more_vert));
|
await tester.tap(find.byIcon(Icons.more_vert));
|
||||||
await tester.pumpAndSettle();
|
await settleMenu();
|
||||||
await tester.tap(find.text('编辑'));
|
await tester.tap(find.text('编辑'));
|
||||||
await tester.pumpAndSettle();
|
await settleMenu();
|
||||||
expect(edited, isTrue);
|
expect(edited, isTrue);
|
||||||
|
|
||||||
await tester.tap(find.byIcon(Icons.more_vert));
|
await tester.tap(find.byIcon(Icons.more_vert));
|
||||||
await tester.pumpAndSettle();
|
await settleMenu();
|
||||||
await tester.tap(find.text('删除'));
|
await tester.tap(find.text('删除'));
|
||||||
await tester.pumpAndSettle();
|
await settleMenu();
|
||||||
expect(deleted, isTrue);
|
expect(deleted, isTrue);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user