[Flutter] ์• ๋‹ˆ๋ฉ”์ด์…˜ ํŽ˜์ด์ง€(๋ผ์šฐํ„ฐ) ์ด๋™ํ•˜๋Š”๋ฒ• - Animate a page route transition

2023. 3. 2. 01:45ยท Flutter/์ผ๋ฐ˜

 

๋‚˜๋Š” ํ”Œ๋Ÿฌํ„ฐ๋ฅผ ๋ฐฐ์šธ๋•Œ 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

 

์ €์ž‘์žํ‘œ์‹œ ๋น„์˜๋ฆฌ ๋ณ€๊ฒฝ๊ธˆ์ง€ (์ƒˆ์ฐฝ์—ด๋ฆผ)
'Flutter/์ผ๋ฐ˜' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€
  • [Flutter] GetX์™€ Provider์˜ ์ฐจ์ด
  • [Flutter] ํ•ธ๋“œํฐ ์ƒ๋‹จ๋ฐ” ๊ธ€์”จ ์ƒ‰๊น” ๋ณ€๊ฒฝํ•˜๊ธฐ
  • [Flutter] ์—ฌ๋Ÿฌ ์ด๋ฏธ์ง€๋ฅผ ๋ถˆ๋Ÿฌ์˜ฌ๋•Œ map์„ ์‚ฌ์šฉํ•˜์—ฌ ์‰ฝ๊ฒŒ ๋ถˆ๋Ÿฌ์˜ค๊ธฐ
  • [Flutter] GestureDetector ์‚ฌ์šฉ๋ฒ• - ์œ„์ ฏ์„ ๋งˆ์šฐ์Šค๋กœ ์ด๋™ํ•˜๋Š”๋ฒ•
Hac. Dog ๐ŸŒญ
Hac. Dog ๐ŸŒญ
Hello World
Hac. Dog ๐ŸŒญ
Hac. Dog : Blog
Hac. Dog ๐ŸŒญ
์ „์ฒด
์˜ค๋Š˜
์–ด์ œ
  • ๋ถ„๋ฅ˜ ์ „์ฒด๋ณด๊ธฐ (21)
    • Flutter (18)
      • ์ผ๋ฐ˜ (11)
      • pakages (7)
    • Google PlayStore (1)
    • Python (1)

๊ณต์ง€์‚ฌํ•ญ

hELLO ยท Designed By ์ •์ƒ์šฐ
๊ธ€์“ฐ๊ธฐ / ๊ด€๋ฆฌ์ž
Hac. Dog ๐ŸŒญ
[Flutter] ์• ๋‹ˆ๋ฉ”์ด์…˜ ํŽ˜์ด์ง€(๋ผ์šฐํ„ฐ) ์ด๋™ํ•˜๋Š”๋ฒ• - Animate a page route transition
์ƒ๋‹จ์œผ๋กœ

ํ‹ฐ์Šคํ† ๋ฆฌํˆด๋ฐ”

๋‹จ์ถ•ํ‚ค

๋‚ด ๋ธ”๋กœ๊ทธ

๋‚ด ๋ธ”๋กœ๊ทธ - ๊ด€๋ฆฌ์ž ํ™ˆ ์ „ํ™˜
Q
Q
์ƒˆ ๊ธ€ ์“ฐ๊ธฐ
W
W

๋ธ”๋กœ๊ทธ ๊ฒŒ์‹œ๊ธ€

๊ธ€ ์ˆ˜์ • (๊ถŒํ•œ ์žˆ๋Š” ๊ฒฝ์šฐ)
E
E
๋Œ“๊ธ€ ์˜์—ญ์œผ๋กœ ์ด๋™
C
C

๋ชจ๋“  ์˜์—ญ

์ด ํŽ˜์ด์ง€์˜ URL ๋ณต์‚ฌ
S
S
๋งจ ์œ„๋กœ ์ด๋™
T
T
ํ‹ฐ์Šคํ† ๋ฆฌ ํ™ˆ ์ด๋™
H
H
๋‹จ์ถ•ํ‚ค ์•ˆ๋‚ด
Shift + /
โ‡ง + /

* ๋‹จ์ถ•ํ‚ค๋Š” ํ•œ๊ธ€/์˜๋ฌธ ๋Œ€์†Œ๋ฌธ์ž๋กœ ์ด์šฉ ๊ฐ€๋Šฅํ•˜๋ฉฐ, ํ‹ฐ์Šคํ† ๋ฆฌ ๊ธฐ๋ณธ ๋„๋ฉ”์ธ์—์„œ๋งŒ ๋™์ž‘ํ•ฉ๋‹ˆ๋‹ค.