I would like to use an enhanced enum in flutter to supply the widget and app bar to be used on a scaffold with bottom navigation.
Will it lead to performance issues? Will the classes get instantiated each time I use the enum anywhere in the code?
Example for the enum:
enum BottomNavPage {
foo(widget: const FooWidget(), appBar: const FooAppBar()),
bar(widget: const BarWidget(), appBar: const BarAppBar());
final Widget widget;
final AppBar appBar;
const BottomNavPage({this.widget, this.appBar});
}
This is how it might be used in the code (e.g. inside a stateful widget):
Widget build(BuildContext context) {
return Scaffold(
appBar: _currentPage.appBar,
body: _currentPage.widget,
bottomNavigationBar: BottomNavBarWidget());
}
So far so good. Would below examples create new instances of FooWidget
and BarWidget
each time it is used somewhere?
// Setting a new Page
setState(() => _currentPage = BottomNavPage.foo);
// Action based on current page
switch(_currentPage) {
case BottomNavPage.foo:
// Do something
break;
case BottomNavPage.bar:
default:
// Something else
break;
}