我在我的Flatter项目中使用了bottomNavigationBar.我是Flatter的新手,不知道如何分页,使用assets资源 图像图标而不是Iconda.在过go 的两天里,我一直在寻找,但没有得到满意的结果.请帮帮我......

我在这里使用了带有工厂按钮的BottomNavigationBar https://medium.com/coding-with-flutter/flutter-bottomappbar-navigation-with-fab-8b962bb55013https://github.com/bizz84/bottom_bar_fab_flutter

我还try 在这里使用自定义图标 https://medium.com/flutterpub/how-to-use-custom-icons-in-flutter-834a079d977

但没有成功

我只想更改图标,并想知道如何使用分页.我所能做的更改了最后一个分页示例代码.

推荐答案

下面是如何使用assets资源 中的图标

ImageIcon(
     AssetImage("images/icon_more.png"),
     color: Color(0xFF3A5A98),
),

在Bot到mNavBar click中try 此示例

因此,您要替换的是Bot到mNavigationBarItem

 new Bot到mNavigationBarItem(
           icon: Icon(Icons.home),
           title: Text('Home'),
         ),

 new Bot到mNavigationBarItem(
           icon: ImageIcon(
               AssetImage("images/icon_more.png"),
                    color: Color(0xFF3A5A98),
               ),
           title: Text('Home'),
         ),

您可以从我分享的文章中了解导航

UPDATE个 这是您要求的一个例子.

So here the _children variable holds the list of pages that you want 到 navigate based on the selection of Bot到mNavBarItem.

我们的导航方式是,当我们按下选项卡项时,我们使用onTabTaps函数设置它的索引.当索引更改时,视图也会相应更改,正如我们已经指示的那样,Body显示子对象的当前索引


class MyHomePage extends StatefulWidget {
  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int _currentIndex = 0;
  final List<Widget> _children = [
    Container(
      color: Colors.red,
    ),
    Container(
      color: Colors.blue,
    ),
    Container(
      color: Colors.green,
    )
  ];

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

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: _children[_currentIndex],
      bot到mNavigationBar: Bot到mNavigationBar(
        onTap: onTabTapped, // new
        currentIndex: _currentIndex, // new
        items: [
          new Bot到mNavigationBarItem(
            icon: Icon(Icons.home),
            title: Text('Home'),
          ),
          new Bot到mNavigationBarItem(
            icon: Icon(Icons.mail),
            title: Text('Messages'),
          ),
          new Bot到mNavigationBarItem(
              icon: Icon(Icons.person), title: Text('Profile'))
        ],
      ),
    );
  }
}

Flutter相关问答推荐

为什么在Flutter中使用firebase数据库时获取引用时会划掉引用?

无法在Flatter中设计正确的布局

为什么用户界面不会在Flight中的复选框中更改?

当我转到其他屏幕并按下后退按钮时,屏幕将不会刷新

如何使 dart 函数变得通用?

了解多Provider 和流

Flutter Riverpod 没有捕获 List 的嵌套值变化

如何修改来自合并 list 的 Android list 权限?

无状态和有状态小部件,我可以同时使用吗?

Flutter:如何在现有布局之上显示圆角布局?

如何使 flutter 2 手指zoom ?

Flutter 中的 Provider 不会在第一次构建 App 时返回

在 Flutter 中显示有关提供者通知的对话框

Paypal 支付网关添加带有 magento 2 网络详细信息用户名、密码、签名 Magento 2 的 flutter 应用程序?

Flutter 分析发现 Gitlab CI/CD 管道中的问题,但它在本地没有

alert 对话框内的 ListView 显示空的透明窗口

如何流畅切换画面?

Future.wait() 中的 futures 可以顺序调用吗?

NoSuchMethodError:方法 '[]' 在 null 上被调用.我的信息流中的错误

如何在Flutter 中水平滚动堆叠定位的小部件?