我试图使用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
andT - T → T
) and an*
operator to scale by multiplying with a double (T * double → T
) can be directly used withTween<T>
.
bool
不提供+
,-
和*
运算符。
关于flutter - 类 'bool'没有实例方法 '-'。接收方:true尝试调用:-(false),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64290555/