Search code examples
flutterappbar

centering text in appbar vertically - Flutter


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


Solution

  • 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