【问题标题】:flutter 1.23.0-18.1pre BottomNavigationBar deprecated 'title' use 'label'颤振 1.23.0-18.1pre BottomNavigationBar 已弃用 'title' 使用 'label'
【发布时间】:2020-10-27 10:03:14
【问题描述】:

title 部分给出了一个错误,告诉我应该改用标签。

错误是:

info: 'title' 已弃用,不应使用。请改用“标签”,因为它可以改善文本缩放体验。此功能在 v1.19.0 之后已被弃用.. (deprecated_member_use at lib/Screens/hostHomePage.dart:49)

希望有人能帮帮我吗?

BottomNavigationBarItem _buildNavigationItem(
      int index, IconData iconData, String text) {
    return BottomNavigationBarItem(
      icon: Icon(
        iconData,
        color: AppConstants.nonSelectedIconColor,
      ),
      activeIcon: Icon(
        iconData,
        color: AppConstants.selectedIconColor,
      ),
      title: Text(
        text,
        style: TextStyle(
          color: _selectedIndex == index
              ? AppConstants.selectedIconColor
              : AppConstants.nonSelectedIconColor,
        ),
      ),
    );
  }

【问题讨论】:

  • 如果您有错误,请在帖子中完整引用。
  • 我添加了错误信息
  • 好的,那你觉得不清楚呢?它说您应该改用更新的功能

标签: flutter


【解决方案1】:

正如我在文档中看到的那样,您提到的内容是正确的,要使其正常工作,您必须使用标签并将字符串传递给它。并删除您传递小部件的标题参数。

BottomNavigationBarItem _buildNavigationItem(
  int index, IconData iconData, String text) {
return BottomNavigationBarItem(
  icon: Icon(
    iconData,
    color: AppConstants.nonSelectedIconColor,
  ),
  activeIcon: Icon(
    iconData,
    color: AppConstants.selectedIconColor,
  ),
  label: text
);
}

这段代码应该适合您,而不是您现在正在编写的代码。 :-)。

link to the newer documentation

【讨论】:

  • 感谢您的快速回复!这会产生以下错误:错误:参数类型“String”不能分配给参数类型“Widget”。 (argument_type_not_assignable at [travelapp] lib/Screens/hostHomePage.dart:49) info: 'title' 已弃用,不应使用。请改用“标签”,因为它可以改善文本缩放体验。此功能在 v1.19.0 之后被弃用。(deprecated_member_use at [travelapp] lib/Screens/hostHomePage.dart:49)
  • 对不起,这是我的一个小错字。而不是标题使用标签。这就是你问题的重点,我把它搞砸了抱歉;)
猜你喜欢
  • 2021-10-31
  • 1970-01-01
  • 1970-01-01
  • 2021-11-27
  • 2021-10-15
  • 2021-02-14
  • 2020-05-30
  • 2020-12-26
  • 2021-08-19
相关资源
最近更新 更多