<small id='0Yk5p'></small><noframes id='0Yk5p'>

      • <bdo id='0Yk5p'></bdo><ul id='0Yk5p'></ul>
      <legend id='0Yk5p'><style id='0Yk5p'><dir id='0Yk5p'><q id='0Yk5p'></q></dir></style></legend>
      <tfoot id='0Yk5p'></tfoot>
      <i id='0Yk5p'><tr id='0Yk5p'><dt id='0Yk5p'><q id='0Yk5p'><span id='0Yk5p'><b id='0Yk5p'><form id='0Yk5p'><ins id='0Yk5p'></ins><ul id='0Yk5p'></ul><sub id='0Yk5p'></sub></form><legend id='0Yk5p'></legend><bdo id='0Yk5p'><pre id='0Yk5p'><center id='0Yk5p'></center></pre></bdo></b><th id='0Yk5p'></th></span></q></dt></tr></i><div id='0Yk5p'><tfoot id='0Yk5p'></tfoot><dl id='0Yk5p'><fieldset id='0Yk5p'></fieldset></dl></div>
    1. Flutter:SingleChildScrollView 内的 TabBarView

      Flutter: TabBarView inside SingleChildScrollView(Flutter:SingleChildScrollView 内的 TabBarView)

      <small id='FrPHV'></small><noframes id='FrPHV'>

          <tbody id='FrPHV'></tbody>
      • <legend id='FrPHV'><style id='FrPHV'><dir id='FrPHV'><q id='FrPHV'></q></dir></style></legend>

            <bdo id='FrPHV'></bdo><ul id='FrPHV'></ul>

            <tfoot id='FrPHV'></tfoot>
                <i id='FrPHV'><tr id='FrPHV'><dt id='FrPHV'><q id='FrPHV'><span id='FrPHV'><b id='FrPHV'><form id='FrPHV'><ins id='FrPHV'></ins><ul id='FrPHV'></ul><sub id='FrPHV'></sub></form><legend id='FrPHV'></legend><bdo id='FrPHV'><pre id='FrPHV'><center id='FrPHV'></center></pre></bdo></b><th id='FrPHV'></th></span></q></dt></tr></i><div id='FrPHV'><tfoot id='FrPHV'></tfoot><dl id='FrPHV'><fieldset id='FrPHV'></fieldset></dl></div>
              • 本文介绍了Flutter:SingleChildScrollView 内的 TabBarView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我的问题是我想要一个 TabBarView 在 SingleChildScrollView 中,但它给了我这个错误:RenderFlex 子级具有非零 flex 但传入的高度约束是无界的.

                My problem is that I want a TabBarView inside a SingleChildScrollView but it gives me this error: RenderFlex children have non-zero flex but incoming height constraints are unbounded.

                如果我删除 SingleChildScrollView 它可以工作,但我需要该小部件,因为我想推送一个 ListView,它可以使用 TabBar 滚动,例如 Instagram.

                If I remove the SingleChildScrollView it works but I need the widget because then I want to push a ListView that it scrolls with the TabBar, like Instagram.

                代码:

                import 'package:flutter/material.dart';
                
                void main() {
                  runApp(MyApp());
                }
                
                class MyApp extends StatefulWidget {
                  @override
                  _MyAppState createState() => _MyAppState();
                }
                
                class _MyAppState extends State<MyApp> with SingleTickerProviderStateMixin {
                  TabController tabController;
                
                  @override
                  void initState() {
                    super.initState();
                    tabController = new TabController(length: 2, vsync: this);
                  }
                
                  @override
                  void dispose() {
                    tabController.dispose();
                    super.dispose();
                  }
                
                  @override
                  Widget build(BuildContext context) {
                    return MaterialApp(
                        home: Scaffold(
                            body: SingleChildScrollView(
                      child: Column(
                        children: [
                          TabBar(
                            controller: tabController,
                            tabs: [
                              Tab(
                                icon: Icon(
                                  Icons.photo_library,
                                  size: 30,
                                ),
                              ),
                              Tab(
                                icon: Icon(
                                  Icons.perm_media,
                                  size: 30,
                                ),
                              ),
                            ],
                            labelColor: Colors.deepOrange,
                            unselectedLabelColor: Colors.black,
                            indicatorColor: Colors.deepOrange,
                          ),
                          Expanded(
                            child: TabBarView(controller: tabController, children: [
                              Expanded(child: Container()),
                              Expanded(child: Container())
                            ]),
                          ),
                        ],
                      ),
                    )));
                  }
                }
                
                

                变化:

                import 'package:flutter/material.dart';
                
                void main() {
                  runApp(MyApp());
                }
                
                class MyApp extends StatefulWidget {
                  @override
                  _MyAppState createState() => _MyAppState();
                }
                
                class _MyAppState extends State<MyApp> with SingleTickerProviderStateMixin {
                  TabController tabController;
                
                  @override
                  void initState() {
                    super.initState();
                    tabController = new TabController(length: 2, vsync: this);
                  }
                
                  @override
                  void dispose() {
                    tabController.dispose();
                    super.dispose();
                  }
                
                  @override
                  Widget build(BuildContext context) {
                    return MaterialApp(
                        home: Scaffold(
                            body: Column(
                        mainAxisSize: MainAxisSize.min,
                        children: [
                          TabBar(
                            controller: tabController,
                            tabs: [
                              Tab(
                                icon: Icon(
                                  Icons.photo_library,
                                  size: 30,
                                ),
                              ),
                              Tab(
                                icon: Icon(
                                  Icons.perm_media,
                                  size: 30,
                                ),
                              ),
                            ],
                            labelColor: Colors.deepOrange,
                            unselectedLabelColor: Colors.black,
                            indicatorColor: Colors.deepOrange,
                          ),
                          Expanded(
                            child: SingleChildScrollView(child:TabBarView(controller: tabController, children: [
                              Container(),
                              Container()
                            ]),
                          ),)
                        ],
                      ),
                    ));
                  }
                }
                

                推荐答案

                您可以使用 NestedScrollView 来解决这个问题.

                You can use NestedScrollView to fix this issue.

                下面的代码帮我解决了:

                The below code helped me to solve:

                NestedScrollView(
                      headerSliverBuilder: (context, value) {
                        return [
                          SliverToBoxAdapter(
                              child: Header()
                          ),
                          SliverToBoxAdapter(
                            child: TabBar(
                              controller: _controller,
                              tabs: [
                                Tab(icon: Icon(Icons.x)),
                                Tab(icon: Icon(Icons.y)),
                                Tab(icon: Icon(Icons.z)),
                              ],
                            ),
                          ),
                        ];
                      },
                    body: Container(
                      child: TabBarView(
                        controller: _controller,
                        children: <Widget>[
                          page1(),
                          page2(),
                          page3(),
                        ],
                      ),
                    ),
                  )
                

                更多解释请参考这个答案

                这篇关于Flutter:SingleChildScrollView 内的 TabBarView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                How can I use CClistview in COCOS2d Android?(如何在 COCOS2d Android 中使用 CClistview?)
                cocos2d-android: how to display score(cocos2d-android:如何显示分数)
                Sqlite database not copied from asset folder Android(Sqlite 数据库未从资产文件夹 Android 复制)
                SQLite Database Copy Appears Corrupted When Generated by Device and not Emulator(SQLite 数据库副本在由设备而不是模拟器生成时出现损坏)
                Android file copy(安卓文件拷贝)
                Android how to detect Copy event of Edittext in android(Android如何在android中检测Edittext的Copy事件)
                <tfoot id='hW4ov'></tfoot>
                  <i id='hW4ov'><tr id='hW4ov'><dt id='hW4ov'><q id='hW4ov'><span id='hW4ov'><b id='hW4ov'><form id='hW4ov'><ins id='hW4ov'></ins><ul id='hW4ov'></ul><sub id='hW4ov'></sub></form><legend id='hW4ov'></legend><bdo id='hW4ov'><pre id='hW4ov'><center id='hW4ov'></center></pre></bdo></b><th id='hW4ov'></th></span></q></dt></tr></i><div id='hW4ov'><tfoot id='hW4ov'></tfoot><dl id='hW4ov'><fieldset id='hW4ov'></fieldset></dl></div>
                      <tbody id='hW4ov'></tbody>

                        <bdo id='hW4ov'></bdo><ul id='hW4ov'></ul>
                        <legend id='hW4ov'><style id='hW4ov'><dir id='hW4ov'><q id='hW4ov'></q></dir></style></legend>

                          <small id='hW4ov'></small><noframes id='hW4ov'>