
๋๋ ํ๋ฌํฐ๋ฅผ ๋ฐฐ์ธ๋ Navigator.of(context).push()๋ฅผ ํตํด ๋จ์ ํ์ด์ง ์ ํ๋ง ๋๋์ค ์์๋ค.
ํ์ง๋ง ๊ณต์๋ฌธ์๋ฅผ ๋ณด๋์ค PageRouteBuilder๋ฅผ ํตํด ์ ํ์ ์ข๋ ๋ ํนํ๊ฒ ํ ์ ์๋ค๋๊ฒ์ ์์๋ค.
์ฌ์ฉ๋ฒ์ ๋งค์ฐ ๊ฐ๋จํ๋ค.
Route _createRoute() {
return PageRouteBuilder(
pageBuilder: (context, animation, secondaryAnimation) => const Page2(),
transitionsBuilder: (context, animation, secondaryAnimation, child) {
const begin = Offset(0.0, 1.0);
const end = Offset.zero;
final tween = Tween(begin: begin, end: end);
final offsetAnimation = animation.drive(tween);
return child;
},
);
}
์ ์ฝ๋๊ฐ ์ถ๊ฐํด์ฃผ๋ฉด ๋๋ค.
์ํ์ด์ง๊ฐ ๋ฐ์์๋ถํฐ ์์ชฝ์ผ๋ก ์ฌ๋ผ์ค๊ฒ ๋๋ฏ๋ก offset์ ์ฃผ๊ฒ ๋๋ค.
begin ๋๋ end ๊ฐ์ (0.0~1.0) ๊ฐ์ผ๋ก ์ค์
์ด๋ CurveTween์ ์ฌ์ฉํ์ฌ ํจ๊ณผ๋ฅผ ์ค์ ์๋ค.
var curve = Curves.ease;
var curveTween = CurveTween(curve: curve);
์ ์ฒด์ฝ๋
import 'package:flutter/material.dart';
void main() => runApp(
MyApp(),
);
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: HomeScreen(),
);
}
}
class HomeScreen extends StatelessWidget {
const HomeScreen({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(),
body: Center(
child: ElevatedButton(
onPressed: () {
Navigator.of(context).push(
_createRoute(),
);
},
child: Text('Go'),
),
),
);
}
}
// https://docs.flutter.dev/cookbook/animation/page-route-animation
// ์ค๊ฐ์์ ํ์ด์ง์ด๋์ ํจ๊ณผ๋ฅผ ์ค์ ์์
Route _createRoute() {
return PageRouteBuilder(
pageBuilder: (context, animation, secondaryAnimation) => Page2(),
transitionsBuilder: (context, animation, secondaryAnimation, child) {
const begin = Offset(0.0, 1.0);
const end = Offset.zero;
const curve = Curves.ease;
final tween = Tween(begin: begin, end: end);
final curvedAnimation = CurvedAnimation(parent: animation, curve: curve);
return SlideTransition(
position: tween.animate(curvedAnimation),
child: child,
);
},
);
}
class Page2 extends StatelessWidget {
const Page2({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(),
body: Center(
child: Text('Page 2'),
),
);
}
}
์ ๋ด์ฉ์ ๊ณต์๋ฌธ์๋ฅผ ์ฐธ๊ณ ํ์ฌ ์์ฑํ์์ต๋๋ค.
https://docs.flutter.dev/cookbook/animation/page-route-animation
Animate a page route transition
How to animate from one page to another.
docs.flutter.dev

๋๋ ํ๋ฌํฐ๋ฅผ ๋ฐฐ์ธ๋ Navigator.of(context).push()๋ฅผ ํตํด ๋จ์ ํ์ด์ง ์ ํ๋ง ๋๋์ค ์์๋ค.
ํ์ง๋ง ๊ณต์๋ฌธ์๋ฅผ ๋ณด๋์ค PageRouteBuilder๋ฅผ ํตํด ์ ํ์ ์ข๋ ๋ ํนํ๊ฒ ํ ์ ์๋ค๋๊ฒ์ ์์๋ค.
์ฌ์ฉ๋ฒ์ ๋งค์ฐ ๊ฐ๋จํ๋ค.
Route _createRoute() { return PageRouteBuilder( pageBuilder: (context, animation, secondaryAnimation) => const Page2(), transitionsBuilder: (context, animation, secondaryAnimation, child) { const begin = Offset(0.0, 1.0); const end = Offset.zero; final tween = Tween(begin: begin, end: end); final offsetAnimation = animation.drive(tween); return child; }, ); }
์ ์ฝ๋๊ฐ ์ถ๊ฐํด์ฃผ๋ฉด ๋๋ค.
์ํ์ด์ง๊ฐ ๋ฐ์์๋ถํฐ ์์ชฝ์ผ๋ก ์ฌ๋ผ์ค๊ฒ ๋๋ฏ๋ก offset์ ์ฃผ๊ฒ ๋๋ค.
begin ๋๋ end ๊ฐ์ (0.0~1.0) ๊ฐ์ผ๋ก ์ค์
์ด๋ CurveTween์ ์ฌ์ฉํ์ฌ ํจ๊ณผ๋ฅผ ์ค์ ์๋ค.
var curve = Curves.ease; var curveTween = CurveTween(curve: curve);
์ ์ฒด์ฝ๋
import 'package:flutter/material.dart'; void main() => runApp( MyApp(), ); class MyApp extends StatelessWidget { const MyApp({super.key}); @override Widget build(BuildContext context) { return MaterialApp( debugShowCheckedModeBanner: false, home: HomeScreen(), ); } } class HomeScreen extends StatelessWidget { const HomeScreen({super.key}); @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar(), body: Center( child: ElevatedButton( onPressed: () { Navigator.of(context).push( _createRoute(), ); }, child: Text('Go'), ), ), ); } } // https://docs.flutter.dev/cookbook/animation/page-route-animation // ์ค๊ฐ์์ ํ์ด์ง์ด๋์ ํจ๊ณผ๋ฅผ ์ค์ ์์ Route _createRoute() { return PageRouteBuilder( pageBuilder: (context, animation, secondaryAnimation) => Page2(), transitionsBuilder: (context, animation, secondaryAnimation, child) { const begin = Offset(0.0, 1.0); const end = Offset.zero; const curve = Curves.ease; final tween = Tween(begin: begin, end: end); final curvedAnimation = CurvedAnimation(parent: animation, curve: curve); return SlideTransition( position: tween.animate(curvedAnimation), child: child, ); }, ); } class Page2 extends StatelessWidget { const Page2({super.key}); @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar(), body: Center( child: Text('Page 2'), ), ); } }
์ ๋ด์ฉ์ ๊ณต์๋ฌธ์๋ฅผ ์ฐธ๊ณ ํ์ฌ ์์ฑํ์์ต๋๋ค.
https://docs.flutter.dev/cookbook/animation/page-route-animation
Animate a page route transition
How to animate from one page to another.
docs.flutter.dev