Home > Blockchain >  centering text in appbar vertically - Flutter
centering text in appbar vertically - Flutter

Time:02-03

I am trying to center the text in a appbar but it just won't vertically center. I have tried many codes from google and tackoverflow and it just seems not to work. Please help and thanks in advance

appBar: AppBar(
    // centerTitle: true,
    backgroundColor: Colors.pink,
    bottom: PreferredSize(
      preferredSize: Size.fromHeight(200),
      child: SizedBox(
        height: 200,
      ),
    ),
    title: Row(mainAxisAlignment: MainAxisAlignment.center ,children: [Text('weoijf')],)
    ,
    shape: RoundedRectangleBorder(
      borderRadius: BorderRadius.vertical(bottom: Radius.circular(100))
    ),
  ),

appbar problem

CodePudding user response:

Please Find below code i think this will help you to achive what you want let me know if any query

appBar: PreferredSize(
          preferredSize: Size.fromHeight(200),
          child: AppBar(
            // centerTitle: true,
            backgroundColor: Colors.pink,
            shape: RoundedRectangleBorder(
                borderRadius: BorderRadius.vertical(bottom: Radius.circular(100))
            ),
            flexibleSpace: Container(
              alignment: Alignment.center,
              child: Text(
                'weoijf',
                style: TextStyle(
                  color: Colors.white
                ),
              ),
            ),
          ),
        )

Thanks

CodePudding user response:

You can't provide title like this But if you want to show title in center use this code:-

 appBar: AppBar(
        backgroundColor: Colors.pink,
        bottom: const PreferredSize(
          preferredSize: Size.fromHeight(200),
          child: SizedBox(
            height: 240,
            child: Center(
                child: Text(
              "weoijf",
              style: TextStyle(color: Colors.white),
            )),
          ),
        ),
        shape: const RoundedRectangleBorder(
            borderRadius: BorderRadius.vertical(bottom: Radius.circular(100))),
      ),
  •  Tags:  
  • Related