mirror of
https://github.com/AyanDas-99/Flutter-animations.git
synced 2025-07-03 16:13:01 +08:00
added lecture 8 - 3D Drawer
This commit is contained in:
133
lib/Screens/lecture8.dart
Normal file
133
lib/Screens/lecture8.dart
Normal file
@ -0,0 +1,133 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'dart:math' show pi;
|
||||
|
||||
class Lecture8 extends StatefulWidget {
|
||||
final String title;
|
||||
const Lecture8({
|
||||
Key? key,
|
||||
required this.title,
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<Lecture8> createState() => _Lecture8State();
|
||||
}
|
||||
|
||||
class _Lecture8State extends State<Lecture8> with TickerProviderStateMixin {
|
||||
late AnimationController _xControllerForChild;
|
||||
late Animation<double> _yRotationAnimationForChild;
|
||||
|
||||
late AnimationController _xControllerForDrawer;
|
||||
late Animation<double> _yRotationAnimationForDrawer;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
_xControllerForChild =
|
||||
AnimationController(vsync: this, duration: Duration(milliseconds: 500));
|
||||
_yRotationAnimationForChild =
|
||||
Tween<double>(begin: 0, end: -pi / 2).animate(_xControllerForChild);
|
||||
|
||||
_xControllerForDrawer =
|
||||
AnimationController(vsync: this, duration: Duration(milliseconds: 500));
|
||||
_yRotationAnimationForDrawer =
|
||||
Tween<double>(begin: pi / 2.7, end: 0).animate(_xControllerForDrawer);
|
||||
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_xControllerForChild.dispose();
|
||||
_xControllerForDrawer.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final screenWidth = MediaQuery.of(context).size.width;
|
||||
final maxDrag = screenWidth * 0.8;
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(title: Text(widget.title)),
|
||||
body: AnimatedBuilder(
|
||||
animation:
|
||||
Listenable.merge([_xControllerForChild, _xControllerForDrawer]),
|
||||
builder: (context, child) => GestureDetector(
|
||||
onHorizontalDragUpdate: (details) {
|
||||
final delta = details.delta.dx / maxDrag;
|
||||
_xControllerForChild.value += delta;
|
||||
_xControllerForDrawer.value += delta;
|
||||
},
|
||||
onHorizontalDragEnd: (details) {
|
||||
if (_xControllerForChild.value < 0.5) {
|
||||
_xControllerForChild.reverse();
|
||||
_xControllerForDrawer.reverse();
|
||||
} else {
|
||||
_xControllerForChild.forward();
|
||||
_xControllerForDrawer.forward();
|
||||
}
|
||||
},
|
||||
child: Stack(
|
||||
children: [
|
||||
Transform(
|
||||
alignment: Alignment.centerLeft,
|
||||
transform: Matrix4.identity()
|
||||
..setEntry(3, 2, 0.001)
|
||||
..translate(_xControllerForChild.value * maxDrag)
|
||||
..rotateY(_yRotationAnimationForChild.value),
|
||||
child: const Home()),
|
||||
Transform(
|
||||
alignment: Alignment.centerRight,
|
||||
transform: Matrix4.identity()
|
||||
..setEntry(3, 2, 0.001)
|
||||
..translate(
|
||||
-screenWidth + _xControllerForDrawer.value * maxDrag)
|
||||
..rotateY(_yRotationAnimationForDrawer.value),
|
||||
child: const MyDrawer()),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class Home extends StatefulWidget {
|
||||
const Home({super.key});
|
||||
|
||||
@override
|
||||
State<Home> createState() => _HomeState();
|
||||
}
|
||||
|
||||
class _HomeState extends State<Home> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
color: Colors.blueGrey,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class MyDrawer extends StatefulWidget {
|
||||
const MyDrawer({super.key});
|
||||
|
||||
@override
|
||||
State<MyDrawer> createState() => _MyDrawerState();
|
||||
}
|
||||
|
||||
class _MyDrawerState extends State<MyDrawer> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Material(
|
||||
child: Container(
|
||||
color: Color.fromARGB(255, 49, 65, 73),
|
||||
child: ListView.builder(
|
||||
padding: const EdgeInsets.only(left: 80, top: 100),
|
||||
itemCount: 20,
|
||||
itemBuilder: (context, index) => ListTile(
|
||||
title: Text('Item $index'),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
20
lib/Screens/lecture9.dart
Normal file
20
lib/Screens/lecture9.dart
Normal file
@ -0,0 +1,20 @@
|
||||
// ignore_for_file: public_member_api_docs, sort_constructors_first
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class Lecture9 extends StatefulWidget {
|
||||
final String title;
|
||||
const Lecture9({
|
||||
Key? key,
|
||||
required this.title,
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<Lecture9> createState() => _Lecture9State();
|
||||
}
|
||||
|
||||
class _Lecture9State extends State<Lecture9> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return const Placeholder();
|
||||
}
|
||||
}
|
@ -6,6 +6,8 @@ import 'package:animations/Screens/lecture3.dart';
|
||||
import 'package:animations/Screens/lecture4.dart';
|
||||
import 'package:animations/Screens/lecture5.dart';
|
||||
import 'package:animations/Screens/lecture6.dart';
|
||||
import 'package:animations/Screens/lecture8.dart';
|
||||
import 'package:animations/Screens/lecture9.dart';
|
||||
import 'package:animations/Screens/practice1.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
@ -45,6 +47,10 @@ class MyApp extends StatelessWidget {
|
||||
'lec6/': (context) => const Lecture6(title: "TweenAnimationBuilder"),
|
||||
'practice1/': (context) => const Practice1(),
|
||||
'lec7/': (context) => const Lecture7(title: "CustomPainter & Polygons"),
|
||||
'lec8/': (context) => const Lecture8(title: "3D Drawer"),
|
||||
'lec9/': (context) => const Lecture9(
|
||||
title: "Animated Prompt",
|
||||
)
|
||||
},
|
||||
);
|
||||
}
|
||||
@ -85,6 +91,8 @@ class _MyHomePageState extends State<MyHomePage> {
|
||||
title: 'TweenAnimationBuilder, ClipPath, CustomClipper'),
|
||||
Link(link: 'practice1/', title: "Practice 1"),
|
||||
Link(link: 'lec7/', title: "CustomPainter & Polygons"),
|
||||
Link(link: 'lec8/', title: "3D Drawer"),
|
||||
Link(link: 'lec9/', title: "Animated Prompt"),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
Reference in New Issue
Block a user