Skip to content

Instantly share code, notes, and snippets.

@sbis04
Created October 27, 2020 09:34
Show Gist options
  • Save sbis04/bf34764efa3ba8f86e254b9caebcac10 to your computer and use it in GitHub Desktop.
Save sbis04/bf34764efa3ba8f86e254b9caebcac10 to your computer and use it in GitHub Desktop.
class HomeViewLarge extends StatefulWidget {
final int currentIndex;
/// Callback function
final Function(int selectedIndex) onTapped;
HomeViewLarge(this.currentIndex, this.onTapped);
@override
_HomeViewLargeState createState() => _HomeViewLargeState();
}
class _HomeViewLargeState extends State<HomeViewLarge> {
int _index = 0;
@override
void initState() {
super.initState();
_index = widget.currentIndex;
}
@override
Widget build(BuildContext context) {
return Container(
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.start,
children: [
Expanded(
flex: 2,
child: MenuWidget(
selectedIndex: _index,
onTapped: (selectedIndex) {
setState(() {
_index = selectedIndex;
// Invoking the callback
widget.onTapped(_index);
});
},
),
),
// ...
],
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment