首页 > 解决方案 > 是否可以在 Flutter 中使用没有 MaterialApp 的 GridView?

问题描述

我是 Flutter 的新手,我正在为一些概念而苦苦挣扎。

我无法在这样的容器内使用 GridView() 小部件:

class _ProductsGridState extends State<ProductsGrid> {
  @override
  Widget build(BuildContext context) {
    return Container(
      child: GridView.count(
        crossAxisCount: 2,
      ),
    );
  }
}

调试控制台给了我这个错误:

包:flutter/src/painting/basic_types.dart':断言失败:第 225 行 pos 10:'textDirection != null':不正确

谢谢 !:)

标签: flutterdart

解决方案


MaterialApp 是您的应用程序的根级小部件,它在幕后做了很多工作,为您提供一个基本页面,您可以在其中添加多个小部件,这些小部件可以在屏幕上显示。没有 Materialapp,您的应用程序将无法正常工作。


推荐阅读