在其他屏幕上访问课程时遇到问题-Flutter

时间:2020-06-09 05:38:22

标签: flutter dart flutter-layout

我是Flutter的新手。我了解Flutter几乎可以使用所有小部件,即使如此,我也无法理解如何使用这些小部件中的类。

我想做的是将我的类Animation调用到第二个屏幕,但在Container(或另一个能够渲染动画的小部件)内部。我收到以下错误:位置参数过多,预​​期为0,但发现为1。位置参数必须在命名参数之前发生。我已经阅读过类似的问题,但就我而言(我可以理解),我没有将任何参数传递给第二个屏幕。

这是我的代码

class Animation extends State<MyHomePage> with
SingleTickerProviderStateMixin {

 Animation<double> animation;
 AnimationController controller;

 @override
 void initState() {
   super.initState();

   controller =
       AnimationController(vsync: this, duration: Duration(seconds: 2));
   animation = Tween<double>(begin: 0, end: 300).animate(controller)
     ..addListener(() {
       setState(() {});
     })
     ..addStatusListener((status) {
       if (status == AnimationStatus.completed) {
         controller.reverse();
       } else if (status == AnimationStatus.dismissed) {
         controller.forward();
       }
     });

   controller.forward();
 }

@override
 void dispose() {
   controller.dispose();
   super.dispose();
 }

 @override
 Widget build(BuildContext context) {
   return Center(
       child: Container(
         height: animation.value,
         width: animation.value,
         decoration: new BoxDecoration(
         color: Color(0xFF88e0c9),
         shape: BoxShape.circle,
       ),
     ),
   );
 }

}

第二个屏幕的代码

class SecondScreen extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: Container(
         alignment: Alignment.center,
         padding: const EdgeInsets.all(8.0),
          decoration: BoxDecoration(
            gradient: LinearGradient(
              begin: Alignment.topRight,
              end: Alignment.bottomLeft,
              colors: <Color>[
                Color(0xFF91FFFB),
                Color(0xFF47debb),
                Color(0xFF77e0c9),          
              ],
            ),
          ),
       child: Text(
              'Some Text',
               textAlign: TextAlign.center,
               style: GoogleFonts.coveredByYourGrace(
                letterSpacing: 0.9,
                fontSize: 30.0,
                color: Colors.white,
                fontWeight: FontWeight.bold
                ),
            ),
        ),

       Container //Here I want to render my animation

      ),
    );
  }
}

我的主页代码

class MyHomePage extends StatefulWidget {
  @override
  _HomeState createState() => _HomeState();
}

class _HomeState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: Container(
          decoration: BoxDecoration(
            gradient: LinearGradient(
              begin: Alignment.topRight,
              end: Alignment.bottomLeft,
              colors: <Color>[
                Color(0xFF91FFFB),
                Color(0xFF47debb),
                Color(0xFF77e0c9),
              ],
            ),
          ),
          child: Buttons(),
        ),
      ),
    );
  }
}

我的runApp(MyApp())方法在单独的dart文件中。我在那里 home: MyHomePage()

0 个答案:

没有答案