How to use 'CupertinoFullscreenDialogTransition'?

你说的曾经没有我的故事 提交于 2020-06-01 06:38:32

问题


I didn't find any example for constructor CupertinoFullscreenDialogTransition

https://api.flutter.dev/flutter/cupertino/CupertinoFullscreenDialogTransition-class.html

I tried to understand below code but I didn't get it.

CupertinoFullscreenDialogTransition({
  Key key,
  @required Animation<double> animation,
  @required this.child,
}) : _positionAnimation = CurvedAnimation(
       parent: animation,
       curve: Curves.linearToEaseOut,
       // The curve must be flipped so that the reverse animation doesn't play
       // an ease-in curve, which iOS does not use.
       reverseCurve: Curves.linearToEaseOut.flipped,
     ).drive(_kBottomUpTween),
     super(key: key);

回答1:


I've made this simple example, I hope it helps you understand how to implement the CupertinoFullscreenDialogTransition Widget.

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.orange,
      ),
      home: MyHomePage(),
    );
  }
}

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

class _MyHomePageState extends State<MyHomePage>  with SingleTickerProviderStateMixin{
 AnimationController _animationController;

 @override
  void initState() {
   _animationController = AnimationController(
     vsync: this,
     duration: Duration(milliseconds: 500),
   );
    super.initState();
  }
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Stackoverflow playground'),
      ),
      body: Container(
        child: Column(
          children: <Widget>[
            CupertinoFullscreenDialogTransition(
            primaryRouteAnimation: _animationController,
            secondaryRouteAnimation: _animationController,
            linearTransition: false,
              child: Center(
                child: Container(
                  color: Colors.blueGrey,
                  width: 300,
                  height: 300,
                ),
              ),
            ),
            Row(
              mainAxisAlignment: MainAxisAlignment.spaceAround,
              children: <Widget>[
                RaisedButton(
                  onPressed: () => _animationController.forward(),
                  child: Text('Forward'),
                ),
                RaisedButton(
                  onPressed: () => _animationController.reverse(),
                  child: Text('Reverse'),
                ),
              ],
            ),
          ],
        ),
      )
    );
  }
}


来源:https://stackoverflow.com/questions/59530136/how-to-use-cupertinofullscreendialogtransition

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!