Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dynamic AppBar of Flutter

Tags:

flutter

dart

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.

like image 920
Vyacheslav Avatar asked Oct 17 '25 17:10

Vyacheslav


1 Answers

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
  ),
)
like image 64
Rémi Rousselet Avatar answered Oct 20 '25 15:10

Rémi Rousselet



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!