Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Place container instead of AppBar

I need to remove an app bar if a state changes in my app and I need to place a container at the top that will allow me text with custom description. I am trying to place a conditional statement before appBar but it doesn’t allow me to. Are there other alternatives?

   return SafeArea(
      child: Scaffold(
          context.watch<UseData>().hideBar == false ? appBar:
        AppBar(
          // automaticallyImplyLeading: false,
          title:
          Text("Test", style: TextStyle(
              color: Colors.black
          )),
          centerTitle: true,
 
          bottomOpacity: 0,
          elevation: 2,
          backgroundColor: Colors.transparent,
          iconTheme: IconThemeData(color: Colors.black),
        ) : Container(child: ...)),

Too many positional arguments: 0 expected, but 1 found. (Documentation) Try removing the extra positional arguments, or specifying the name for named arguments.

I also tried using positioned, but the top: 0 keeps staying under AppBar, I need a custom container over the app bar.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

     Positioned(
        top: 0,
        child: Container(
          child: Column(
            children: [
              Text("hi")
            ],
          )
        ),
      ),

enter image description here

>Solution :

appBar accepts PreferredSizeWidget so you can’t pass Container widget to it directly rather than just Wrap you Container into PreferredSize widget pass height inside preferredSize property as per your requirement. Check below code for reference :

return Scaffold(
      appBar: isAppBar
          ? AppBar(
              title: Text("Title Here"),
            )
          : PreferredSize(
              preferredSize: Size.fromHeight(100.00),
              child: Container(
                child: Text("Second Title"),
              ),
            ),
    );
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading