Reputation: 27221
I have to change AppBar appearance and items dynamically (by tapping on another UI elements). What is the best approach?
I tested several methods. For example,
return Scaffold(
appBar: StreamBuilder(
stream: bloc.tasks,
builder: (context, AsyncSnapshot<List<UserTask>> tasks) {
return new AppBar();/// my setup is here
}),
but this is obviously doesn't compile.
Upvotes: 4
Views: 5836
Reputation: 277707
appBar
requires a widget that implements PreferredSizeWidget
, and StreamBuilder
isn't one.
You can wrap that tree into a PreferredSize
:
Scaffold(
appBar: PreferredSize(
preferredSize: const Size(double.infinity, kToolbarHeight),
child: // StreamBuilder
),
)
Upvotes: 25