【问题标题】:How to remove Background Bottom Nav Color While Scrolling in Flutter如何在 Flutter 中滚动时删除背景底部导航颜色
【发布时间】:2021-02-13 17:36:03
【问题描述】:

我有一个在滚动时隐藏的动画容器(类似于 Pinterest)。我在这两个页面中都有 2 个带有列表视图的页面。当我滚动列表视图时,底部导航栏隐藏,但我可以找到与底部导航栏高度相同的填充。它不动。我什至尝试使用 extendBody: true 但它没有用。我什至将 extendBody: true 添加到两个 ListView 但它没有用。谁能帮忙?

class Home extends StatefulWidget {
  @override
  _HomeState createState() => _HomeState();
}

class _HomeState extends State<Home> {
  double yTransValue = 0;

  int _currentIndex = 0;
  final List<Widget> _children = [
    Landingpage1(),
    LandingPage2(),
  ];

  void onTappedBar(int index) {
    setState(() {
      _currentIndex = index;
    });
  }

  @override
  Widget build(BuildContext context) {
    return NotificationListener<ScrollUpdateNotification>(
      onNotification: (notification) {

        if (notification.scrollDelta.sign == 1) {
          setState(() {
            yTransValue = 100;
          });
        } else if (notification.scrollDelta.sign == -1) {
          setState(() {
            yTransValue = 0;
          });
        }
      },
      child: Scaffold(
        extendBody: true,
        body: _children[_currentIndex],
        bottomNavigationBar: AnimatedContainer(
          duration: Duration(milliseconds: 300),
          transform: Matrix4.translationValues(0, yTransValue, 0),
          child: SizedBox(
            height: 60,
            child: BottomNavigationBar(
              fixedColor: Colors.red,
              onTap: onTappedBar,
              currentIndex: _currentIndex,
              items: [
                BottomNavigationBarItem(
                  icon: Icon(
                    Icons.home,
                    size: 20.0,
                  ),
                  title: Text(
                    "",
                    style: TextStyle(height: 0.0),
                  ),
                ),
                BottomNavigationBarItem(
                  icon: Icon(Icons.arrow_circle_down),
                  title: Text(
                    "",
                    style: TextStyle(height: 0.0),
                  ),
                ),
              ],
            ),
          ),
        ),
      ),
    );
  }
}

【问题讨论】:

    标签: flutter flutter-layout bottomnavigationview flutter-animation


    【解决方案1】:

    尝试为您的SizedBox 使用变量height

    height: 100 - yTransValue,
    
      @override
      Widget build(BuildContext context) {
        return NotificationListener<ScrollUpdateNotification>(
          onNotification: (notification) {...},
          child: Scaffold(
            extendBody: true,
            body: _children[_currentIndex],
            bottomNavigationBar: AnimatedContainer(
              duration: Duration(milliseconds: 300),
              transform: Matrix4.translationValues(0, yTransValue, 0),
              child: SizedBox(
                height: 100 - yTransValue,
                child: BottomNavigationBar(...)
              ),
            ),
          ),
        );
      }
    }
    

    【讨论】:

      猜你喜欢
      • 2020-04-18
      • 1970-01-01
      • 2021-12-25
      • 2022-10-04
      • 1970-01-01
      • 2017-12-27
      • 2016-11-14
      • 2018-06-02
      • 1970-01-01
      相关资源
      最近更新 更多