如何在颤音中使用浮动底部导航栏

发布于 2025-01-29 04:07:26 字数 2192 浏览 4 评论 0 原文

我正在尝试使用这个名为DOT导航栏的插件( https://pub.dev/packages/packages/packages/dot_navigation_bar_bar_bar ),然后我已经将插件安装到当前项目中,但我只是想知道如何通过现有屏幕。

我有Home(),calender(),help(),schedule()屏幕,所以想知道当我单击图标时如何打开这些页面。任何帮助或建议都将不胜感激。

这是文档中的示例代码。


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

class _HomeState extends State<Home> {
  var _selectedTab = _SelectedTab.home;

  void _handleIndexChanged(int i) {
    setState(() {
      _selectedTab = _SelectedTab.values[i];
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      extendBody: true,
      body: Container(
        child: Image.asset("lib/img/1.png"),
      ),
      bottomNavigationBar: Padding(
        padding: EdgeInsets.only(bottom: 10),
        child: DotNavigationBar(
          margin: EdgeInsets.only(left: 10, right: 10),
          currentIndex: _SelectedTab.values.indexOf(_selectedTab),
          dotIndicatorColor: Colors.white,
          unselectedItemColor: Colors.grey[300],
          // enableFloatingNavBar: false,
          onTap: _handleIndexChanged,
          items: [
            /// Home
            DotNavigationBarItem(
              icon: Icon(Icons.home),
              selectedColor: Color(0xff73544C),
            ),

            /// Likes
            DotNavigationBarItem(
              icon: Icon(Icons.favorite),
              selectedColor: Color(0xff73544C),
            ),

            /// Search
            DotNavigationBarItem(
              icon: Icon(Icons.search),
              selectedColor: Color(0xff73544C),
            ),

            /// Profile
            DotNavigationBarItem(
              icon: Icon(Icons.person),
              selectedColor: Color(0xff73544C),
            ),
          ],
        ),
      ),
    );
  }
}

enum _SelectedTab { home, favorite, search, person }

现在它只是这样显示的。

I'm trying to use this plugin called Dot navigation bar (https://pub.dev/packages/dot_navigation_bar) and I already installed the plugin into my current project but I'm just wondering how can I pass my existing Screens.

I have Home(), Calender(), Help(), Schedule() screen so just wondering how can I open those page when I click on the icons. Any help or suggestion will be really appreciated.

This is the example code from the documentation.


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

class _HomeState extends State<Home> {
  var _selectedTab = _SelectedTab.home;

  void _handleIndexChanged(int i) {
    setState(() {
      _selectedTab = _SelectedTab.values[i];
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      extendBody: true,
      body: Container(
        child: Image.asset("lib/img/1.png"),
      ),
      bottomNavigationBar: Padding(
        padding: EdgeInsets.only(bottom: 10),
        child: DotNavigationBar(
          margin: EdgeInsets.only(left: 10, right: 10),
          currentIndex: _SelectedTab.values.indexOf(_selectedTab),
          dotIndicatorColor: Colors.white,
          unselectedItemColor: Colors.grey[300],
          // enableFloatingNavBar: false,
          onTap: _handleIndexChanged,
          items: [
            /// Home
            DotNavigationBarItem(
              icon: Icon(Icons.home),
              selectedColor: Color(0xff73544C),
            ),

            /// Likes
            DotNavigationBarItem(
              icon: Icon(Icons.favorite),
              selectedColor: Color(0xff73544C),
            ),

            /// Search
            DotNavigationBarItem(
              icon: Icon(Icons.search),
              selectedColor: Color(0xff73544C),
            ),

            /// Profile
            DotNavigationBarItem(
              icon: Icon(Icons.person),
              selectedColor: Color(0xff73544C),
            ),
          ],
        ),
      ),
    );
  }
}

enum _SelectedTab { home, favorite, search, person }

Right now It just showing like this.

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

聊慰 2025-02-05 04:07:26

您可以替换此软件包,并在 floatingActionButton 参数中馈送任何(自定义/默认的飞行导航键),如下所示,

Scaffold(
    extendBody: true,  // <--- do not forget to mark this as true
    floatingActionButtonLocation: FloatingActionButtonLocation.centerFloat,
    floatingActionButton: NavigationBar(...),
    ...
)

如下所示,kudos to @iman

custom flo floating底部导航栏具有白色背景扑来

Scaffold(
    extendBody: true, // <--- do not forget mark this as true
    floatingActionButtonLocation: FloatingActionButtonLocation.centerFloat,
    floatingActionButton: Container(
      margin: const EdgeInsets.symmetric(horizontal: 25),
      decoration: BoxDecoration(
          color: Colors.white,
          borderRadius: BorderRadius.circular(50),
      ),
      child: NavigationBar(
        backgroundColor: Colors.transparent, // <--- to remove background color
        elevation: 0,                       // <--- to remove shadows
        ....
      ),

You can replace this package and feed any (custom/ default flutter NavigationBar) in the floatingActionButton parameter of the main Scaffold as shown below

Scaffold(
    extendBody: true,  // <--- do not forget to mark this as true
    floatingActionButtonLocation: FloatingActionButtonLocation.centerFloat,
    floatingActionButton: NavigationBar(...),
    ...
)

as described in this thread, kudos to @Iman

Custom floating bottom navigation bar has white background flutter

Scaffold(
    extendBody: true, // <--- do not forget mark this as true
    floatingActionButtonLocation: FloatingActionButtonLocation.centerFloat,
    floatingActionButton: Container(
      margin: const EdgeInsets.symmetric(horizontal: 25),
      decoration: BoxDecoration(
          color: Colors.white,
          borderRadius: BorderRadius.circular(50),
      ),
      child: NavigationBar(
        backgroundColor: Colors.transparent, // <--- to remove background color
        elevation: 0,                       // <--- to remove shadows
        ....
      ),
倒数 2025-02-05 04:07:26

body 通过导航项目的数组。

此外,您需要添加 .index ,因为 _SelectedTab 不是INT值。

navigation=[home(), favorite(), search(), person()]
body: navigation[_selectedTab.index]

In body pass array of navigation items.

In addition, you would need to add .index because _selectedTab is not an int value.

navigation=[home(), favorite(), search(), person()]
body: navigation[_selectedTab.index]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文