具有自定义BottomNavBar和FAB的extendBody无法正常工作

时间:2020-09-15 09:35:37

标签: flutter dart

我已经搜索了类似的问题,但是找不到任何问题。 我用停靠的FAB制作了一个自定义的底部导航栏。据我了解,要使FAB的槽口透明,我需要在脚手架上添加extendBody = true;,我这样做了。结果是,在四个导航栏图标中,只有其中一个显示了透明凹口。 下面的代码和图像。图片显示了第二个和第三个导航栏图标。

     Scaffold(
          drawerEnableOpenDragGesture: true,
          extendBody: true,
          appBar: AppBar(
            title: Text('Some text),
          drawer: AppDrawer(),
          bottomNavigationBar: BottomAppBar(
            color: Colors.blue,
            shape: CircularNotchedRectangle(),
            notchMargin: 2.0,
            child: Container(
              height: MediaQuery.of(context).size.width * 0.15,
              child: Row(
                mainAxisSize: MainAxisSize.max,
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  Expanded(
                    flex: 4,
                    child: Row(
                      mainAxisAlignment: MainAxisAlignment.spaceAround,
                      children: [
                        IconButton(icon: Icon(Icons.account_box), // extendBody not working!
                          onPressed: () {
                            setState(() {
                              _selectedPageIndex = 0;
                            });
                          },
                        ),
                        IconButton(icon: Icon(Icons.account_box), // extendBody working!
                          onPressed: () {
                            setState(() {
                              _selectedPageIndex = 1;
                            });
                          },
                        ),
                      ],
                    ),
                  ),
                  Expanded(flex: 2, child: SizedBox()),
                  Expanded(
                    flex: 4,
                    child: Row(
                      mainAxisAlignment: MainAxisAlignment.spaceAround,
                      children: [
                        IconButton(icon: Icon(Icons.email), // extendBody not working!
                          onPressed: () {
                            setState(() {
                              _selectedPageIndex = 2;
                            });
                          },
                        ),
                        IconButton(
                          icon: Icon(Icons.email), // extendBody not working!
                          onPressed: () {
                            setState(() {
                              _selectedPageIndex = 3;
                            });
                          },
                        ),
                      ],
                    ),
                  ),
                ],
              ),
            ),
          ),
          floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
          body: _pages[_selectedPageIndex]['page'],
          floatingActionButton: FloatingActionButton(
            mini: true,
            onPressed: () {
              if (_selectedPageIndex == 0)
                Navigator.of(context).pushReplacementNamed(
                    Screen1.routeName);
              if (_selectedPageIndex == 1)
                Navigator.of(context).pushReplacementNamed(
                    Screen2.routeName);
              if (_selectedPageIndex == 2)
                Navigator.of(context).pushReplacementNamed(
                    Screen3.routeName);
              if (_selectedPageIndex == 3)
                Navigator.of(context).pushReplacementNamed(
                    Screen4.routeName);
            },
            child: _pages[_selectedPageIndex]['icon'],
            backgroundColor: Theme.of(context).accentColor,
          ),
        )

enter image description here enter image description here

我想念什么?谢谢!

1 个答案:

答案 0 :(得分:1)

我解决了。 // Cell class Cell: UICollectionViewListCell { var event: Event? var onEventDidChange: ((_ event: Event) -> Void)? //... } // Example cell registration in ViewController let eventCellRegistration = UICollectionView.CellRegistration<Event.Cell, Event> { [weak self] (cell, indexPath, event) in cell.event = event // Setting the data model for the cell // This is what I tried to do. A closure that the cell calls, whenever the cell made changes to the event (the model) cell.onEventDidChange = { event in /* update database */ } } 是正确的,但是不能将孩子包裹在UIContentView中。