Created
November 18, 2022 09:47
-
-
Save quangpd/86290f208c3ccb89bea94763c23bd94a to your computer and use it in GitHub Desktop.
DraggableScrollableSheet open-close with animation
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
https://stackoverflow.com/a/57233951/794445 | |
https://i.stack.imgur.com/qK0dN.gif | |
class HomePage extends StatefulWidget { | |
@override | |
_HomePageState createState() => _HomePageState(); | |
} | |
class _HomePageState extends State<HomePage> with SingleTickerProviderStateMixin { | |
AnimationController _controller; | |
Duration _duration = Duration(milliseconds: 500); | |
Tween<Offset> _tween = Tween(begin: Offset(0, 1), end: Offset(0, 0)); | |
@override | |
void initState() { | |
super.initState(); | |
_controller = AnimationController(vsync: this, duration: _duration); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
floatingActionButton: GestureDetector( | |
child: FloatingActionButton( | |
child: AnimatedIcon(icon: AnimatedIcons.menu_close, progress: _controller), | |
elevation: 5, | |
backgroundColor: Colors.deepOrange, | |
foregroundColor: Colors.white, | |
onPressed: () async { | |
if (_controller.isDismissed) | |
_controller.forward(); | |
else if (_controller.isCompleted) | |
_controller.reverse(); | |
}, | |
), | |
), | |
body: SizedBox.expand( | |
child: Stack( | |
children: <Widget>[ | |
FlutterLogo(size: 500), | |
SizedBox.expand( | |
child: SlideTransition( | |
position: _tween.animate(_controller), | |
child: DraggableScrollableSheet( | |
builder: (BuildContext context, ScrollController scrollController) { | |
return Container( | |
color: Colors.blue[800], | |
child: ListView.builder( | |
controller: scrollController, | |
itemCount: 25, | |
itemBuilder: (BuildContext context, int index) { | |
return ListTile(title: Text('Item $index')); | |
}, | |
), | |
); | |
}, | |
), | |
), | |
), | |
], | |
), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment