If you want to add a beautiful sliding animation menu to your application in an easy way, you can use this package. All you need is to pass your content and drawer widgets to the SlidingDrawer.
To use the SlidingDrawer pass build functions drawerBuilder
and contentBuilder
that return drawer
and content widgets correspondingly.
You can set drawer width, animation duration and curve by using settings
argument.
Set ignorePointer
to true if you need to disable opening/closing drawer by dragging.
To respond to opening/closing drawer, API provide listener onAnimationStatusChanged
.
Supports left and right drawer position.
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key});
@override
State<StatefulWidget> createState() {
return _MyHomePageState();
}
}
class _MyHomePageState extends State<MyHomePage> {
// Optional. Provide Key<SlidingDrawerState> if you want
// to open/close the drawer in response to some action
final slidingDrawerKey = GlobalKey<SlidingDrawerState>();
@override
Widget build(BuildContext context) {
return SlidingDrawer(
key: slidingDrawerKey,
// Build content widget
contentBuilder: (context) {
return Scaffold(
appBar: AppBar(
automaticallyImplyLeading: false,
leading: IconButton(
icon: const Icon(
Icons.menu_rounded,
),
onPressed: () {
// Open drawer
slidingDrawerKey.open();
},
),
title: const Text('Home page'),
),
body: const MyHomePageBodyWidget(),
);
},
// Build drawer widget
drawerBuilder: (context) {
return MyDrawerWidget(
onItemPress: () {
// Close drawer
slidingDrawerKey.close();
}
);
},
);
}
}