Vyacheslav
Vyacheslav

Reputation: 27221

Dynamic AppBar of Flutter

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

Answers (1)

R&#233;mi Rousselet
R&#233;mi Rousselet

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

Related Questions