android - 动画中的英雄和showDialog动画

标签 android ios flutter dart

我需要帮助来重新创建带有 flutter 的此示例动画,我尝试使用showDialog(),但我看不到动画,我使用了带有标签的Hero(),但不起作用,请帮助我!

最佳答案

可以使用Stack,AnimatedPositioned和AnimatedContainer来完成:

Example

检查以下示例代码:

import 'package:flutter/material.dart';

class MyPage extends StatefulWidget {
  @override
  _MyPageState createState() => _MyPageState();
}

class _MyPageState extends State<MyPage> {
  bool isOpen = false;

  // AnimatedContainer dimensions:
  double width = 55, height = 55;

  // AnimatedPositioned positions:
  double left = 20, bottom = 20;

  @override
  Widget build(BuildContext context) {

    return Scaffold(
      body: SafeArea(
        child: Container(
          color: Color(0xff151515),
          child: Stack(
            children: <Widget>[
              Positioned(
                left: 0,
                top: 0,
                right: 0,
                bottom: 0,
                child: Column(
                  mainAxisAlignment: MainAxisAlignment.center,
                  children: <Widget>[
                    Text("TIMER", style: TextStyle(color: Colors.white, fontSize: 36, fontWeight: FontWeight.w700),),
                    Text("00 : 00", style: TextStyle(color: Colors.white, fontSize: 36, fontWeight: FontWeight.w700),),
                  ],
                ),
              ),
              Positioned(
                left: 0,
                top: 0,
                right: 0,
                bottom: 0,
                child: GestureDetector(
                  child: AnimatedOpacity(
                    // If the widget is visible, animate to 0.0 (invisible).
                    // If the widget is hidden, animate to 1.0 (fully visible).
                    opacity: isOpen ? 1.0 : 0.0,
                    duration: Duration(milliseconds: 500),
                    // The green box must be a child of the AnimatedOpacity widget.
                    child: Container(
                      width: 200.0,
                      height: 200.0,
                      color: Colors.black45,
                    ),
                  ),
                  onTap: () {
                    if (isOpen) {
                      setState(() {
                        width = 55; height = 55;
                        left = 20; bottom = 20;
                        isOpen = false;
                      });
                    }
                  },
                ),
              ),
              AnimatedPositioned(
                left: left,
                bottom: bottom,
                duration: Duration(milliseconds: 500),
                curve: Curves.easeInOut,
                child: GestureDetector(
                  child: AnimatedContainer(
                    width: width,
                    height: height,
                    decoration: new BoxDecoration(
                        color: Colors.blue,
                        borderRadius: BorderRadius.circular(28)),
                    duration: Duration(milliseconds: 500),
                    curve: Curves.easeInOut,
                    // child: dialog container content goes here,
                  ),
                  onTap: () {
                    if (!isOpen) {
                      setState(() {
                        width = 200; height = 200;
                        left = 60; bottom = 60;
                        isOpen = !isOpen;
                      });
                    }
                  },
                ),
              ),
              Positioned(
                bottom: 30,
                left: 40,
                child: IgnorePointer(
                  child: Text(
                    '1',
                    style: TextStyle(color: Colors.white, fontSize: 30),
                  ),
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }
}

关于android - 动画中的英雄和showDialog动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60674896/

相关文章:

ios - 在 IOS 中假动画单个图像文件可能吗?

ios - 字典数组中每个对象的最大值

java - 从 Android 启动不同的任务

ios - 当加载WKWebview时,它是nil

android - 当按下 EditText 上的 "Enter"按钮时创建一个新行

flutter - 在 Flutter 中延迟一段时间后如何运行代码?

dart - 如何在flutter中创建可滚动的日期选择器?

flutter - 按钮单击添加从 API 获取的下拉小部件

java - 如何将数据加载到 FragmentActivity 中以供嵌套 fragment 使用?

android - 错误:任务 ':app:transformClassesWithJarMergingForDebug'重复条目的执行失败