新增用户须知,更新依赖
This commit is contained in:
13 files changed
+592
-235
No files matched your search
+43
-1
@@ -3,9 +3,11 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter_localizations/flutter_localizations.dart';
|
||||
import 'package:package_info_plus/package_info_plus.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'core/theme/app_theme.dart';
|
||||
import 'core/utils/update_service.dart';
|
||||
import 'core/widgets/background_widget.dart';
|
||||
import 'core/widgets/user_agreement_dialog.dart'; // 新增
|
||||
import 'features/server_list/server_list_page.dart';
|
||||
import 'providers/theme_provider.dart';
|
||||
import 'providers/server_provider.dart';
|
||||
@@ -23,9 +25,35 @@ class ZVManagerApp extends StatefulWidget {
|
||||
class ZVManagerAppState extends State<ZVManagerApp> {
|
||||
final GlobalKey<BackgroundWidgetState> _bgKey = GlobalKey();
|
||||
|
||||
bool _showAgreement = false;
|
||||
bool _isReady = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_checkAgreement();
|
||||
}
|
||||
|
||||
// 新增:检查是否已同意用户守则
|
||||
Future<void> _checkAgreement() async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
final agreed = prefs.getBool('user_agreed') ?? false;
|
||||
setState(() {
|
||||
_showAgreement = !agreed;
|
||||
_isReady = true;
|
||||
});
|
||||
if (agreed) {
|
||||
_checkUpdateSilently();
|
||||
}
|
||||
}
|
||||
|
||||
// 新增:同意后保存并进入
|
||||
Future<void> _onAgree() async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
await prefs.setBool('user_agreed', true);
|
||||
setState(() {
|
||||
_showAgreement = false;
|
||||
});
|
||||
_checkUpdateSilently();
|
||||
}
|
||||
|
||||
@@ -81,7 +109,21 @@ class ZVManagerAppState extends State<ZVManagerApp> {
|
||||
builder: (context, child) {
|
||||
return BackgroundWidget(
|
||||
key: _bgKey,
|
||||
child: child!,
|
||||
child: Stack(
|
||||
children: [
|
||||
child!,
|
||||
// 新增:用户守则弹窗
|
||||
if (_isReady && _showAgreement)
|
||||
Positioned.fill(
|
||||
child: Container(
|
||||
color: Colors.black.withOpacity(0.6),
|
||||
child: Center(
|
||||
child: UserAgreementDialog(onAgree: _onAgree),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
@@ -12,27 +12,44 @@ class BackgroundWidget extends StatefulWidget {
|
||||
State<BackgroundWidget> createState() => BackgroundWidgetState();
|
||||
}
|
||||
|
||||
// 导出 State 供外部调用
|
||||
class BackgroundWidgetState extends State<BackgroundWidget> {
|
||||
class BackgroundWidgetState extends State<BackgroundWidget>
|
||||
with WidgetsBindingObserver {
|
||||
VideoPlayerController? _controller;
|
||||
FileImage? _cachedImage;
|
||||
String? _currentType;
|
||||
String? _currentPath;
|
||||
bool _isLoading = true;
|
||||
bool _isInForeground = true;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
WidgetsBinding.instance.addObserver(this);
|
||||
_loadBackground();
|
||||
}
|
||||
|
||||
@override
|
||||
void didChangeAppLifecycleState(AppLifecycleState state) {
|
||||
// 后台时暂停视频,省电 + 减少卡顿
|
||||
if (state == AppLifecycleState.paused) {
|
||||
_isInForeground = false;
|
||||
_controller?.pause();
|
||||
} else if (state == AppLifecycleState.resumed) {
|
||||
_isInForeground = true;
|
||||
if (_controller != null && _controller!.value.isInitialized) {
|
||||
_controller!.play();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _loadBackground() async {
|
||||
final data = await BackgroundService.getBackground();
|
||||
final type = data['type'];
|
||||
final path = data['path'];
|
||||
|
||||
// 如果没变化就不重新加载
|
||||
// 路径没变,不重新加载
|
||||
if (_currentType == type && _currentPath == path && _controller != null) {
|
||||
setState(() => _isLoading = false);
|
||||
if (mounted) setState(() => _isLoading = false);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -44,78 +61,113 @@ class BackgroundWidgetState extends State<BackgroundWidget> {
|
||||
|
||||
_currentType = type;
|
||||
_currentPath = path;
|
||||
_cachedImage = null;
|
||||
|
||||
// ===== 视频背景 =====
|
||||
if (type == 'video' && path != null) {
|
||||
try {
|
||||
final file = File(path);
|
||||
if (!file.existsSync()) {
|
||||
if (mounted) setState(() => _isLoading = false);
|
||||
return;
|
||||
}
|
||||
|
||||
final videoSound = await BackgroundService.getVideoSound();
|
||||
final controller = VideoPlayerController.file(File(path));
|
||||
await controller.initialize();
|
||||
final controller = VideoPlayerController.file(file);
|
||||
|
||||
// 超时保护,避免卡住
|
||||
await controller.initialize().timeout(
|
||||
const Duration(seconds: 10),
|
||||
onTimeout: () {
|
||||
throw Exception('视频初始化超时');
|
||||
},
|
||||
);
|
||||
|
||||
controller.setLooping(true);
|
||||
controller.setVolume(videoSound ? 1.0 : 0.0);
|
||||
controller.play();
|
||||
setState(() {
|
||||
_controller = controller;
|
||||
_isLoading = false;
|
||||
});
|
||||
if (_isInForeground) controller.play();
|
||||
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
_controller = controller;
|
||||
_isLoading = false;
|
||||
});
|
||||
}
|
||||
return;
|
||||
} catch (e) {
|
||||
print('视频加载失败: $e');
|
||||
debugPrint('视频加载失败: $e');
|
||||
}
|
||||
}
|
||||
|
||||
setState(() => _isLoading = false);
|
||||
// ===== 图片背景 =====
|
||||
if (type == 'image' && path != null) {
|
||||
final file = File(path);
|
||||
if (file.existsSync()) {
|
||||
_cachedImage = FileImage(file);
|
||||
}
|
||||
}
|
||||
|
||||
if (mounted) setState(() => _isLoading = false);
|
||||
}
|
||||
|
||||
// 供外部调用的刷新方法
|
||||
/// 供外部调用刷新壁纸
|
||||
void refreshBackground() {
|
||||
_loadBackground();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
WidgetsBinding.instance.removeObserver(this);
|
||||
_controller?.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (_isLoading) {
|
||||
return widget.child;
|
||||
}
|
||||
// 还在加载,直接显示子组件
|
||||
if (_isLoading) return widget.child;
|
||||
|
||||
// 有视频背景
|
||||
// ===== 视频背景 =====
|
||||
if (_controller != null && _controller!.value.isInitialized) {
|
||||
return Stack(
|
||||
fit: StackFit.expand,
|
||||
children: [
|
||||
SizedBox.expand(
|
||||
child: FittedBox(
|
||||
fit: BoxFit.cover,
|
||||
child: SizedBox(
|
||||
width: _controller!.value.size.width,
|
||||
height: _controller!.value.size.height,
|
||||
child: VideoPlayer(_controller!),
|
||||
return RepaintBoundary(
|
||||
child: Stack(
|
||||
fit: StackFit.expand,
|
||||
children: [
|
||||
SizedBox.expand(
|
||||
child: FittedBox(
|
||||
fit: BoxFit.cover,
|
||||
child: SizedBox(
|
||||
width: _controller!.value.size.width,
|
||||
height: _controller!.value.size.height,
|
||||
child: VideoPlayer(_controller!),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
Container(color: Colors.black.withOpacity(0.3)),
|
||||
_wrapWithTransparentTheme(widget.child),
|
||||
],
|
||||
Container(color: Colors.black.withOpacity(0.3)),
|
||||
_wrapWithTransparentTheme(widget.child),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// 有图片背景
|
||||
if (_currentType == 'image' && _currentPath != null) {
|
||||
return Stack(
|
||||
fit: StackFit.expand,
|
||||
children: [
|
||||
Image.file(File(_currentPath!), fit: BoxFit.cover),
|
||||
_wrapWithTransparentTheme(widget.child),
|
||||
],
|
||||
// ===== 图片背景 =====
|
||||
if (_cachedImage != null) {
|
||||
return RepaintBoundary(
|
||||
child: Stack(
|
||||
fit: StackFit.expand,
|
||||
children: [
|
||||
Image(
|
||||
image: _cachedImage!,
|
||||
fit: BoxFit.cover,
|
||||
gaplessPlayback: true, // 避免切换时闪白
|
||||
),
|
||||
_wrapWithTransparentTheme(widget.child),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// 无背景
|
||||
// ===== 无背景 =====
|
||||
return widget.child;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,188 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
class UserAgreementDialog extends StatefulWidget {
|
||||
final VoidCallback onAgree;
|
||||
|
||||
const UserAgreementDialog({super.key, required this.onAgree});
|
||||
|
||||
@override
|
||||
State<UserAgreementDialog> createState() => _UserAgreementDialogState();
|
||||
}
|
||||
|
||||
class _UserAgreementDialogState extends State<UserAgreementDialog> {
|
||||
bool _isChecked = false;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return WillPopScope(
|
||||
onWillPop: () async => false,
|
||||
child: Dialog(
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(20)),
|
||||
insetPadding: const EdgeInsets.symmetric(horizontal: 20),
|
||||
child: Container(
|
||||
width: double.infinity,
|
||||
padding: const EdgeInsets.all(24),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
// 图标
|
||||
const Text('📜', style: TextStyle(fontSize: 48)),
|
||||
const SizedBox(height: 12),
|
||||
|
||||
// 标题
|
||||
const Text(
|
||||
'用户守则',
|
||||
style: TextStyle(
|
||||
fontSize: 22,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Color(0xFF1A1A2E),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
|
||||
// 内容
|
||||
Container(
|
||||
height: 260,
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0xFFF8F9FA),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
border: Border.all(color: const Color(0xFFE0E0E0)),
|
||||
),
|
||||
child: const SingleChildScrollView(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
_SectionTitle('一、总则'),
|
||||
_SectionText('欢迎使用 ZV Manager。本守则旨在规范用户行为,保障服务器与用户权益。使用本软件即表示你已阅读并同意本守则。'),
|
||||
|
||||
_SectionTitle('二、使用规范'),
|
||||
_SectionText('1. 本软件仅供 Minecraft 服务器管理使用,不得用于任何违法用途。'),
|
||||
_SectionText('2. 不得利用本软件对他人服务器进行未经授权的访问或攻击。'),
|
||||
_SectionText('3. 不得利用本软件传播违法信息或进行任何破坏行为。'),
|
||||
|
||||
_SectionTitle('三、账号与安全'),
|
||||
_SectionText('1. 请妥善保管你的 RCON 密码,因密码泄露造成的损失由用户自行承担。'),
|
||||
_SectionText('2. 本软件采用加密方式存储密码,但不对因设备丢失导致的信息泄露负责。'),
|
||||
|
||||
_SectionTitle('四、免责声明'),
|
||||
_SectionText('1. 本软件为社区开源项目,并非 Mojang Studios 或 Microsoft 官方产品。'),
|
||||
_SectionText('2. 使用本软件产生的任何后果由用户自行承担。'),
|
||||
_SectionText('3. 开发者保留随时修改本守则的权利。'),
|
||||
|
||||
_SectionTitle('五、其他'),
|
||||
_SectionText('本守则最终解释权归 ZV Team 所有。如有疑问,请联系开发者。'),
|
||||
|
||||
SizedBox(height: 16),
|
||||
Text(
|
||||
'© 2026 ZV Team · 与 Mojang 无关',
|
||||
style: TextStyle(fontSize: 12, color: Color(0xFF999999)),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
|
||||
// 同意勾选
|
||||
GestureDetector(
|
||||
onTap: () {
|
||||
setState(() {
|
||||
_isChecked = !_isChecked;
|
||||
});
|
||||
},
|
||||
child: Row(
|
||||
children: [
|
||||
SizedBox(
|
||||
width: 24,
|
||||
height: 24,
|
||||
child: Checkbox(
|
||||
value: _isChecked,
|
||||
onChanged: (value) {
|
||||
setState(() {
|
||||
_isChecked = value ?? false;
|
||||
});
|
||||
},
|
||||
activeColor: const Color(0xFF28A745),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
const Text(
|
||||
'我已阅读并同意《用户守则》',
|
||||
style: TextStyle(fontSize: 14, color: Color(0xFF555555)),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
|
||||
// 按钮
|
||||
SizedBox(
|
||||
width: double.infinity,
|
||||
child: FilledButton(
|
||||
onPressed: _isChecked ? widget.onAgree : null,
|
||||
style: FilledButton.styleFrom(
|
||||
backgroundColor: const Color(0xFF28A745),
|
||||
disabledBackgroundColor: const Color(0xFFCCCCCC),
|
||||
padding: const EdgeInsets.symmetric(vertical: 14),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
),
|
||||
child: const Text(
|
||||
'同意并进入',
|
||||
style: TextStyle(fontSize: 16, fontWeight: FontWeight.w600),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _SectionTitle extends StatelessWidget {
|
||||
final String text;
|
||||
const _SectionTitle(this.text);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(top: 12, bottom: 4),
|
||||
child: Text(
|
||||
text,
|
||||
style: const TextStyle(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Color(0xFF1A1A2E),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _SectionText extends StatelessWidget {
|
||||
final String text;
|
||||
const _SectionText(this.text);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(bottom: 4),
|
||||
child: Text(
|
||||
text,
|
||||
style: const TextStyle(
|
||||
fontSize: 13,
|
||||
color: Color(0xFF666666),
|
||||
height: 1.6,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -130,13 +130,10 @@ class _SettingsPageState extends State<SettingsPage> {
|
||||
}
|
||||
|
||||
Future<void> _pickVideo() async {
|
||||
final result = await FilePicker.pickFiles(
|
||||
type: FileType.video,
|
||||
allowMultiple: false,
|
||||
);
|
||||
if (result.isEmpty) return;
|
||||
final result = await FilePicker.pickFile(type: FileType.video);
|
||||
if (result == null) return;
|
||||
|
||||
final filePath = result.single.path;
|
||||
final filePath = result.path;
|
||||
if (filePath == null) return;
|
||||
|
||||
final path = await _saveFileToAssets(filePath, 'video');
|
||||
|
||||
Reference in new issue
Block a user