7 changed files with 207 additions and 4 deletions
@ -0,0 +1,155 @@ |
|||
import 'package:flutter/material.dart'; |
|||
import 'package:flutter_screenutil/flutter_screenutil.dart'; |
|||
import 'package:get/get.dart'; |
|||
import '../webview_page.dart'; |
|||
import '../../../core/utils/doc_url_helper.dart'; |
|||
|
|||
/// 会员服务协议确认弹窗 |
|||
/// 在用户进入支付(充值/购买会员)前必须显式同意 |
|||
class MemberServiceAgreementDialog extends StatelessWidget { |
|||
final VoidCallback? onAccept; // 同意回调 |
|||
final VoidCallback? onReject; // 拒绝回调 |
|||
final bool canDismiss; // 是否可通过返回键关闭 |
|||
|
|||
const MemberServiceAgreementDialog({ |
|||
super.key, |
|||
this.onAccept, |
|||
this.onReject, |
|||
this.canDismiss = true, |
|||
}); |
|||
|
|||
/// 显示会员服务协议弹窗,返回值为 true 表示同意,false / null 表示拒绝或取消 |
|||
static Future<bool> show({bool canDismiss = true}) async { |
|||
final result = await Get.dialog<bool>( |
|||
MemberServiceAgreementDialog( |
|||
canDismiss: canDismiss, |
|||
onAccept: () => Get.back(result: true), |
|||
onReject: () => Get.back(result: false), |
|||
), |
|||
barrierDismissible: canDismiss, |
|||
); |
|||
return result == true; |
|||
} |
|||
|
|||
@override |
|||
Widget build(BuildContext context) { |
|||
final bool isDarkMode = Get.theme.brightness == Brightness.dark; |
|||
|
|||
return PopScope( |
|||
canPop: canDismiss, |
|||
child: Dialog( |
|||
shape: RoundedRectangleBorder( |
|||
borderRadius: BorderRadius.circular(16.r), |
|||
), |
|||
backgroundColor: isDarkMode ? Colors.grey[800] : Colors.white, |
|||
child: Container( |
|||
padding: EdgeInsets.all(20.w), |
|||
child: Column( |
|||
mainAxisSize: MainAxisSize.min, |
|||
children: [ |
|||
Text( |
|||
'memberServiceAgreementTitle'.tr, // 会员服务协议 |
|||
style: TextStyle( |
|||
fontSize: 18.sp, |
|||
fontWeight: FontWeight.bold, |
|||
color: isDarkMode ? Colors.white : Colors.black, |
|||
), |
|||
), |
|||
SizedBox(height: 16.h), |
|||
Padding( |
|||
padding: EdgeInsets.symmetric(horizontal: 20.w), |
|||
child: Text.rich( |
|||
TextSpan( |
|||
children: [ |
|||
TextSpan( |
|||
text: 'memberServiceAgreementIntro'.tr, |
|||
style: TextStyle( |
|||
fontSize: 14.sp, |
|||
color: isDarkMode |
|||
? Colors.white70 |
|||
: Colors.black87, |
|||
), |
|||
), |
|||
WidgetSpan( |
|||
alignment: PlaceholderAlignment.middle, |
|||
child: GestureDetector( |
|||
onTap: () { |
|||
Get.to(() => WebViewPage( |
|||
url: memberServiceAgreementUrl(), |
|||
title: 'memberServiceAgreement'.tr, |
|||
)); |
|||
}, |
|||
child: Text( |
|||
'memberServiceAgreement'.tr, // 《会员服务协议》 |
|||
style: TextStyle( |
|||
fontSize: 14.sp, |
|||
color: const Color(0xFF3B82F6), |
|||
), |
|||
), |
|||
), |
|||
), |
|||
TextSpan( |
|||
text: 'memberServiceAgreementOutro'.tr, |
|||
style: TextStyle( |
|||
fontSize: 14.sp, |
|||
color: isDarkMode ? Colors.white70 : Colors.black87, |
|||
), |
|||
), |
|||
], |
|||
), |
|||
textAlign: TextAlign.center, |
|||
), |
|||
), |
|||
SizedBox(height: 20.h), |
|||
Row( |
|||
mainAxisAlignment: MainAxisAlignment.spaceEvenly, |
|||
children: [ |
|||
TextButton( |
|||
onPressed: () { |
|||
if (onReject != null) { |
|||
onReject!(); |
|||
} else { |
|||
Get.back(result: false); |
|||
} |
|||
}, |
|||
style: TextButton.styleFrom( |
|||
foregroundColor: isDarkMode |
|||
? Colors.grey[400] |
|||
: Colors.black54, |
|||
), |
|||
child: Text( |
|||
'disagree'.tr, // 不同意 |
|||
style: TextStyle( |
|||
color: isDarkMode ? Colors.grey[400] : Colors.black54, |
|||
), |
|||
), |
|||
), |
|||
ElevatedButton( |
|||
onPressed: () { |
|||
if (onAccept != null) { |
|||
onAccept!(); |
|||
} else { |
|||
Get.back(result: true); |
|||
} |
|||
}, |
|||
style: ElevatedButton.styleFrom( |
|||
backgroundColor: const Color(0xFF0066CC), |
|||
foregroundColor: Colors.white, |
|||
shape: RoundedRectangleBorder( |
|||
borderRadius: BorderRadius.circular(8.r), |
|||
), |
|||
elevation: isDarkMode ? 4 : 2, |
|||
padding: EdgeInsets.symmetric( |
|||
horizontal: 16.w, vertical: 10.h), |
|||
), |
|||
child: Text('agreeAndContinue'.tr), // 同意并继续 |
|||
), |
|||
], |
|||
), |
|||
], |
|||
), |
|||
), |
|||
), |
|||
); |
|||
} |
|||
} |
|||
Loading…
Reference in new issue