flutter - 如何修复 flutter 上的 "A RenderFlex overflowed

我从网上为不同的应用栏设计带来了一些代码并将其应用到我的代码中。我想为我的应用程序使用 bottomnavigationbar 和 tabbar。但是当我尝试将它们一起应用时,bottomenavigationbar 的部分在底部溢出了无限像素。为了在 tabbarview 上滚动,我也附加了 expanded 和 singlechildscrollview,但没有任何改变。 我是 Dart 和 Flutter 的真正初学者。 请给我提示以解决此问题。


Home.dart



class Home extends StatelessWidget {

  GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      key: _scaffoldKey,
      body: Column(
        children: <Widget>[
          Container(
            height: 160.0,
            child: Stack(
              children: <Widget>[
                Container(
                  color: Colors.pinkAccent[400],
                  width: MediaQuery.of(context).size.width,
                  height: 100.0,
                  child: Center(
                    child: Text(
                      "여행 앱 로고",
                      style: TextStyle(color: Colors.white, fontSize: 18.0),
                    ),
                  ),
                ),
                Positioned(
                  top: 80.0,
                  left: 0.0,
                  right: 0.0,
                  child: Container(
                    padding: EdgeInsets.symmetric(horizontal: 20.0),
                    child: DecoratedBox(
                      decoration: BoxDecoration(
                          borderRadius: BorderRadius.circular(1.0),
                          border: Border.all(
                              color: Colors.grey.withOpacity(0.5), width: 1.0),
                          color: Colors.white),
                      child: Row(
                        children: [
                          IconButton(
                            icon: Icon(
                              Icons.menu,
                              color: Colors.pinkAccent[400],
                            ),
                            onPressed: () {
                              print("your menu action here");
                              _scaffoldKey.currentState.openDrawer();
                            },
                          ),
                          Expanded(
                            child: TextField(
                              decoration: InputDecoration.collapsed(
                                hintText: "검색",
                              ),
                            ),
                          ),
                          IconButton(
                            icon: Icon(
                              Icons.search,
                              color: Colors.pinkAccent[400],
                            ),
                            onPressed: () {
                              print("your menu action here");
                            },
                          ),
                        ],
                      ),
                    ),
                  ),
                )
              ],
            ),
          ),
         Container(
           child: TabBarHome(),
         ),
        ],
      ),
    );
  }
}





TabBarHome.dart


class TabBarHome extends StatefulWidget {
  @override
  _TabBarHomeState createState() => _TabBarHomeState();
}

class _TabBarHomeState extends State<TabBarHome> with
SingleTickerProviderStateMixin {
  TabController _tabController;

  @override
  void initState() {
    super.initState();

    _tabController = TabController(length: 3, vsync: this);
  }

  @override
  void dispose() {
    super.dispose();

    _tabController.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        body: Column(
          children: <Widget>[
            Expanded(
              child: SingleChildScrollView(
                child: TabBarView(
                  controller: _tabController,
                  children: <Widget>[
                    Text('회원가입'),
                    Text('마이페이지'),
                    Text('공지'),
                  ],
                ),
              ),
            ),
          ],
        ),
        bottomNavigationBar: Container(
          child: TabBar(
            controller: _tabController,
            labelColor: Colors.black45,
            tabs: <Widget>[
              Tab(icon: Icon(Icons.person), text: '회원가입'),
              Tab(icon: Icon(Icons.assignment_ind), text: '마이페이지'),
              Tab(icon: Icon(Icons.list), text: '공지'),
            ],
          ),
          color: Colors.cyanAccent[100],
        ),
        floatingActionButtonLocation: FloatingActionButtonLocation.centerFloat,
        floatingActionButton: FloatingActionButton.extended(
          onPressed: () { },
          tooltip: '해외 명소',
          icon: Icon(Icons.location_on),
          label: Text("해외"),
          backgroundColor: Colors.orange[600],
          elevation: 10.0,
        ),
    );
  }
}


我希望滚动每个 tabbarview 页面并且不出错。谢谢。

最佳答案

这是我对您的问题的解决方案。我也只使用了一个脚手架,而不是使用两个。请检查一下,让我知道它是否适合您。

    class Home extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    // TODO: implement createState
    return _HomeState();
  }
}

