hi-client/lib/app/widgets/dialogs/kr_dialog.dart
Rust 0ec2f72a93 彻底解决在安卓15部分机型出现界面不兼容等问题
(cherry picked from commit fc31fc6e5ee3a7aefa8928bb40d164282e4edf90)
2025-11-02 02:48:03 -08:00

231 lines
7.5 KiB
Dart
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:kaer_with_panels/app/localization/app_translations.dart';
import 'dart:io';
import 'package:path_provider/path_provider.dart';
class KRDialog extends StatelessWidget {
final String? title;
final String? message;
final String? confirmText;
final String? cancelText;
final VoidCallback? onConfirm;
final VoidCallback? onCancel;
final Widget? icon;
final Widget? customMessageWidget;
const KRDialog({
Key? key,
this.title,
this.message,
this.confirmText,
this.cancelText,
this.onConfirm,
this.onCancel,
this.icon,
this.customMessageWidget,
}) : super(key: key);
static Future<void> show({
String? title,
String? message,
String? confirmText,
String? cancelText,
VoidCallback? onConfirm,
VoidCallback? onCancel,
Widget? icon,
Widget? customMessageWidget,
}) {
// 🔧 Android 15 诊断:记录对话框显示事件
print('📢 [KRDialog] ========== KRDialog.show() 被调用 ==========');
print('📢 [KRDialog] 标题: $title');
print('📢 [KRDialog] 消息: $message');
print('📢 [KRDialog] 当前时间: ${DateTime.now()}');
Future(() async {
try {
final dir = await getApplicationDocumentsDirectory();
final debugFile = File('${dir.path}/DIALOG_DEBUG.txt');
await debugFile.writeAsString(
'=' * 60 + '\n'
'📢 KRDialog.show() 被调用!\n'
'时间: ${DateTime.now()}\n'
'标题: $title\n'
'消息: $message\n'
'版本标识: Android15_Fix_v7_DialogFixed\n'
'=' * 60 + '\n',
mode: FileMode.append,
);
} catch (e) {
print('📢 [KRDialog] ❌ 写入对话框日志失败: $e');
}
});
return Get.dialog(
KRDialog(
title: title,
message: message,
confirmText: confirmText,
cancelText: cancelText,
onConfirm: onConfirm,
onCancel: onCancel,
icon: icon,
customMessageWidget: customMessageWidget,
),
barrierDismissible: false,
);
}
Widget _buildConfirmButton() {
// 🔧 Android 15 关键修复:完全移除 ScreenUtil使用固定像素值
return Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(23),
boxShadow: [
BoxShadow(
color: const Color(0xFF1797FF).withOpacity(0.25),
blurRadius: 8,
offset: const Offset(0, 2),
),
],
),
child: TextButton(
onPressed: () {
print('📢 [KRDialog] 确认按钮被点击');
Get.back();
onConfirm?.call();
},
style: TextButton.styleFrom(
backgroundColor: const Color(0xFF1797FF),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(23),
),
padding: EdgeInsets.zero,
minimumSize: const Size.fromHeight(46),
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
),
child: Text(
confirmText ?? AppTranslations.kr_dialog.kr_confirm,
style: const TextStyle(
fontSize: 15,
fontWeight: FontWeight.w500,
color: Colors.white,
fontFamily: 'AlibabaPuHuiTi-Medium',
),
),
),
);
}
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
final isDark = theme.brightness == Brightness.dark;
print('📢 [KRDialog] 开始构建对话框 Widget');
print('📢 [KRDialog] 标题: $title');
print('📢 [KRDialog] 主题模式: ${isDark ? "暗色" : "亮色"}');
// 🔧 Android 15 关键修复:完全移除 ScreenUtil使用固定像素值
return Dialog(
backgroundColor: theme.cardColor,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
),
child: Container(
width: 280,
padding: const EdgeInsets.all(24),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
if (icon != null) ...[
icon!,
const SizedBox(height: 20),
],
if (title != null) ...[
Text(
title!,
style: TextStyle(
fontSize: 17,
fontWeight: FontWeight.w600,
color: isDark ? Colors.white : const Color(0xFF333333),
fontFamily: 'AlibabaPuHuiTi-Medium',
height: 1.3,
),
textAlign: TextAlign.center,
),
const SizedBox(height: 12),
],
if (message != null || customMessageWidget != null) ...[
Container(
constraints: const BoxConstraints(maxHeight: 200),
child: SingleChildScrollView(
child: customMessageWidget ?? Text(
message!,
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 14,
color: isDark ? const Color(0xFFCCCCCC) : const Color(0xFF666666),
fontFamily: 'AlibabaPuHuiTi-Regular',
height: 1.4,
),
),
),
),
const SizedBox(height: 28),
],
if (cancelText != null) ...[
Row(
children: [
Expanded(
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(23),
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.03),
blurRadius: 4,
offset: const Offset(0, 2),
),
],
),
child: TextButton(
onPressed: () {
print('📢 [KRDialog] 取消按钮被点击');
Get.back();
onCancel?.call();
},
style: TextButton.styleFrom(
backgroundColor: isDark ? const Color(0xFF222222) : const Color(0xFFEEEEEE),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(23),
),
padding: EdgeInsets.zero,
minimumSize: const Size.fromHeight(46),
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
),
child: Text(
cancelText ?? AppTranslations.kr_dialog.kr_cancel,
style: TextStyle(
fontSize: 15,
fontWeight: FontWeight.w500,
color: isDark ? const Color(0xFFBBBBBB) : const Color(0xFF666666),
fontFamily: 'AlibabaPuHuiTi-Medium',
),
),
),
),
),
const SizedBox(width: 12),
Expanded(child: _buildConfirmButton()),
],
),
] else ...[
_buildConfirmButton(),
],
],
),
),
);
}
}