How to fix "A RenderFlex overflowed by Infinity pixels on the bottom." error on flutter?

Issue

I brought some code from the net for the different appbar design and apply it to my code. And I wanted to use bottomnavigationbar and tabbar for my app. But when I tried to apply them together, the part of bottomenavigationbar overflowed by infinity pixels on the bottom. To make scroll on the tabbarview, I attached expanded and singlechildscrollview too, but nothing changed.
I’m a real beginner of Dart and Flutter.
Please give me a hint to fix this problem.


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,
        ),
    );
  }
}


I expect to scroll each tabbarview page and make no errors. Thank you.

Solution

Here is my solution to your problem. I have also used just one Scaffold rather than using two. Please check this out and let me know if it works for you.

    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,
      ),
    );
  }
}

Answered By – nick.tdr

Answer Checked By – Marilyn (FlutterFixes Volunteer)

Leave a Reply

Your email address will not be published.