Last active
January 14, 2022 10:16
-
-
Save Kurogoma4D/5358c34634910274e33fbce871106966 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
import 'package:flutter_hooks/flutter_hooks.dart'; | |
void main() => runApp(MyApp()); | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
title: 'Flutter Demo', | |
debugShowCheckedModeBanner: false, | |
theme: ThemeData(primarySwatch: Colors.blue), | |
home: const Home(), | |
); | |
} | |
} | |
class Home extends StatelessWidget { | |
const Home({Key? key}) : super(key: key); | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar(title: const Text('Animation')), | |
body: const Center(child: _Animation()), | |
); | |
} | |
} | |
const kRestitution = 0.6; | |
class _Animation extends HookWidget { | |
const _Animation({Key? key}) : super(key: key); | |
@override | |
Widget build(BuildContext context) { | |
const boxSize = 20.0; | |
final barHeight = MediaQuery.of(context).size.height * 0.8; | |
final controller = | |
useAnimationController(duration: const Duration(seconds: 3)); | |
final animation = | |
CurvedAnimation(parent: controller, curve: Curves.bounceOut); | |
return Stack( | |
children: [ | |
Container( | |
decoration: BoxDecoration( | |
border: Border.all(color: Colors.black54, width: 2.0), | |
), | |
height: barHeight, | |
width: boxSize, | |
), | |
AnimatedBuilder( | |
animation: controller, | |
builder: (context, _) { | |
return Positioned( | |
top: animation.value * (barHeight - boxSize), | |
left: 0, | |
child: GestureDetector( | |
onTap: () => controller.forward(from: 0.0), | |
child: Container( | |
height: boxSize, | |
width: boxSize, | |
color: Colors.red.withOpacity(0.54), | |
), | |
), | |
); | |
}), | |
], | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment