he _ScaffoldLayout custom multichild layout delegate forgot to lay out the following children:

错误写法

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: CommonAppBar.buildAppBar("首页"),
        body: Container(
          alignment: Alignment.topCenter,
          child: SliverGrid(
            gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
              crossAxisCount: 2,
              mainAxisSpacing: 8,
              crossAxisSpacing: 8,
            ),
            delegate: SliverChildBuilderDelegate(
              (context, index) {
                return this._homeGridItem(context, index);
              },
              childCount: 6,
            ),
          ),
        ));
  }

正确写法

@override
Widget build(BuildContext context) {
  return Scaffold(
    appBar: CommonAppBar.buildAppBar("首页"),
    body: CustomScrollView(// Sliver开头的控件boby 必须是CustomScrollView
      slivers: [
        SliverGrid(
          gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
            crossAxisCount: 2,
            mainAxisSpacing: 8,
            crossAxisSpacing: 8,
          ),
          delegate: SliverChildBuilderDelegate(
            (context, index) {
              return this._homeGridItem(context, index);
            },
            childCount: 6,
          ),
        )
      ],
    ),
  );
}

找了好久原因

你可能感兴趣的:(flutter使用记录)