android - 无法在我的 flutter 演示应用程序中的 ListView 中显示 gridview

标签 android dart flutter

我正在将我的原生 android 项目转换为 flutter 应用程序,在此我需要在其他小部件下方显示选项网格。

这是代码

void main() {
  runApp(new MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    Column homeThumb(String icon, String label) {
      Color color = Theme.of(context).primaryColor;

      return new Column(
        mainAxisSize: MainAxisSize.min,
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          new Container(
            margin: const EdgeInsets.all(8.0),
            child: new Image.asset(icon, width: 32.0, height: 32.0),
          ),
          new Container(
            margin: const EdgeInsets.only(top: 8.0),
            child: new Text(
              label,
              textAlign: TextAlign.center,
              style: new TextStyle(
                fontSize: 12.0,
                fontWeight: FontWeight.w400,
                color: color,
              ),
            ),
          ),
        ],
      );
    }

    Widget homeIcon = new Container(
        child: new Column(
            mainAxisAlignment: MainAxisAlignment.spaceAround,
            children: <Widget>[
          new Container(
              margin: const EdgeInsets.only(
                  top: 40.0, left: 8.0, right: 8.0, bottom: 8.0),
              child: new Row(
                mainAxisAlignment: MainAxisAlignment.spaceAround,
                children: [
                  homeThumb("images/icons/list.png", 'Claim Offers'),
                  homeThumb("images/icons/wallet.png", 'Wallet'),
                  homeThumb("images/icons/cart.png", 'Redeem Offers'),
                ],
              )),
          new Container(
              margin: const EdgeInsets.all(8.0),
              child: new Row(
                mainAxisAlignment: MainAxisAlignment.spaceAround,
                children: [
                  homeThumb("images/icons/user.png", 'Account'),
                  homeThumb("images/icons/badge.png", 'Merchants'),
                  homeThumb("images/icons/history.png", 'Shopping History'),
                ],
              )),
          new Container(
              margin: const EdgeInsets.all(8.0),
              child: new Row(
                mainAxisAlignment: MainAxisAlignment.spaceAround,
                children: [
                  homeThumb("images/icons/bell.png", 'Notifications'),
                  homeThumb("images/icons/plane.png", 'Service Request'),
                  homeThumb("images/icons/share.png", 'Share & Earn'),
                ],
              )),


        ]));

    Widget grid = new GridView.count(
      crossAxisCount: 4,
      children: new List<Widget>.generate(16, (index) {
        return new GridTile(
          child: new Card(
              color: Colors.blue.shade200,
              child: new Center(
                child: new Text('tile $index'),
              )
          ),
        );
      }),
    );

    return new MaterialApp(
      title: 'Minkville',
      home: new Scaffold(
        appBar: new AppBar(
          title: new Text('Minkville'),
        ),
        body: new ListView(
          children: [
            new Image.asset(
              'images/slider/img_s1.jpg',
              width: 600.0,
              height: 180.0,
              fit: BoxFit.fill,
            ),
            homeIcon,
            grid

          ],
        ),
      ),
    );
  }
}

在调试时,会出现以下日志

I/flutter (16594): 抛出另一个异常:'package:flutter/src/rendering/sliver_multi_box_adaptor.dart': Failed assertion: line 441 pos 12: 'child.hasSize': is not true. i/flutter (16594): 又抛出一个异常:RenderBox was not layout: RenderRepaintBoundary#199e9 relayoutBoundary=up3 NEEDS-PAINT

最佳答案

忽略以上所有答案。 确保在 ListViewGridView 中都设置了 shr​​inkWrap : true。 问题解决了!!

关于android - 无法在我的 flutter 演示应用程序中的 ListView 中显示 gridview,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51099313/

相关文章:

android - 无法从 hashmap 的数组列表中删除重复元素

java - 显示位图图像 (ImageView)

android - 查找播放或使用蓝牙音乐流的应用包名

java - 在 Android 中访问基于 Soap 的 Web 服务

flutter - 当不同的文件时,getter发生抖动错误

dart - flutter_search_bar 插件 onClose 监听器

flutter - 如何在 flutter 中获得经纬度

android - "NoSuchMethodError: The method ' [] ' was called on null."我的流中出现错误

flutter - AlertDialog 函数在 flutter 的每个页面上运行

更新 Flutter 版本后未加载 Flutter 资源文件