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

(cherry picked from commit 73af298aebafc2e13668d645d461b99786b0c1e2)
This commit is contained in:
Rust 2025-11-02 15:54:48 +08:00 committed by speakeloudest
parent 17b3f6b92d
commit 75c7d31da1
6 changed files with 120 additions and 108 deletions

View File

@ -97,18 +97,18 @@ class KRHomeBottomPanel extends GetView<KRHomeController> {
if (hasValidSubscription)
//
Builder(builder: (context) {
KRLogUtil.kr_i('🔹 渲染连接信息卡片margin top: ${12.h}', tag: 'HomeBottomPanel');
KRLogUtil.kr_i('🔹 渲染连接信息卡片margin top: ${12}', tag: 'HomeBottomPanel');
return Container(
margin: EdgeInsets.only(top: 12.h),
margin: EdgeInsets.only(top: 12),
child: const KRHomeConnectionInfoView(),
);
})
else
//
Builder(builder: (context) {
KRLogUtil.kr_i('🔹 渲染订阅卡片margin: top=${12.h}, left=${12.w}, right=${12.w}', tag: 'HomeBottomPanel');
KRLogUtil.kr_i('🔹 渲染订阅卡片margin: top=${12}, left=${12}, right=${12}', tag: 'HomeBottomPanel');
return Container(
margin: EdgeInsets.only(top: 12.h, left: 12.w, right: 12.w),
margin: EdgeInsets.only(top: 12, left: 12, right: 12),
child: const KRSubscriptionCard(),
);
}),
@ -116,21 +116,21 @@ class KRHomeBottomPanel extends GetView<KRHomeController> {
// 2.
if (hasValidSubscription && isTrial)
Container(
margin: EdgeInsets.only(top: 12.h),
margin: EdgeInsets.only(top: 12),
child: const KRHomeTrialCard(),
),
// 3.
if (hasValidSubscription && isLastDay && !isTrial)
Container(
margin: EdgeInsets.only(top: 12.h),
margin: EdgeInsets.only(top: 12),
child: const KRHomeLastDayCard(),
),
// 4. -
Padding(
padding: EdgeInsets.symmetric(horizontal: 16.w, vertical: 12.h),
child: const KRHomeConnectionOptionsView(),
const Padding(
padding: EdgeInsets.symmetric(horizontal: 16, vertical: 12),
child: KRHomeConnectionOptionsView(),
),
],
),
@ -157,7 +157,7 @@ class KRHomeBottomPanel extends GetView<KRHomeController> {
//
Center(
child: Container(
padding: EdgeInsets.all(16.w),
padding: EdgeInsets.all(16),
decoration: BoxDecoration(
color: Get.context!.theme.cardColor,
borderRadius: BorderRadius.circular(12.r),
@ -176,7 +176,7 @@ class KRHomeBottomPanel extends GetView<KRHomeController> {
color: Colors.green,
strokeWidth: 3.0,
),
SizedBox(height: 12.h),
SizedBox(height: 12),
Text(
'正在加载...',
style: TextStyle(
@ -194,18 +194,18 @@ class KRHomeBottomPanel extends GetView<KRHomeController> {
Widget _kr_buildErrorView(BuildContext context) {
return Container(
height: 200.h,
padding: EdgeInsets.all(16.w),
height: 200,
padding: EdgeInsets.all(16),
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(
Icons.error_outline,
size: 48.w,
size: 48,
color: Theme.of(context).colorScheme.error,
),
SizedBox(height: 16.h),
SizedBox(height: 16),
Text(
AppTranslations.kr_home.error,
style: KrAppTextStyle(
@ -214,7 +214,7 @@ class KRHomeBottomPanel extends GetView<KRHomeController> {
color: Theme.of(context).textTheme.bodyMedium?.color,
),
),
SizedBox(height: 8.h),
SizedBox(height: 8),
Text(
AppTranslations.kr_home.checkNetwork,
style: KrAppTextStyle(
@ -222,10 +222,10 @@ class KRHomeBottomPanel extends GetView<KRHomeController> {
color: Theme.of(context).textTheme.bodySmall?.color,
),
),
SizedBox(height: 24.h),
SizedBox(height: 24),
SizedBox(
width: 200.w,
height: 44.h,
width: 200,
height: 44,
child: ElevatedButton(
onPressed: () => controller.kr_refreshAll(),
style: ElevatedButton.styleFrom(

View File

@ -25,17 +25,17 @@ class KRHomeConnectionInfoView extends GetView<KRHomeController> {
Widget _buildConnectCard(BuildContext context) {
return Obx(() {
return Container(
margin: EdgeInsets.symmetric(horizontal: 16.w),
margin: EdgeInsets.symmetric(horizontal: 16),
width: double.infinity,
height: 116.h,
height: 116,
decoration: ShapeDecoration(
color: Theme.of(context).cardColor,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(16.w),
borderRadius: BorderRadius.circular(16),
),
),
child: Padding(
padding: EdgeInsets.all(14.w),
padding: EdgeInsets.all(14),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
@ -66,7 +66,7 @@ class KRHomeConnectionInfoView extends GetView<KRHomeController> {
),
Icon(
Icons.arrow_forward_ios,
size: 12.w,
size: 12,
color: Theme.of(context).textTheme.bodySmall?.color,
),
],
@ -74,7 +74,7 @@ class KRHomeConnectionInfoView extends GetView<KRHomeController> {
),
],
),
SizedBox(height: 10.h),
SizedBox(height: 10),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
@ -90,7 +90,7 @@ class KRHomeConnectionInfoView extends GetView<KRHomeController> {
countryCode: countryCode,
);
}),
SizedBox(width: 10.w),
SizedBox(width: 10),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
@ -102,7 +102,7 @@ class KRHomeConnectionInfoView extends GetView<KRHomeController> {
fontWeight: FontWeight.w500,
),
),
SizedBox(height: 6.h),
SizedBox(height: 6),
Row(
children: [
Obx(() {
@ -147,10 +147,10 @@ class KRHomeConnectionInfoView extends GetView<KRHomeController> {
children: [
KRSimpleLoading(
color: Colors.green,
size: 12.w,
size: 12,
duration: const Duration(milliseconds: 800),
),
SizedBox(width: 2.w),
SizedBox(width: 2),
Text(
AppTranslations.kr_home.connecting,
style: TextStyle(
@ -166,7 +166,7 @@ class KRHomeConnectionInfoView extends GetView<KRHomeController> {
return Row(
children: [
Icon(Icons.signal_cellular_alt,
size: 12.w,
size: 12,
color: getLatencyColor(delay)),
SizedBox(width: 2),
Text(
@ -188,9 +188,9 @@ class KRHomeConnectionInfoView extends GetView<KRHomeController> {
}
return Row(
children: [
SizedBox(width: 10.w),
SizedBox(width: 10),
Icon(Icons.arrow_upward,
size: 12.w,
size: 12,
color: Theme.of(context).textTheme.bodySmall?.color),
Text(
controller.kr_formatBytes(KRSingBoxImp.instance.kr_stats.value.uplink),
@ -200,9 +200,9 @@ class KRHomeConnectionInfoView extends GetView<KRHomeController> {
fontWeight: FontWeight.w400,
),
),
SizedBox(width: 10.w),
SizedBox(width: 10),
Icon(Icons.arrow_downward,
size: 12.w,
size: 12,
color: Theme.of(context).textTheme.bodySmall?.color),
Text(
controller.kr_formatBytes(KRSingBoxImp.instance.kr_stats.value.downlink),

View File

@ -14,19 +14,23 @@ class KRHomeConnectionOptionsView extends GetView<KRHomeController> {
@override
Widget build(BuildContext context) {
print('🔌 [ConnectionOptions] 开始构建连接选项组件');
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: [
Text(
AppTranslations.kr_home.connectionSectionTitle,
style: KrAppTextStyle(
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.w600,
color: Theme.of(context).textTheme.bodyMedium?.color,
color: Theme.of(context).brightness == Brightness.dark
? Colors.white
: Colors.black87,
),
),
SizedBox(height: 8.h),
const SizedBox(height: 12),
_buildConnectionOption(
"home_ct",
AppTranslations.kr_home.countryRegion,
@ -41,8 +45,11 @@ class KRHomeConnectionOptionsView extends GetView<KRHomeController> {
Widget _buildConnectionOption(String icon, String label, BuildContext context,
{VoidCallback? onTap}) {
print('🔌 [ConnectionOptions] 构建连接选项: $label');
return GestureDetector(
onTap: () {
print('🔌 [ConnectionOptions] 选项被点击: $label');
if (controller.kr_subscribeService.kr_currentSubscribe.value == null) {
// 使
KRSubscribeNavigationUtil.navigateToPurchase(tag: 'ConnectionOptions');
@ -52,30 +59,34 @@ class KRHomeConnectionOptionsView extends GetView<KRHomeController> {
}
},
child: Container(
padding: EdgeInsets.all(16.w),
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
color: Theme.of(context).cardColor,
borderRadius: BorderRadius.circular(12.r),
borderRadius: BorderRadius.circular(12),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
KrLocalImage(
imageName: icon,
width: 32.w,
height: 32.w,
color: Theme.of(context).textTheme.bodyMedium?.color,
width: 36,
height: 36,
color: Theme.of(context).brightness == Brightness.dark
? Colors.white70
: Colors.black87,
),
SizedBox(height: 12.h),
const SizedBox(height: 12),
Row(
children: [
Expanded(
child: Text(
label,
style: KrAppTextStyle(
fontSize: 13,
style: TextStyle(
fontSize: 14,
fontWeight: FontWeight.w500,
color: Theme.of(context).textTheme.bodyMedium?.color,
color: Theme.of(context).brightness == Brightness.dark
? Colors.white
: Colors.black87,
),
maxLines: 2,
overflow: TextOverflow.ellipsis,
@ -83,8 +94,10 @@ class KRHomeConnectionOptionsView extends GetView<KRHomeController> {
),
Icon(
Icons.arrow_forward_ios,
size: 12.w,
color: Theme.of(context).textTheme.bodySmall?.color,
size: 14,
color: Theme.of(context).brightness == Brightness.dark
? Colors.white54
: Colors.black45,
),
],
),

View File

@ -15,16 +15,16 @@ class KRHomeLastDayCard extends GetView<KRHomeController> {
@override
Widget build(BuildContext context) {
return Container(
margin: EdgeInsets.symmetric(horizontal: 16.w),
margin: EdgeInsets.symmetric(horizontal: 16),
width: double.infinity,
decoration: ShapeDecoration(
color: Theme.of(context).cardColor,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(16.w),
borderRadius: BorderRadius.circular(16),
),
),
child: Padding(
padding: EdgeInsets.all(14.w),
padding: EdgeInsets.all(14),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
@ -54,7 +54,7 @@ class KRHomeLastDayCard extends GetView<KRHomeController> {
),
Icon(
Icons.arrow_forward_ios,
size: 12.w,
size: 12,
color: Colors.blue,
),
],
@ -64,14 +64,14 @@ class KRHomeLastDayCard extends GetView<KRHomeController> {
),
//
SizedBox(height: 10.h),
SizedBox(height: 10),
Row(
children: [
Container(
padding: EdgeInsets.all(8.w),
padding: EdgeInsets.all(8),
decoration: BoxDecoration(
color: Colors.blue.withOpacity(0.1),
borderRadius: BorderRadius.circular(8.w),
borderRadius: BorderRadius.circular(8),
),
child: Row(
mainAxisSize: MainAxisSize.min,
@ -79,9 +79,9 @@ class KRHomeLastDayCard extends GetView<KRHomeController> {
Icon(
Icons.timer_outlined,
color: Colors.blue,
size: 16.w,
size: 16,
),
SizedBox(width: 4.w),
SizedBox(width: 4),
Text(
AppTranslations.kr_home.lastDaySubscriptionMessage,
style: KrAppTextStyle(
@ -93,7 +93,7 @@ class KRHomeLastDayCard extends GetView<KRHomeController> {
],
),
),
SizedBox(width: 12.w),
SizedBox(width: 12),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,

View File

@ -16,16 +16,16 @@ class KRHomeTrialCard extends GetView<KRHomeController> {
@override
Widget build(BuildContext context) {
return Container(
margin: EdgeInsets.symmetric(horizontal: 16.w),
margin: EdgeInsets.symmetric(horizontal: 16),
width: double.infinity,
decoration: ShapeDecoration(
color: Theme.of(context).cardColor,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(16.w),
borderRadius: BorderRadius.circular(16),
),
),
child: Padding(
padding: EdgeInsets.all(14.w),
padding: EdgeInsets.all(14),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
@ -55,7 +55,7 @@ class KRHomeTrialCard extends GetView<KRHomeController> {
),
Icon(
Icons.arrow_forward_ios,
size: 12.w,
size: 12,
color: Colors.blue,
),
],
@ -65,14 +65,14 @@ class KRHomeTrialCard extends GetView<KRHomeController> {
),
//
SizedBox(height: 10.h),
SizedBox(height: 10),
Row(
children: [
Container(
padding: EdgeInsets.all(8.w),
padding: EdgeInsets.all(8),
decoration: BoxDecoration(
color: Colors.blue.withOpacity(0.1),
borderRadius: BorderRadius.circular(8.w),
borderRadius: BorderRadius.circular(8),
),
child: Row(
mainAxisSize: MainAxisSize.min,
@ -80,9 +80,9 @@ class KRHomeTrialCard extends GetView<KRHomeController> {
Icon(
Icons.timer_outlined,
color: Colors.blue,
size: 16.w,
size: 16,
),
SizedBox(width: 4.w),
SizedBox(width: 4),
Text(
AppTranslations.kr_home.trialing,
style: KrAppTextStyle(
@ -94,7 +94,7 @@ class KRHomeTrialCard extends GetView<KRHomeController> {
],
),
),
SizedBox(width: 12.w),
SizedBox(width: 12),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,

View File

@ -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,
),
),
),