Comments (6)
RPReplay_Final1717406215.MP4
from flutter.
I think things are running correctly, but the speed of the page transition makes it appear as if the square has moved prior to animating in.
To wait for the page animation to finish before starting your animation, you can use ModalRoute.of(context).animation:
import 'package:flutter/material.dart';
import 'package:flutter/scheduler.dart';
class BugApp extends StatelessWidget {
const BugApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(onGenerateRoute: (settings) {
return MaterialPageRoute(builder: (context) => const Bug());
});
}
}
class Bug extends StatefulWidget {
const Bug({super.key});
@override
State<StatefulWidget> createState() => _BugState();
}
class _BugState extends State<Bug> with SingleTickerProviderStateMixin {
static final tween = Tween(begin: Offset.zero, end: const Offset(1, 0));
late final AnimationController _controller;
late final Animation<Offset> _animation;
Animation<double>? _routeAnimation;
@override
void initState() {
super.initState();
_controller = AnimationController(
duration: const Duration(seconds: 2),
vsync: this,
);
_animation = tween.animate(_controller);
}
@override
void didChangeDependencies() {
super.didChangeDependencies();
if (_routeAnimation == null) {
_routeAnimation =
ModalRoute.of(context)?.animation ?? kAlwaysCompleteAnimation;
_routeAnimation!.addStatusListener(_handleAnimationStatusChange);
}
}
@override
void dispose() {
_routeAnimation?.removeStatusListener(_handleAnimationStatusChange);
_routeAnimation = null;
_controller.dispose();
super.dispose();
}
void _handleAnimationStatusChange(AnimationStatus status) {
if (status == AnimationStatus.completed) {
_controller.forward();
}
}
@override
Widget build(BuildContext context) {
timeDilation = 10; // This allows you to view the animation in slow motion.
final size = MediaQuery.sizeOf(context);
return Scaffold(
appBar: AppBar(
title: const Text("animation"),
),
body: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
SlideTransition(
position: _animation,
child: Container(
width: size.width / 2,
height: size.width / 2,
color: Colors.grey,
),
),
TextButton(
onPressed: () {
Navigator.of(context).push(
MaterialPageRoute(builder: (context) => const Bug()),
);
},
child: const Text("Push new page"),
)
],
),
);
}
}
from flutter.
@StanleyCocos Check above and see if it helps in your case or not.
from flutter.
Thank you very much, this solution is perfect
from flutter.
Closing as resolved.
from flutter.
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v
and a minimal reproduction of the issue.
from flutter.
Related Issues (20)
- icons paint incorrectly on macOS HOT 6
- [Docs] Hotfixes-to-the-Stable-Channel.md HOT 3
- TestGesture.cancel doesn't invoke Drag.cancel in test
- Bad UTF-8 encoding (U+FFFD; REPLACEMENT CHARACTER) found while decoding string: �
- [pigeon] Add APIs for reading Linux Host response objects
- [webview_flutter_android] onNavigationRequest dosn't callback on Android
- [Impeller] dl_dispatcher needs a way to bail out of rendering due to errors.
- mac-3 lost external connection phone device. HOT 1
- mac-3 lost external connection phone device. HOT 1
- [Impeller] Test surface texture based external textures with Vulkan.
- linux-51 is dead. HOT 1
- Flutter engine presubmit `Linux linux_web_engine` fails with `code = InvalidArgument desc = build.summary_markdown: too big to accept (6555 > 4000 bytes)` HOT 3
- [macOS] platformview can't click if debugRepaintRainbowEnabled enabled HOT 1
- mac-25 lost external connection phone device. HOT 1
- [Android] TextField & TextFormField External keyboard number pad enter key is not trigger onSubmitted & onFieldSubmitted HOT 3
- X Error: Unable to run "adb", check your Android SDK installation and ANDROID_HOME environment variable: C:\Users\ahmed\AppData\Local\Android\Sdk\platform-tools\adb.exe
- Avoid release builds from timing out
- Take platform screenshots on Android
- mac-29 lost external connection phone device. HOT 1
- Flutter App Displays Blank White UI on iOS 14 & 15, but Works Fine on Android and Other iOS Versions
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from flutter.