class _HomeState extends State<Home> with TickerProviderStateMixin {
  GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey();

  TabController _tabController;
  int _selectedTabIndex;

  @override
  void initState() {
    super.initState();
    _selectedTabIndex = 0;
    _tabController = TabController(length: 3, vsync: this);
  }

  @override
  void dispose() {
    super.dispose();

    _tabController.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      key: _scaffoldKey,
      body: Column(
        children: <Widget>[
          Container(
            height: 160.0,
            child: Stack(
              children: <Widget>[
                Container(
                  color: Colors.pinkAccent[400],
                  width: MediaQuery.of(context).size.width,
                  height: 100.0,
                  child: Center(
                    child: Text(
                      "여행 앱 로고",
                      style: TextStyle(color: Colors.white, fontSize: 18.0),
                    ),
                  ),
                ),
                Positioned(
                  top: 80.0,
                  left: 0.0,
                  right: 0.0,
                  child: Container(
                    padding: EdgeInsets.symmetric(horizontal: 20.0),
                    child: DecoratedBox(
                      decoration: BoxDecoration(
                          borderRadius: BorderRadius.circular(1.0),
                          border: Border.all(
                              color: Colors.grey.withOpacity(0.5), width: 1.0),
                          color: Colors.white),
                      child: Row(
                        children: [
                          IconButton(
                            icon: Icon(
                              Icons.menu,
                              color: Colors.pinkAccent[400],
                            ),
                            onPressed: () {
                              print("your menu action here");
                              _scaffoldKey.currentState.openDrawer();
                            },
                          ),
                          Expanded(
                            child: TextField(
                              decoration: InputDecoration.collapsed(
                                hintText: "검색",
                              ),
                            ),
                          ),
                          IconButton(
                            icon: Icon(
                              Icons.search,
                              color: Colors.pinkAccent[400],
                            ),
                            onPressed: () {
                              print("your menu action here");
                            },
                          ),
                        ],
                      ),
                    ),
                  ),
                )
              ],
            ),
          ),
          Expanded(
            child: TabBarView(
              controller: _tabController,
              children: <Widget>[
                Text('회원가입'),
                Text('마이페이지'),
                Text('공지'),
              ],
            ),
          )
          /* Container(
            child: TabBarHome(),
          ),*/
        ],
      ),
      bottomNavigationBar: BottomNavigationBar(
        currentIndex: _selectedTabIndex,
        items: [
          BottomNavigationBarItem(
              icon: Icon(Icons.person), title: Text('회원가입')),
          BottomNavigationBarItem(
              icon: Icon(Icons.assignment_ind), title: Text('마이페이지')),
          BottomNavigationBarItem(icon: Icon(Icons.list), title: Text('공지')),
        ],
        onTap: (int tappedIndex) {
          setState(() {
            _selectedTabIndex = tappedIndex;
            _tabController.index = tappedIndex;
          });
        },
      ),
      floatingActionButtonLocation: FloatingActionButtonLocation.centerFloat,
      floatingActionButton: FloatingActionButton.extended(
        onPressed: () {},
        tooltip: '해외 명소',
        icon: Icon(Icons.location_on),
        label: Text("해외"),
        backgroundColor: Colors.orange[600],
        elevation: 10.0,
      ),
    );
  }
}

关于flutter - 如何修复 flutter 上的 "A RenderFlex overflowed by Infinity pixels on the bottom."错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57071484/

相关文章:

.net-core - 部署到 Azure 后,在 Angular 7 中使用 i18n 的本地化不

angular - Mat-select 滚动不跳转到选定的 mat-option

c++ - 如何使用跳过部分 device_vector 的自定义仿函数实现 thrust::tra

reactjs - Babel 不从当前目录上方的文件转译 JSX

jenkins - 我无法打开蓝海管道编辑器

javascript - 使用 CSS Grid 调整图表大小问题

android - react native : compileDebugJavaWithJavac

reactjs - 在 nextjs 中,对象类型从服务器端更改为客户端

reactjs - 如何使用 Jest 和 Enzyme 在 nextjs 应用程序中编写单元测试

amazon-web-services - 如何在数据加载前截断 AWS Glue 作业中的 RDS