RenderViewport#3997a NEEDS-LAYOUT NEEDS-PAINT尝试将Tabbardefayltview与flutter中的列一起使用

时间:2019-05-11 14:57:56

标签: dart flutter

我试图将TabBarDefaultDiew与SinglechildVcrollView和Column一起使用。构建应用程序时,出现以下错误:

  

RenderViewport#3997a需求布局需求绘画

我曾尝试给容器指定高度和宽度,但还不够。 我以前见过这个错误,当我限制容器的高度和宽度时,该错误消失了。

这是我的代码:

class CategoryPage extends StatefulWidget {
  @override
  _CategoryPageState createState() => _CategoryPageState();
}

class _CategoryPageState extends State<CategoryPage> {
  final GlobalKey<ScaffoldState> _categoryScaffoldKey =
      new GlobalKey<ScaffoldState>();
  @override
  Widget build(BuildContext context) {
    return SafeArea(
      child: DefaultTabController(
        length: 2,
        child: Scaffold(
          key: _categoryScaffoldKey,
          endDrawer: CustomDrawer(),
          body: _buildCategoryBody(context),
        ),
      ),
    );
  }

  Widget _buildCategoryBody(BuildContext context) {
    return SingleChildScrollView(
      child: Column(
        children: <Widget>[
          _buildAppBar(context),
          _buildTabNames(context),
          _buildTabs(context),
        ],
      ),
    );
  }

  Widget _buildAppBar(BuildContext context) {
    return Padding(
      padding: EdgeInsets.symmetric(vertical: 5, horizontal: 3),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: <Widget>[
          IconButton(
            icon: Icon(Icons.search, color: Colors.black),
            onPressed: () {
            },
          ),
          Text(
            "test",
            style: TextStyle(fontWeight: FontWeight.bold),
          ),
          IconButton(
            icon: Icon(
              Icons.menu,
              color: Colors.black,
            ),
            onPressed: () => _categoryScaffoldKey.currentState.openEndDrawer(),
          ),
        ],
      ),
    );
  }

  Widget _buildTabNames(BuildContext context) {
    return TabBar(
      tabs: [
        Tab(
          text: "test",
        ),
        Tab(text: "test"),
      ],
    );
  }

  Widget _buildTabs(BuildContext context) {
    return TabBarView(
      children: <Widget>[
        _buildMenCategory(context),
        _buildWomenCategory(context)
      ],
    );
  }

  Widget _buildMenCategory(BuildContext context) {
    return Container(
      height: 10,
      width: 10,
    );
  }

  Widget _buildWomenCategory(BuildContext context) {
    return Container(
      height: 10,
      width: 10,
    );
  }
}

0 个答案:

没有答案