flutter - 类 'bool'没有实例方法 '-'。接收方:true尝试调用:-(false)

标签 flutter dart

我试图使用TweenAnimationBuilder<bool>,但即使有异常日志,我也真的不知道出了什么问题。在发布此问题之前,我已经厌倦了谷歌搜索,但没有帮助。
异常(exception):

Class 'bool' has no instance method '-'.
Receiver: true
Tried calling: -(false)
The relevant error-causing widget was TweenAnimationBuilder<bool> 
代码:
 @override
  Widget build(BuildContext context) {
    return TweenAnimationBuilder<bool>(
      duration: Duration(seconds: 2),
      tween: Tween<bool>(begin: false, end: true),
      builder: (BuildContext context, bool tween, Widget child) {
        print(tween.toString());
        return Visibility(visible: showNavBar, child: child);
      },
      child: BottomNavigationBar(
        selectedItemColor: Colors.green,
        unselectedItemColor: Colors.black,
        items: [
          BottomNavigationBarItem(icon: Icon(Icons.home), label: "Home"),
          BottomNavigationBarItem(icon: Icon(Icons.explore), label: "Home"),
          BottomNavigationBarItem(
              icon: Icon(Icons.library_books), label: "Home"),
          BottomNavigationBarItem(icon: Icon(Icons.settings), label: "Home")
        ],
        onTap: (index) {},
      ),
    );
  }

最佳答案

TweenAnimationBuilder<bool>尝试使用Tween<bool>,但Tween<T>不能与bool一起使用。从 Tween 文档中:

Types with special considerations

...

Types that define + and - operators to combine values (T + T → T and T - T → T) and an * operator to scale by multiplying with a double (T * double → T) can be directly used with Tween<T>.

bool不提供+-*运算符。

关于flutter - 类 'bool'没有实例方法 '-'。接收方:true尝试调用:-(false),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64290555/

相关文章:

flutter - 为什么迁移到 flutter 3.3.0 后 Build 失败?

dart - 当我尝试实现登录屏幕时抛出异常

flutter - 如何向下扩展定位的容器?

oop - 如何使用对象属性获取 List<customClass> 中自定义对象元素的索引?

flutter - 是否有用于二维条码扫描仪的内置 flutter 库?

flutter - 安卓原生开启 flutter 屏

dart - Flutter Firestore 服务器端时间戳

list - ( Dart/flutter )从混洗的列表中拉出一项而不重新生成列表

android - 任务 ':app:preDebugBuild' 执行失败 .in Flutter

colors - StageXL 和颜色值