You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

已安装Android APP部分Table不显示,仅模拟器可见问题求助

报表页Table仅在模拟器可见、真机不显示的排查方案

APK构建无报错,但出现字体摇树优化提示:

Font asset "MaterialIcons-Regular.otf" was tree-shaken, reducing it from 1645184 to 1928 bytes (99.9% reduction). Tree-shaking can be disabled by providing the --no-tree-shake-icons flag when building your app.

已确认该提示不是问题根源:某页面的Table在模拟器和真机APP中均显示正常,但报表页的Table仅能在模拟器中看到,真机完全不显示。

页面显示情况:

  • 首页:正常显示
  • 普通Table页面:模拟器、真机均正常加载
  • 报表Table页面:仅模拟器可见,真机无显示

以下是报表页Table的核心代码:

//table begins here
Padding(
  padding: const EdgeInsets.symmetric(horizontal: 0),
  child: Table(
    //table border styling
    border: const TableBorder(
      top: BorderSide(width: 0.5, color: Colors.grey),
      bottom: BorderSide(width: 0.5, color: Colors.grey),
      left: BorderSide(width: 0.5, color: Colors.grey),
      right: BorderSide(width: 0.5, color: Colors.grey),
      horizontalInside: BorderSide(width: 0.5, color: Colors.grey),
    ),
    defaultVerticalAlignment: TableCellVerticalAlignment.middle,

    //column width
    columnWidths: const {
      0: FlexColumnWidth(40),
      1: FlexColumnWidth(35),
      2: FlexColumnWidth(22),
    },
    children: [
      //first table row
      TableRow(
        decoration: const BoxDecoration(
          color: Color.fromARGB(255, 228, 228, 228),
        ),
        children: [
          TableCell(
            verticalAlignment: TableCellVerticalAlignment.middle,
            child: Padding(
              padding: const EdgeInsets.all(8.0),
              child: Text(
                'Entity Name',
                style: GoogleFonts.lato(
                  fontSize: 15,
                  fontWeight: FontWeight.bold,
                ),
              ),
            ),
          ),
          TableCell(
            verticalAlignment: TableCellVerticalAlignment.middle,
            child: Padding(
              padding: const EdgeInsets.all(8.0),
              child: Text(
                'Submission Date',
                style: GoogleFonts.lato(
                    fontSize: 15, fontWeight: FontWeight.bold),
              ),
            ),
          ),
          TableCell(
            verticalAlignment: TableCellVerticalAlignment.middle,
            child: Padding(
              padding: const EdgeInsets.all(8.0),
              child: Text(
                'Status',
                style: GoogleFonts.lato(
                    fontSize: 15, fontWeight: FontWeight.bold),
              ),
            ),
          ),
        ],
      ),

      //second table row
      TableRow(
        decoration: const BoxDecoration(
          color: Colors.white,
        ),
        children: [
          TableCell(
            verticalAlignment: TableCellVerticalAlignment.middle,
            child: Padding(
              padding: const EdgeInsets.all(10.0),
              child: Text(
                '',
                style: GoogleFonts.lato(
                  fontSize: 15,
                  fontWeight: FontWeight.normal,
                ),
              ),
            ),
          ),
          TableCell(
            verticalAlignment: TableCellVerticalAlignment.middle,
            child: Padding(
              padding: const EdgeInsets.all(8.0),
              child: Text(
                '',
                style: GoogleFonts.lato(
                    fontSize: 15, fontWeight: FontWeight.normal),
              ),
            ),
          ),
          Center(
            child: TableCell(
              verticalAlignment: TableCellVerticalAlignment.middle,
              child: SizedBox(
                height: 30,
                child: ElevatedButton(
                  style: ElevatedButton.styleFrom(
                    padding: const EdgeInsets.all(4),
                    backgroundColor: const Color(0xff166955),
                  ),
                  onPressed: () {
                    Navigator.push(
                      context,
                      MaterialPageRoute(
                        builder: (context) => const EntityDetails(),
                      ),
                    );
                  },
                  child: Text(
                    'APPROVED',
                    style: GoogleFonts.lato(
                      fontSize: 12,
                      fontWeight: FontWeight.normal,
                    ),
                  ),
                ),
              ),
            ),
          ),
        ],
      ),

      //third table row
      TableRow(
        decoration: const BoxDecoration(
          color: Color.fromARGB(255, 250, 250, 250),
        ),
        children: [
          TableCell(
            verticalAlignment: TableCellVerticalAlignment.middle,
            child: Padding(
              padding: const EdgeInsets.all(10.0),

              //entity name
              child: Text(
                '',
                style: GoogleFonts.lato(
                  fontSize: 15,
                  fontWeight: FontWeight.normal,
                ),
              ),
            ),
          ),
          TableCell(
            verticalAlignment: TableCellVerticalAlignment.middle,
            child: Padding(
              padding: const EdgeInsets.all(8.0),
              child: Text(
                '',
                style: GoogleFonts.lato(
                    fontSize: 15, fontWeight: FontWeight.normal),
              ),
            ),
          ),
          Center(
            child: TableCell(
              verticalAlignment: TableCellVerticalAlignment.middle,
              child: SizedBox(
                height: 30,
                child: ElevatedButton(
                  style: ElevatedButton.styleFrom(
                    padding: const EdgeInsets.all(4),
                    backgroundColor: const Color(0xff166955),
                  ),
                  onPressed: () {},
                  child: Text(
                    'APPROVED',
                    style: GoogleFonts.lato(
                      fontSize: 12,
                      fontWeight: FontWeight.normal,
                    ),
                  ),
                ),
              ),
            ),
          ),
        ],
      ),
    ],
  ),
)

排查方向与修复建议

1. 修复TableCell嵌套错误

代码中Center包裹TableCell的写法不符合Flutter布局规范,TableCell是Table的直接子组件,外层嵌套Center会导致真机渲染异常。调整为TableCell内部嵌套Center:

TableCell(
  verticalAlignment: TableCellVerticalAlignment.middle,
  child: Center(
    child: SizedBox(
      height: 30,
      child: ElevatedButton(
        // 按钮原有代码
      ),
    ),
  ),
)

2. 优化布局适配性

当前使用FlexColumnWidth的比例可能在真机不同屏幕尺寸下导致布局溢出或被挤压,建议添加横向滚动容器,或替换为更稳定的宽度配置:

SingleChildScrollView(
  scrollDirection: Axis.horizontal,
  child: Table(
    // 原Table代码
  ),
)

3. 排除Google Fonts加载问题

真机环境下Google Fonts可能因网络或缓存问题未加载,导致文本不显示进而让Table行高度异常。可以:

  • 替换为系统默认字体测试:
    style: TextStyle(
      fontSize: 15,
      fontWeight: FontWeight.bold,
    )
    
  • 在APP初始化阶段预加载字体:
    await GoogleFonts.lato().load();
    

4. 验证release模式编译配置

模拟器通常用debug模式,真机可能使用release模式,检查编译优化是否导致布局被误删:

  • 尝试运行flutter build apk --no-tree-shake-icons构建,排除字体摇树的潜在影响
  • 检查pubspec.yaml中flutter配置,确保未禁用相关widget

内容的提问来源于stack exchange,提问作者Paul Amanya

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.06 00:26:06