mirror of
https://github.com/AyanDas-99/Flutter-animations.git
synced 2025-08-23 22:16:24 +08:00
lecture 4 done, created hero animation
This commit is contained in:
114
lib/Screens/lecture4.dart
Normal file
114
lib/Screens/lecture4.dart
Normal file
@ -0,0 +1,114 @@
|
|||||||
|
// ignore_for_file: public_member_api_docs, sort_constructors_first
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter/src/widgets/framework.dart';
|
||||||
|
import 'package:flutter/src/widgets/placeholder.dart';
|
||||||
|
|
||||||
|
class Person {
|
||||||
|
final String name;
|
||||||
|
final String age;
|
||||||
|
final String emoji;
|
||||||
|
Person({
|
||||||
|
required this.name,
|
||||||
|
required this.age,
|
||||||
|
required this.emoji,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
final people = [
|
||||||
|
Person(name: "Ayan", age: '20', emoji: '👨'),
|
||||||
|
Person(name: "Daddu", age: '20', emoji: '👴'),
|
||||||
|
Person(name: "Thakur ji", age: '20', emoji: '👮'),
|
||||||
|
Person(name: "Angela", age: '20', emoji: '👼'),
|
||||||
|
];
|
||||||
|
|
||||||
|
class Lecture4 extends StatefulWidget {
|
||||||
|
final String title;
|
||||||
|
const Lecture4({
|
||||||
|
Key? key,
|
||||||
|
required this.title,
|
||||||
|
}) : super(key: key);
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<Lecture4> createState() => _Lecture4State();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _Lecture4State extends State<Lecture4> {
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Scaffold(
|
||||||
|
appBar: AppBar(title: Text(widget.title)),
|
||||||
|
body: ListView.builder(
|
||||||
|
itemCount: people.length,
|
||||||
|
itemBuilder: (context, index) {
|
||||||
|
Person person = people[index];
|
||||||
|
return InkWell(
|
||||||
|
onTap: () => Navigator.push(
|
||||||
|
context,
|
||||||
|
MaterialPageRoute(
|
||||||
|
builder: (context) => Details(person: people[index]),
|
||||||
|
)),
|
||||||
|
child: ListTile(
|
||||||
|
leading: Hero(
|
||||||
|
tag: person.name,
|
||||||
|
child: Text(
|
||||||
|
person.emoji,
|
||||||
|
style: TextStyle(fontSize: 30),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
title: Text(person.name),
|
||||||
|
subtitle: Text("${person.age} years old"),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class Details extends StatelessWidget {
|
||||||
|
final Person person;
|
||||||
|
|
||||||
|
const Details({super.key, required this.person});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Scaffold(
|
||||||
|
appBar: AppBar(
|
||||||
|
centerTitle: true,
|
||||||
|
title: Hero(
|
||||||
|
flightShuttleBuilder: (flightContext, animation, flightDirection,
|
||||||
|
fromHeroContext, toHeroContext) {
|
||||||
|
switch (flightDirection) {
|
||||||
|
case HeroFlightDirection.push:
|
||||||
|
return Material(
|
||||||
|
color: Colors.transparent, child: fromHeroContext.widget);
|
||||||
|
break;
|
||||||
|
case HeroFlightDirection.pop:
|
||||||
|
return Material(
|
||||||
|
color: Colors.transparent, child: toHeroContext.widget);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
tag: person.name,
|
||||||
|
child: Text(
|
||||||
|
person.emoji,
|
||||||
|
style: TextStyle(fontSize: 40),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
body: Center(
|
||||||
|
child: Column(
|
||||||
|
children: [
|
||||||
|
SizedBox(
|
||||||
|
height: 20,
|
||||||
|
),
|
||||||
|
Text(person.name),
|
||||||
|
SizedBox(
|
||||||
|
height: 20,
|
||||||
|
),
|
||||||
|
Text("${person.age} years old")
|
||||||
|
],
|
||||||
|
)),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
26
lib/Screens/lecture5.dart
Normal file
26
lib/Screens/lecture5.dart
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
// ignore_for_file: public_member_api_docs, sort_constructors_first
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter/src/widgets/framework.dart';
|
||||||
|
import 'package:flutter/src/widgets/placeholder.dart';
|
||||||
|
|
||||||
|
class Lecture5 extends StatefulWidget {
|
||||||
|
final String title;
|
||||||
|
const Lecture5({
|
||||||
|
Key? key,
|
||||||
|
required this.title,
|
||||||
|
}) : super(key: key);
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<Lecture5> createState() => _Lecture5State();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _Lecture5State extends State<Lecture5> {
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Scaffold(
|
||||||
|
appBar: AppBar(
|
||||||
|
title: Text(widget.title),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -3,6 +3,7 @@ import 'dart:math';
|
|||||||
|
|
||||||
import 'package:animations/Screens/lecture2.dart';
|
import 'package:animations/Screens/lecture2.dart';
|
||||||
import 'package:animations/Screens/lecture3.dart';
|
import 'package:animations/Screens/lecture3.dart';
|
||||||
|
import 'package:animations/Screens/lecture4.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
import 'Screens/lecture1.dart';
|
import 'Screens/lecture1.dart';
|
||||||
@ -35,6 +36,7 @@ class MyApp extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
'lec3/': (context) =>
|
'lec3/': (context) =>
|
||||||
const Lecture3(title: "3D Animation, Stack and rotate widgets"),
|
const Lecture3(title: "3D Animation, Stack and rotate widgets"),
|
||||||
|
'lec4/': (context) => const Lecture4(title: "Hero Animation"),
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -68,6 +70,7 @@ class _MyHomePageState extends State<MyHomePage> {
|
|||||||
Link(
|
Link(
|
||||||
link: 'lec3/',
|
link: 'lec3/',
|
||||||
title: "3D Animations, Stack and rotate widgets"),
|
title: "3D Animations, Stack and rotate widgets"),
|
||||||
|
Link(link: 'lec4/', title: 'Hero Animations'),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
Reference in New Issue
Block a user