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

时间:2020-10-10 06:13:47

标签: flutter dart

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

例外:

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) {},
      ),
    );
  }

1 个答案:

答案 0 :(得分:3)

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

有特殊考虑的类型

...

定义+-运算符以组合值(T + T → TT - T → T)和*运算符以乘以双倍( T * double → T)可以直接与Tween<T>一起使用。

bool不提供+-*运算符。