File tree Expand file tree Collapse file tree 5 files changed +20
-0
lines changed
Expand file tree Collapse file tree 5 files changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -71,6 +71,9 @@ List<SideMenuItem> items = [
7171 SideMenuExpansionItem(
7272 title: "Expansion Item",
7373 icon: const Icon(Icons.kitchen),
74+ onTap: (index, _, isExpanded) => {
75+ print('$index, expanded $isExpanded')
76+ },
7477 children: [
7578 SideMenuItem(
7679 title: 'Expansion Item 1',
Original file line number Diff line number Diff line change @@ -125,6 +125,9 @@ class _MyHomePageState extends State<MyHomePage> {
125125 SideMenuExpansionItem (
126126 title: "Expansion Item" ,
127127 icon: const Icon (Icons .kitchen),
128+ onTap: (index, _, isExpanded) => {
129+ print ('$index , expanded $isExpanded ' )
130+ },
128131 children: [
129132 SideMenuItem (
130133 title: 'Expansion Item 1' ,
Original file line number Diff line number Diff line change @@ -99,6 +99,7 @@ class SideMenu extends StatefulWidget {
9999 icon: data.icon,
100100 index: sideMenuExpansionItemIndex,
101101 iconWidget: data.iconWidget,
102+ onTap: data.onTap,
102103 children: data.children
103104 .map ((childData) => SideMenuItemWithGlobal (
104105 global: global,
Original file line number Diff line number Diff line change 11import 'package:flutter/material.dart' ;
22import 'package:easy_sidemenu/src/side_menu_item.dart' ;
3+ import 'package:easy_sidemenu/src/side_menu_controller.dart' ;
34
45class SideMenuExpansionItem {
56 /// #### Side Menu Item
@@ -9,6 +10,10 @@ class SideMenuExpansionItem {
910 /// name
1011 final String ? title;
1112
13+ /// A function that will be called when tap on [SideMenuExpansionItem] corresponding
14+ /// to this [SideMenuExpansionItem]
15+ final void Function (int index, SideMenuController sideMenuController, bool isExpanded)? onTap;
16+
1217 /// A Icon to display before [title]
1318 final Icon ? icon;
1419
@@ -19,6 +24,7 @@ class SideMenuExpansionItem {
1924
2025 const SideMenuExpansionItem ({
2126 Key ? key,
27+ this .onTap,
2228 this .title,
2329 this .icon,
2430 this .iconWidget,
Original file line number Diff line number Diff line change 11import 'package:flutter/material.dart' ;
22import 'package:easy_sidemenu/src/side_menu_display_mode.dart' ;
33import 'package:easy_sidemenu/src/side_menu_item_with_global.dart' ;
4+ import 'package:easy_sidemenu/src/side_menu_controller.dart' ;
45
56import 'global/global.dart' ;
67
@@ -26,12 +27,17 @@ class SideMenuExpansionItemWithGlobal extends StatefulWidget {
2627 /// for maintaining record of the state
2728 final int index;
2829
30+ /// A function that will be called when tap on [SideMenuExpansionItem] corresponding
31+ /// to this [SideMenuExpansionItem]
32+ final void Function (int index, SideMenuController sideMenuController, bool isExpanded)? onTap;
33+
2934 const SideMenuExpansionItemWithGlobal (
3035 {Key ? key,
3136 required this .global,
3237 this .title,
3338 this .icon,
3439 this .iconWidget,
40+ this .onTap,
3541 required this .index,
3642 required this .children})
3743 : assert (title != null || icon != null ,
@@ -99,6 +105,7 @@ class _SideMenuExpansionState extends State<SideMenuExpansionItemWithGlobal> {
99105 isExpanded = value;
100106 widget.global.expansionStateList[widget.index] = value;
101107 });
108+ widget.onTap? .call (widget.index, widget.global.controller, value);
102109 },
103110 trailing: Icon (
104111 isExpanded
You can’t perform that action at this time.
0 commit comments