如何在Dart中修复底部导航器错误

huangapple go评论69阅读模式
英文:

How can i fix the bottom navigator error in dart

问题

以下是您要翻译的内容:

我在Flutter Dart中创建了一个BottomNavigation栏,但出现了错误。

代码如下

如何在Dart中修复底部导航器错误

错误如下

并且这是错误,请帮助

如何在Dart中修复底部导航器错误

如果有人能帮助我解决这个错误,我将非常感激

控制台版本如下

英文:

I was making a BottonNavigation bar in flutter dart and i am getting an error

the code is
This the code

如何在Dart中修复底部导航器错误

the error is
And this the error pls help

如何在Dart中修复底部导航器错误

I want a solution for this error if someone can help me i will thank them a lot

The console version is this

答案1

得分: 0

你需要在目标参数中传递 NavigationDestination,而不是 NavigationDrawerDestination。

示例代码片段:

bottomNavigationBar: NavigationBar(
        onDestinationSelected: (int index) {
          setState(() {
            currentPageIndex = index;
          });
        },
        selectedIndex: currentPageIndex,
        destinations: const <Widget>[
          NavigationDestination(
            icon: Icon(Icons.explore),
            label: 'Explore',
          ),
          NavigationDestination(
            icon: Icon(Icons.commute),
            label: 'Commute',
          ),
          NavigationDestination(
            selectedIcon: Icon(Icons.bookmark),
            icon: Icon(Icons.bookmark_border),
            label: 'Saved',
          ),
        ],
      ),

请参考官方文档:https://api.flutter.dev/flutter/material/NavigationBar-class.html

或者,如果您正在使用其他包,请查阅其文档。

或者,您也可以使用https://api.flutter.dev/flutter/material/BottomNavigationBar-class.html

英文:

you need to pass NavigationDestination instead of NavigationDrawerDestination in the destinations params

** sample code snippet **

bottomNavigationBar: NavigationBar(
        onDestinationSelected: (int index) {
          setState(() {
            currentPageIndex = index;
          });
        },
        selectedIndex: currentPageIndex,
        destinations: const &lt;Widget&gt;[
          NavigationDestination(
            icon: Icon(Icons.explore),
            label: &#39;Explore&#39;,
          ),
          NavigationDestination(
            icon: Icon(Icons.commute),
            label: &#39;Commute&#39;,
          ),
          NavigationDestination(
            selectedIcon: Icon(Icons.bookmark),
            icon: Icon(Icons.bookmark_border),
            label: &#39;Saved&#39;,
          ),
        ],
      ),

follow official documentation https://api.flutter.dev/flutter/material/NavigationBar-class.html (material you/3)

or If you are using other package for it check its documentation

or you can also use
https://api.flutter.dev/flutter/material/BottomNavigationBar-class.html (material 2)

huangapple
  • 本文由 发表于 2023年2月13日 23:47:32
  • 转载请务必保留本文链接:https://go.coder-hub.com/75438164.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定