From e868493bb69ad1a5c9fc12cd7b4bdea73908cb18 Mon Sep 17 00:00:00 2001 From: ZV Dev Date: Fri, 23 Oct 2026 19:41:57 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E7=94=A8=E6=88=B7=E5=AE=88=E5=88=99?= =?UTF-8?q?=E5=BC=BA=E5=88=B6=E9=98=85=E8=AF=BB=EF=BC=8810=E7=A7=92?= =?UTF-8?q?=E5=80=92=E8=AE=A1=E6=97=B6+=E6=BB=9A=E5=8A=A8=E5=88=B0?= =?UTF-8?q?=E5=BA=95=E6=89=8D=E5=8F=AF=E5=8B=BE=E9=80=89=E5=90=8C=E6=84=8F?= =?UTF-8?q?=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/core/widgets/user_agreement_dialog.dart | 88 ++++++++++++++++----- 1 file changed, 69 insertions(+), 19 deletions(-) diff --git a/lib/core/widgets/user_agreement_dialog.dart b/lib/core/widgets/user_agreement_dialog.dart index 81b3203..6bbccd4 100644 --- a/lib/core/widgets/user_agreement_dialog.dart +++ b/lib/core/widgets/user_agreement_dialog.dart @@ -1,3 +1,4 @@ +import 'dart:async'; import 'package:flutter/material.dart'; class UserAgreementDialog extends StatefulWidget { @@ -12,6 +13,48 @@ class UserAgreementDialog extends StatefulWidget { class _UserAgreementDialogState extends State { bool _isChecked = false; + /// 强制阅读:倒计时 10 秒 + 滚动到底,两者都满足才能勾选同意。 + static const int _readSeconds = 10; + int _countdown = _readSeconds; + bool _readToEnd = false; + Timer? _timer; + final _scrollController = ScrollController(); + + @override + void initState() { + super.initState(); + _timer = Timer.periodic(const Duration(seconds: 1), (t) { + if (!mounted) return t.cancel(); + setState(() => _countdown--); + if (_countdown <= 0) t.cancel(); + }); + _scrollController.addListener(_onScroll); + } + + @override + void dispose() { + _timer?.cancel(); + _scrollController.removeListener(_onScroll); + _scrollController.dispose(); + super.dispose(); + } + + void _onScroll() { + if (_readToEnd) return; + final c = _scrollController; + if (c.position.maxScrollExtent <= 0 || c.offset >= c.position.maxScrollExtent - 8) { + setState(() => _readToEnd = true); + } + } + + bool get _canAgree => _isChecked && _countdown <= 0 && _readToEnd; + + String get _buttonLabel { + if (_countdown > 0) return '请仔细阅读守则(${_countdown}s)'; + if (!_readToEnd) return '请阅读至守则底部'; + return '同意并进入'; + } + @override Widget build(BuildContext context) { return PopScope( @@ -49,7 +92,8 @@ class _UserAgreementDialogState extends State { borderRadius: BorderRadius.circular(12), border: Border.all(color: const Color(0xFFE0E0E0)), ), - child: const SingleChildScrollView( + child: SingleChildScrollView( + controller: _scrollController, child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ @@ -107,13 +151,15 @@ class _UserAgreementDialogState extends State { ), const SizedBox(height: 16), - // 同意勾选 + // 同意勾选(倒计时结束且阅读到底后才可勾选) GestureDetector( - onTap: () { - setState(() { - _isChecked = !_isChecked; - }); - }, + onTap: _countdown <= 0 && _readToEnd + ? () { + setState(() { + _isChecked = !_isChecked; + }); + } + : null, child: Row( children: [ SizedBox( @@ -121,11 +167,13 @@ class _UserAgreementDialogState extends State { height: 24, child: Checkbox( value: _isChecked, - onChanged: (value) { - setState(() { - _isChecked = value ?? false; - }); - }, + onChanged: (_countdown <= 0 && _readToEnd) + ? (value) { + setState(() { + _isChecked = value ?? false; + }); + } + : null, activeColor: const Color(0xFF28A745), shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(4), @@ -133,9 +181,11 @@ class _UserAgreementDialogState extends State { ), ), const SizedBox(width: 8), - const Text( - '我已阅读并同意《用户守则》', - style: TextStyle(fontSize: 14, color: Color(0xFF555555)), + Text( + _countdown > 0 + ? '阅读倒计时 $_countdown 秒…' + : (_readToEnd ? '我已阅读并同意《用户守则》' : '请先滑动阅读至守则底部'), + style: const TextStyle(fontSize: 14, color: Color(0xFF555555)), ), ], ), @@ -146,7 +196,7 @@ class _UserAgreementDialogState extends State { SizedBox( width: double.infinity, child: FilledButton( - onPressed: _isChecked ? widget.onAgree : null, + onPressed: _canAgree ? widget.onAgree : null, style: FilledButton.styleFrom( backgroundColor: const Color(0xFF28A745), disabledBackgroundColor: const Color(0xFFCCCCCC), @@ -155,9 +205,9 @@ class _UserAgreementDialogState extends State { borderRadius: BorderRadius.circular(12), ), ), - child: const Text( - '同意并进入', - style: TextStyle(fontSize: 16, fontWeight: FontWeight.w600), + child: Text( + _buttonLabel, + style: const TextStyle(fontSize: 16, fontWeight: FontWeight.w600), ), ), ),