簡體   English   中英

誰能告訴我為什么我在嘗試實現動畫時會在 Flutter 中收到此錯誤

[英]Can anybody tell why am I getting this error in Flutter while trying to implement animation

            Another exception was thrown: 'package:flutter/src/animation/curves.dart': Failed assertion: line 182 pos 12: 'begin <= 1.0': is not true.

========小部件庫捕獲的異常===================================== =================='package:flutter/src/animation/curves.dart':失敗的斷言:第182行pos 12:'begin <= 1.0':不是真的. 相關的導致錯誤的小部件是:MyHomeWidget file:///C:/Users/Alfred%20J.%20Stanley/FlutterProjects/flutter_app_test/lib/main.dart:21:13

    import 'package:flutter/cupertino.dart';
    import 'package:flutter/material.dart';
    import 'package:flutter_app_test/DrawerClass.dart';
    import 'package:flutter_app_test/widgets/category_widget.dart';
    import 'package:flutter_app_test/widgets/search_bar.dart';
    import 'constants.dart';

    class MyHomeWidget extends StatefulWidget {
      @override
    State<StatefulWidget> createState() {
    return MyHomeWidgetState();
    }
    }

    class MyHomeWidgetState extends State<MyHomeWidget>
    with SingleTickerProviderStateMixin {
    AnimationController animationController;
    Animation animationcolor;
    Animation animationsize;
    Animation animationsizeText;

    @override
    void initState() {
    super.initState();
    animationController = AnimationController(vsync: this, duration: Duration(seconds:4));
    animationsizeText=Tween<double>(begin: 10.0,end: 30.0).animate(CurvedAnimation(parent: 
    animationController,curve: Interval(1.75,2.75)));
    animationsize = TweenSequence(
    [
    TweenSequenceItem(tween: Tween(begin: 50.0, end: 30.0), weight: 1),
    TweenSequenceItem(tween: Tween(begin: 30.0, end: 50.0), weight: 1)
    ],).animate(CurvedAnimation(parent: animationController,curve: Interval(3.0,4.0)));

    animationcolor = ColorTween(begin: Colors.grey, end: Colors.black)
    .animate(animationController);
    animationController.forward();

    animationController.addListener(() {
    setState(() {});
    });
    }

    @override
    Widget build(BuildContext context) {
    var screen_size = MediaQuery.of(context).size;
    return Scaffold(
    drawer: DrawerClass(),
    appBar: AppBar(
    title: Text("App Bar Title"),
    ),
    bottomNavigationBar: BottomNavigationBar(
    currentIndex: 0,
    backgroundColor: Colors.blue,
    items: [
      BottomNavigationBarItem(
        icon: Image.asset(
          'assets/images/cloud.png',
          height: 30,
        ),
        title: Text(
          'item1',
          style: TextStyle(color: Colors.white),
        ),
      ),
      BottomNavigationBarItem(
        icon: Image.asset(
          'assets/images/cloud.png',
          height: 30,
        ),
        title: Text(
          'item2',
          style: TextStyle(color: Colors.white),
        ),
      ),
      BottomNavigationBarItem(
        icon: Image.asset(
          'assets/images/cloud.png',
          height: 30,
        ),
        title: Text(
          'item3',
          style: TextStyle(color: Colors.white),
        ),
      ),
    ],
  ),
  body:Stack(
      children: <Widget>[
        Container(
          width: screen_size.width,
          height: screen_size.height * 0.4,
          decoration: BoxDecoration(
              color: Colors.lightBlueAccent,
              image: DecorationImage(
                image: AssetImage('assets/images/cloud.png'),
                alignment: Alignment.centerLeft,
              )),
          child: Column(
            children: [
              Align(
                alignment: Alignment.topRight,
                child: Container(
                  width: animationsize.value,
                  height: animationsize.value,
                  decoration: BoxDecoration(
                    shape: BoxShape.circle,
                    color: Colors.white,
                    image: DecorationImage(
                      image: AssetImage('assets/images/cloud.png'),
                    ),
                  ),
                ),
              ),
              Center(
                child: Text(
                  "Good Morning, Faiz Ahammed",
                  style: TextStyle(
                      fontSize: animationsizeText.value,
                      fontWeight: FontWeight.w100,
                      color: animationcolor.value),
                ),
              ),
            ],
          ),
        ),
        SafeArea(
          child: Padding(
            padding: EdgeInsets.fromLTRB(20.0, 120.0, 20.0,5.0),
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: <Widget>[

                SearchBar(),
                Expanded(
                  child: GridView.count(
                    mainAxisSpacing: 20.0,
                    crossAxisSpacing: 20.0,
                    childAspectRatio: 0.85,
                    crossAxisCount: 2,
                    children: <Widget>[
                      Category(
                        title: "Meditation",
                        svgsrc: "assets/images/cloud.png",
                        onPress: () {},
                      ),
                      Category(
                        title: "Yoga",
                        svgsrc: "assets/images/cloud.png",
                        onPress: () {},
                      ),
                      Category(
                        title: "Karatte",
                        svgsrc: "assets/images/cloud.png",
                        onPress: () {},
                      ),
                      Category(
                        title: "Kunfu",
                        svgsrc: "assets/images/cloud.png",
                        onPress: () {},
                      ),
                      Category(
                        title: "Swimming",
                        svgsrc: "assets/images/cloud.png",
                        onPress: () {},
                      ),
                      Category(
                        title: "Cycling",
                        svgsrc: "assets/images/cloud.png",
                        onPress: () {},
                      ),
                      Category(
                        title: "Trekking",
                        svgsrc: "assets/images/cloud.png",
                        onPress: () {},
                      ),
                      Category(
                        title: "Sailing",
                        svgsrc: "assets/images/cloud.png",
                        onPress: () {},
                      ),
                    ],
                  ),
                ),
              ],
            ),
          ),
        ),
      ],
    ),
  );

} }

如果您閱讀Interval Class 文檔,您將看到:

曲線在開始之前為 0.0,然后彎曲(根據曲線)從開始時的 0.0 到結束時的 1.0,然后在結束時保持 1.0。

所以beginend參數都必須是一個值,例如0.0<=begin<end<=1.0

當您的代碼中有以下內容時,您不會注意這一點:

Interval(1.75,2.75)

如果不深入查看完整代碼,我無法理解您的意圖,但這些值沒有意義。 Interval是一條曲線,它僅表示值如何變化,因此數字本身的縮放比例應該沒有任何區別。

從技術上講,曲線是將值從 0.0 -> 1.0 映射到 0.0 -> 1.0 的函數。 也就是說,它可以使動畫在其過程的不同部分加速或減速。 顧名思義,它僅指動畫的曲線 有關常見動畫曲線的示例,請參閱此頁面

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

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