简体   繁体   English

当给定 onTap 时,我想在动画过渡中将图像(一只蜜蜂)从第 1 页的左上角移动到第 2 页的右下角

[英]I want to move an image(a Bee) from the top left corner of page 1 to the bottom right corner of page 2 in an animated transition when onTap is given

I am developing an app, and I want to move an asset, an image of a bee in this case from top left of page 1 to the bottom right of page 2, in an animated fashion, which shows the bee fly to page 2, all this is happening while the user has clicked on the onTap button wrapped in a gestureDetector and the page is transitioning from page 1 to page 2.我正在开发一个应用程序,我想以动画方式移动资产,在这种情况下是蜜蜂的图像,从第 1 页的左上角到第 2 页的右下角,显示蜜蜂飞到第 2 页,所有这一切都发生在用户单击封装在手势检测器中的 onTap 按钮并且页面从第 1 页转换到第 2 页时。

I am attaching code for reference.我附上代码以供参考。 This is page 1这是第 1 页

 // ignore_for_file: prefer_const_constructors

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:learn_n_fun/landingScreens/page2.dart';

import '../animation/slidingAnimationForward.dart';

class Page1 extends StatefulWidget {
  const Page1({Key? key}) : super(key: key);

  @override
  _Page1State createState() => _Page1State();
}

class _Page1State extends State<Page1> {
  @override
  Widget build(BuildContext context) {
    var height = MediaQuery.of(context).size.height;
    var width = MediaQuery.of(context).size.width;
    return Scaffold(
        backgroundColor: Colors.white,
        body: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          mainAxisAlignment: MainAxisAlignment.start,
          children: [
            Expanded(
                flex: 2,
                child: Padding(
                  padding: EdgeInsets.fromLTRB(
                      width / 25, height / 10, width / 20, 0),
                  child: Column(
                    mainAxisAlignment: MainAxisAlignment.start,
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Text(
                        "Welcome",
                        style: TextStyle(
                          // fontSize: height / 20,
                          fontSize: 55,
                          fontWeight: FontWeight.w800,
                          fontFamily: "Playfair Display",
                        ),
                      ),
                      SizedBox(
                        height: height / 100,
                      ),
                      Text(
                        "Have you ever wondered what a Business Model Canvas is?",
                        style: TextStyle(
                          // fontWeight: FontWeight.w400,
                          // fontSize: height / 35,
                          fontSize: 22,
                          fontFamily: "Lato",
                        ),
                      )
                    ],
                  ),
                )),
            Padding(
                padding: EdgeInsets.all(0),
                // flex: 4,
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    Container(
                      height: height / 8,
                      child: RotationTransition(
                        turns: AlwaysStoppedAnimation(-70 / 360),
                        child: Image.asset(
                          "assets/images/bee.png",
                          fit: BoxFit.cover,
                        ),
                      ),
                    ),
                    Container(
                      margin: EdgeInsets.fromLTRB(width / 9.5, 0, 0, 0),
                      child: Image.asset(
                        "assets/images/florist16.png",
                        fit: BoxFit.cover,
                      ),
                    ),
                  ],
                )),
            Expanded(
                flex: 1,
                child: Container(
                  margin: EdgeInsets.fromLTRB(
                      width / 25, height / 80, width / 25, 0),
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      Row(
                        children: [
                          CircleAvatar(
                            radius: width / 100,
                            backgroundColor: Colors.black,
                          ),
                          const SizedBox(
                            width: 4,
                          ),
                          CircleAvatar(
                            radius: width / 100,
                            backgroundColor: Colors.grey.withOpacity(.5),
                          ),
                          const SizedBox(
                            width: 4,
                          ),
                          CircleAvatar(
                            radius: width / 100,
                            backgroundColor: Colors.grey.withOpacity(.5),
                          )
                        ],
                      ),
                      GestureDetector(
                          onTap: () {
                            Navigator.push(
                                context, SlidingPageF(child: const Page2()));
                          },
                          child: const ImageIcon(
                            AssetImage("assets/images/Front_arrow.png"),
                            size: 50,
                            color: Colors.black,
                          ))
                    ],
                  ),
                )),
          ],
        ));
  }
}

Any ideas on how i can achieve this?关于我如何实现这一目标的任何想法?

There is AnimatedAlign widget I think would work in your case.我认为有 AnimatedAlign 小部件适用于您的情况。 https://api.flutter.dev/flutter/widgets/AnimatedAlign-class.html https://api.flutter.dev/flutter/widgets/AnimatedAlign-class.html

You can do it with Hero Widget.你可以用Hero小部件来做到这一点。 https://api.flutter.dev/flutter/widgets/Hero-class.html https://api.flutter.dev/flutter/widgets/Hero-class.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Flutter 仅顶部、右侧、左侧边框,右上角和左上角为圆角 - Flutter only top, right, left border with rounded top right and top left corner 动画从左到右水平播放,但我想要垂直(从上到下) - Animation going horizontally from left to right but I want vertical (top to bottom) 如何在TextFormField的左上角开始文本 - How to start text in the left top corner in TextFormField 在脚手架的右上角放置一个 IconButton - Place an IconButton on the top right corner of your scaffold 如何将图标对齐到容器的右上角 - how to align icon to the top right corner of the Container 如何添加 ontap 功能? (我想导航到另一个页面) - How to add a ontap funtion? (I want to navigate to another page) 如何将图像放在顶角并在 flutter 中对其进行修剪? - How to put image on top corner and trim it in flutter? 右上角和左上角的 Alignment 在页面顶部没有完全对齐 | flutter - The Alignment on top Right and top Left are not exactly Align on the top of the page | flutter 如何在颤动按钮的右上角获得可点击的图标? - How can I get a clickable icon on the top right corner of a button in flutter? 使用 Flutter 的 Cupertino 小部件,我如何触发底部标签栏顶部的水平页面转换 - Using Flutter's Cupertino widgets, how do I trigger a horizontal page transition on top of bottom tab bars
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM