[英]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.