Last active
September 23, 2022 15:09
-
-
Save pingbird/13fa1c22cccd9042ab6ad457d7cac297 to your computer and use it in GitHub Desktop.
This file contains hidden or 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'; | |
void main() { | |
runApp(const MyApp()); | |
} | |
class MyApp extends StatelessWidget { | |
const MyApp({Key? key}) : super(key: key); | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
theme: ThemeData.dark(), | |
debugShowCheckedModeBanner: false, | |
home: const MyHomePage(), | |
); | |
} | |
} | |
class MyHomePage extends StatefulWidget { | |
const MyHomePage({Key? key}) : super(key: key); | |
@override | |
State<MyHomePage> createState() => _MyHomePageState(); | |
} | |
class _MyHomePageState extends State<MyHomePage> { | |
var open = false; | |
@override | |
Widget build(BuildContext context) { | |
final slider = TweenAnimationBuilder<double>( | |
tween: Tween(begin: -1.0, end: open ? 0.0 : -1.0), | |
duration: const Duration(milliseconds: 200), | |
curve: Curves.ease, | |
builder: (context, value, child) { | |
return FractionalTranslation( | |
translation: Offset(0, value), | |
child: const SizedBox( | |
width: 300, | |
height: 200, | |
child: Card( | |
child: Center(child: Text('Hello, World!')), | |
), | |
), | |
); | |
}, | |
); | |
return Scaffold( | |
backgroundColor: Colors.white, | |
body: GestureDetector( | |
onTap: () { | |
setState(() { | |
open = !open; | |
}); | |
}, | |
behavior: HitTestBehavior.opaque, | |
child: Center( | |
child: Container( | |
decoration: BoxDecoration( | |
border: Border.all(color: Colors.black12), | |
), | |
child: slider, | |
), | |
), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment