flutter - 如何使用 'CupertinoFullscreenDialogTransition' ?

标签 flutter dart flutter-layout

我没有找到构造函数 CupertinoFullscreenDialogTransition 的任何示例

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

我试图理解下面的代码,但我没有理解。

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);

最佳答案

这是一个更完整的例子

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

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  static const String _title = 'AppBar tutorial';

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      theme: ThemeData(
        brightness: Brightness.light,
        primaryColor: Colors.blue[900],
        appBarTheme: AppBarTheme(iconTheme: IconThemeData(color: Colors.white)),
      ),
      title: _title,
      home: CupertinoFullscreenDialogTransitionPage(),
    );
  }
}

//First Page
class CupertinoFullscreenDialogTransitionPage extends StatefulWidget {
  @override
  _CupertinoFullscreenDialogTransitionState createState() =>
      _CupertinoFullscreenDialogTransitionState();
}

class _CupertinoFullscreenDialogTransitionState
    extends State<CupertinoFullscreenDialogTransitionPage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: PreferredSize(
        preferredSize: Size.fromHeight(60),
        child: AppBar(
          title: Text("Cupertino Screen Transition"),
          centerTitle: true,
        ),
      ),
      body: Center(
          child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: <Widget>[
          CupertinoButton.filled(
            child: Text("Next Page Cupertino Transition"),
            onPressed: () => Navigator.of(context).push(
              PageRouteBuilder(
                opaque: false,
                pageBuilder: (context, _, __) {
                  return FullDialogPage();
                },
              ),
            ),
          ),
        ],
      )),
    );
  }
}

//Second Page
class FullDialogPage extends StatefulWidget {
  @override
  _FullDialogPageState createState() => _FullDialogPageState();
}

class _FullDialogPageState extends State<FullDialogPage>
    with TickerProviderStateMixin {
  AnimationController _primary, _secondary;
  Animation<double> _animationPrimary, _animationSecondary;

  @override
  void initState() {
    //Primaty
    _primary = AnimationController(vsync: this, duration: Duration(seconds: 1));
    _animationPrimary = Tween<double>(begin: 0, end: 1)
        .animate(CurvedAnimation(parent: _primary, curve: Curves.easeOut));
    //Secondary
    _secondary =
        AnimationController(vsync: this, duration: Duration(seconds: 1));
    _animationSecondary = Tween<double>(begin: 0, end: 1)
        .animate(CurvedAnimation(parent: _secondary, curve: Curves.easeOut));
    _primary.forward();
    super.initState();
  }

  @override
  void dispose() {
    _primary.dispose();
    _secondary.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return CupertinoFullscreenDialogTransition(
      primaryRouteAnimation: _animationPrimary,
      secondaryRouteAnimation: _animationSecondary,
      linearTransition: false,
      child: Scaffold(
        appBar: AppBar(
          backgroundColor: Colors.indigo[900],
          title: Text("Testing"),
          leading: IconButton(
            icon: Icon(Icons.arrow_back),
            onPressed: () {
              _primary.reverse();
              Future.delayed(Duration(seconds: 1), () {
                Navigator.of(context).pop();
              });
            },
          ),
        ),
      ),
    );
  }
}

关于flutter - 如何使用 'CupertinoFullscreenDialogTransition' ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59530136/

相关文章:

firebase - 找不到插件项目:firebase_core_web

flutter - 如何在 flutter 中对齐行和列中的点?

android - 设备 emulator-5554 未经授权。 (安卓)

flutter - 如何在 BottomNavigationBar 中的小部件元素内添加 TabBarView

flutter - 从Flutter中的图库中保存ImagePicker图像

flutter - 根据另一个小部件的位置/大小定位/调整小部件的大小

android - 当我从 flutter 的 Assets 中获取时的ImageIcon颜色问题

dart - 在 Flutter 中的容器内制作可滚动的文本

flutter - 找不到插件项目:location_web。请更新settings.gradle

flutter - 如何用肘节改变 bool true false ?