Tutorial and code of Liquid Shrink SideMenu in Flutter. Copy and paste the below code as per your requirements.
shrink_sidemenu: ^2.0.0+2-null-safety
import 'package:flutter/material.dart';
import 'package:shrink_sidemenu/shrink_sidemenu.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Liquid Shrink SideMenu',
theme: ThemeData(
primarySwatch: Colors.blue,
visualDensity: VisualDensity.adaptivePlatformDensity,
),
home: const MyHomePage(title: 'Liquid Ui Shrink SideMenus'),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({Key? key, required this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;
bool isOpened = false;
final GlobalKey<SideMenuState> _sideMenuKey = GlobalKey<SideMenuState>();
final GlobalKey<SideMenuState> _endSideMenuKey = GlobalKey<SideMenuState>();
void _incrementCounter() {
setState(() {
_counter++;
});
}
toggleMenu([bool end = false]) {
if (end) {
final _state = _endSideMenuKey.currentState!;
if (_state.isOpened) {
_state.closeSideMenu();
} else {
_state.openSideMenu();
}
} else {
final _state = _sideMenuKey.currentState!;
if (_state.isOpened) {
_state.closeSideMenu();
} else {
_state.openSideMenu();
}
}
}
@override
Widget build(BuildContext context) {
return SideMenu(
key: _endSideMenuKey,
inverse: true, // end side menu
background: Colors.green[700],
type: SideMenuType.slideNRotate,
menu: Padding(
padding: const EdgeInsets.only(left: 25.0),
child: buildMenu(),
),
onChange: (_isOpened) {
setState(() => isOpened = _isOpened);
},
child: SideMenu(
key: _sideMenuKey,
menu: buildMenu(),
type: SideMenuType.slideNRotate,
onChange: (_isOpened) {
setState(() => isOpened = _isOpened);
},
child: IgnorePointer(
ignoring: isOpened,
child: Scaffold(
appBar: AppBar(
centerTitle: true,
leading: IconButton(
icon: const Icon(Icons.menu),
onPressed: () => toggleMenu(),
),
actions: [
IconButton(
icon: const Icon(Icons.menu),
onPressed: () => toggleMenu(true),
)
],
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
const Text(
'You have pushed the button this many times:',
),
Text(
'$_counter',
style: Theme.of(context).textTheme.headline4,
),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: const Icon(Icons.add),
),
),
),
),
);
}
Widget buildMenu() {
return SingleChildScrollView(
padding: const EdgeInsets.symmetric(vertical: 50.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding(
padding: const EdgeInsets.only(left: 16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: const [
CircleAvatar(
backgroundColor: Colors.white,
radius: 22.0,
),
SizedBox(height: 16.0),
Text(
"Hello, John Doe",
style: TextStyle(color: Colors.white),
),
SizedBox(height: 20.0),
],
),
),
ListTile(
onTap: () {},
leading: const Icon(Icons.home, size: 20.0, color: Colors.white),
title: const Text("Home"),
textColor: Colors.white,
dense: true,
),
ListTile(
onTap: () {},
leading: const Icon(Icons.verified_user,
size: 20.0, color: Colors.white),
title: const Text("Profile"),
textColor: Colors.white,
dense: true,
),
ListTile(
onTap: () {},
leading: const Icon(Icons.monetization_on,
size: 20.0, color: Colors.white),
title: const Text("Wallet"),
textColor: Colors.white,
dense: true,
),
ListTile(
onTap: () {},
leading: const Icon(Icons.shopping_cart,
size: 20.0, color: Colors.white),
title: const Text("Cart"),
textColor: Colors.white,
dense: true,
),
ListTile(
onTap: () {},
leading:
const Icon(Icons.star_border, size: 20.0, color: Colors.white),
title: const Text("Favorites"),
textColor: Colors.white,
dense: true,
),
ListTile(
onTap: () {},
leading:
const Icon(Icons.settings, size: 20.0, color: Colors.white),
title: const Text("Settings"),
textColor: Colors.white,
dense: true,
),
],
),
);
}
}