簡體   English   中英

flutter 中的“類型 'double' 不是類型轉換中類型 'int' 的子類型”錯誤。 我應該怎么辦?

[英]“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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM