修复ScreenUtil 在某些安卓设备上计算异常,导致所有使用 .w 和 .h 的尺寸都变成 0 或极小值,导致界面不显示

(cherry picked from commit 73af298aebafc2e13668d645d461b99786b0c1e2)
This commit is contained in:
2025-11-02 15:54:48 +08:00
committed by speakeloudest
parent 17b3f6b92d
commit 75c7d31da1
6 changed files with 120 additions and 108 deletions
@@ -29,47 +29,45 @@ class KRSubscriptionCard extends StatelessWidget {
print('🎴 [SubscriptionCard] 卡片颜色: ${Theme.of(context).cardColor}');
print('🎴 [SubscriptionCard] 主题亮度: ${Theme.of(context).brightness}');
print('🎴 [SubscriptionCard] 文本颜色: ${Theme.of(context).textTheme.bodyMedium?.color}');
print('🎴 [SubscriptionCard] ScreenUtil - 12.w=${12.w}, 16.h=${16.h}, 44.w=${44.w}');
print('🎴 [SubscriptionCard] ScreenUtil 测试 - 12.w=${12.w}, 16.h=${16.h}, 44.w=${44.w}');
// 🔧 关键修复:添加最小高度约束和调试边框
// 🔧 关键修复:完全移除 ScreenUtil,使用固定像素值避免缩放问题
return Container(
// 添加最小高度,确保卡片可见
constraints: const BoxConstraints(minHeight: 180),
// 添加固定高度,确保卡片可见
constraints: const BoxConstraints(minHeight: 200),
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
color: Theme.of(context).cardColor,
borderRadius: BorderRadius.circular(12.w),
// 🔧 添加边框用于调试可见性
border: Border.all(
color: Colors.blue.withOpacity(0.3),
width: 2,
),
borderRadius: BorderRadius.circular(12),
),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
// 图标
Container(
width: 44.w,
height: 44.w,
margin: EdgeInsets.only(top: 16.h),
width: 48,
height: 48,
decoration: BoxDecoration(
color: Colors.blue.withOpacity(0.1),
shape: BoxShape.circle,
),
child: Icon(
child: const Icon(
Icons.language,
color: Colors.blue,
size: 26.w,
size: 28,
),
),
SizedBox(height: 12.h),
const SizedBox(height: 16),
// 描述文字
Padding(
padding: EdgeInsets.symmetric(horizontal: 16.w),
padding: const EdgeInsets.symmetric(horizontal: 16),
child: Text(
AppTranslations.kr_home.subscriptionDescription,
textAlign: TextAlign.center,
style: KrAppTextStyle(
fontSize: 14,
style: TextStyle(
fontSize: 15,
fontWeight: FontWeight.w400,
height: 1.5,
// 🔧 关键修复:确保文本颜色可见
color: Theme.of(context).brightness == Brightness.dark
? Colors.white
@@ -77,28 +75,29 @@ class KRSubscriptionCard extends StatelessWidget {
),
),
),
SizedBox(height: 16.h),
Padding(
padding: EdgeInsets.fromLTRB(16.w, 0, 16.w, 16.h),
child: SizedBox(
width: double.infinity,
height: 42.h,
child: ElevatedButton(
onPressed: () => KRSubscribeNavigationUtil.navigateToPurchase(tag: 'SubscriptionCard'),
style: ElevatedButton.styleFrom(
backgroundColor: Colors.blue,
elevation: 0,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8.r),
),
const SizedBox(height: 20),
// 订阅按钮
SizedBox(
width: double.infinity,
height: 46,
child: ElevatedButton(
onPressed: () {
print('🎴 [SubscriptionCard] 订阅按钮被点击');
KRSubscribeNavigationUtil.navigateToPurchase(tag: 'SubscriptionCard');
},
style: ElevatedButton.styleFrom(
backgroundColor: Colors.blue,
elevation: 0,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8),
),
child: Text(
AppTranslations.kr_home.subscribe,
style: KrAppTextStyle(
fontSize: 16,
fontWeight: FontWeight.w500,
color: Colors.white,
),
),
child: Text(
AppTranslations.kr_home.subscribe,
style: const TextStyle(
fontSize: 16,
fontWeight: FontWeight.w500,
color: Colors.white,
),
),
),