![](/img/trans.png)
[英]Flutter. type 'Null' is not a subtype of type 'String' in type cast
[英]“type 'double' is not a subtype of type 'int' in type cast” error in flutter. What should i do?
我在 flutter 中做一個簡單的曲線 Animation,但我總是收到這樣的錯誤“類型'double'不是類型轉換中'int'類型的子類型”,我在這里犯了什么錯誤?
class HomePage extends StatefulWidget {
@override
_HomePageState createState() => _HomePageState();
}
class _HomePageState extends State<HomePage>
with SingleTickerProviderStateMixin {
Animation animation;
AnimationController animationController;
@override
void initState() {
super.initState();
animationController =
AnimationController(duration: Duration(seconds: 3), vsync: this);
animation = Tween(begin: -1, end: 0).animate(CurvedAnimation(
curve: Curves.fastOutSlowIn, parent: animationController));
}
@override
Widget build(BuildContext context) {
final double width = MediaQuery.of(context).size.width;
animationController.forward();
return AnimatedBuilder(
animation: animationController,
builder: (BuildContext context, Widget child) {
return Scaffold(
body: Transform(
transform:
Matrix4.translationValues(animation.value * width, 0, 0),
child: Center(
child: Text(
"Welcome",
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 50),
),
),
),
);
});
}
}
您只需將Tween
的類型顯式 state 設為double
:
AnimationController(duration: Duration(seconds: 3), vsync: this);
animation = Tween<double>(begin: -1, end: 0).animate(CurvedAnimation(curve: Curves.fastOutSlowIn, parent: animationController));
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.