Animation Hero

 import "package:flutter/material.dart";


void main() {
runApp(const MyApp(),);
}
class MyApp extends StatelessWidget {
const MyApp({super.key});

@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: "Hero Animation in Flutter",
theme: ThemeData(
primarySwatch: Colors.deepPurple,
),
home: const AnimationHero(),
);
}
}
class AnimationHero extends StatefulWidget {
const AnimationHero({super.key});

@override
State<AnimationHero> createState() {
return HeroState();
}
}
class HeroState extends State<AnimationHero> {

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text("Hero Animation"),
),
body: Container(
child: Center(
child: InkWell(
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) {
return DetailPage();
},
),
);
},
child: Hero(
tag: "background", //tag must be the same in both "Hero" widget
child: Image.asset("assets/images/oliver_sea.jpg", width: 150, height: 100,),
),
),
),
),
);
}
}
class DetailPage extends StatelessWidget {
const DetailPage({super.key});

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text("Detail page"),
),
body: Container(
child: Hero(
tag: "background", //tag must be the same in both "Hero" widget
child: Image.asset("assets/images/oliver_sea.jpg"),
),
),
);
}
}

Comments

Popular posts from this blog

Second GET API Calling with Bloc simple Example in Flutter

Stack Container Scrollable Card widget UI with Custom Widget

Pagination with Bloc Pattern in Flutter