Yes, you can leave a stream open.
but it will impact your app performance and in my opinion it's a complex approach for a simple callback action.
Here's what i would do:
** in the Drawer's page:
// add a callback parameter
final Function(Widget w) onItemTap;
// add the callback to the drawer's constructor
Drawer(this.onItemTap);
** in The Drawer's gesture detector:
// on tapping on an item, send this callback to the page where you have instantiated the drawer page.
onTap(){ widget.onItemTap( WidgetToShow() ) },
Now when you instantiate the drawer class anywhere in your mainscreen you have a callback parameter you can use like this:
Drawer( onItemTap:(Widget w){
// now you have your widget in the mainScreen, do as you want with it
} )
So here's your final drawer/menu's code:
class Drawer extends StatefulWidget {
final Function(Widget w) onItemTap;
Drawer(this.onItemTap);
}
// ....
GestureDetector(
onTap: (){ return widget.onItemTap( WidgetToShow() ); },
),
// ...
and here's your main screen code:
// ...
stack(
children:[
Drawer( onItemTap:(Widget w){
// now you have your widget in the mainScreen, do as you want with it
} ),
]
),
//...
Hope that helped :)
short answer? Yes, you can leave a stream open.
but it will impact your app performance and in my opinion it's a complex approach for a simple callback action.
Here's what i would do:
** in the Drawer's page:
// add a callback parameter
final Function(Widget w) onItemTap;
// add the callback to the drawer's constructor
Drawer(this.onItemTap);
** in The Drawer's gesture detector:
// on tapping on an item, send this callback to the page where you have instantiated the drawer page.
onTap(){ widget.onItemTap( WidgetToShow() ) },
Now when you instantiate the drawer class anywhere in your mainscreen you have a callback parameter you can use like this:
Drawer( onItemTap:(Widget w){
// now you have your widget in the mainScreen, do as you want with it
} )
So here's your final drawer/menu's code:
class Drawer extends StatefulWidget {
final Function(Widget w) onItemTap;
Drawer(this.onItemTap);
}
// ....
GestureDetector(
onTap: (){ return widget.onItemTap( WidgetToShow() ); },
),
// ...
and here's your main screen code:
// ...
stack(
children:[
Drawer( onItemTap:(Widget w){
// now you have your widget in the mainScreen, do as you want with it
} ),
]
),
//...
Hope that helped :)