首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >带有hero和showDialog的动画

带有hero和showDialog的动画
EN

Stack Overflow用户
提问于 2020-03-14 01:29:17
回答 1查看 965关注 0票数 1

我需要帮助重新创建这个示例动画与flutter,我尝试使用showDialog(),但我看不到动画,我使用标签Hero(),但不工作,请帮助我!

EN

回答 1

Stack Overflow用户

发布于 2020-03-14 08:28:39

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

检查下面的示例代码:

代码语言:javascript
复制
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),
                  ),
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60674896

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档