Search code examples
flutteralignmentgoogle-signinappbar

Appbar alignment


I am looking to align the name of the user next to the Welcome Back Text. Is there any way that this can be done in one line of code? Here is what I have right now.

  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(
          brightness: Brightness.light,
          backgroundColor: Colors.white,
          elevation: 0,
          title: Text("Welcome Back", style: TextStyle(color: Color.fromRGBO(49, 39, 79, 1), fontWeight: FontWeight.bold,fontSize: 20),),
          actions: <Widget>[
            new Container(
              child: Text(
                name, style: TextStyle(color: Color.fromRGBO(49, 39, 79, 1), fontWeight: FontWeight.bold,fontSize: 20)
              ),
            ),
            Padding(
              padding: const EdgeInsets.all(8.0),
              child: CircleAvatar(
                backgroundImage: NetworkImage(
                  imageUrl,
                ),
              ),
            ),
          ]),

enter image description here


Solution

  • Use for this case Row(...)

      actions: <Widget>[
        Row(
          children: <Widget>[
            Container(
              child: Text(name, style: TextStyle(color: Color.fromRGBO(49, 39, 79, 1), fontWeight: FontWeight.bold,fontSize: 20))
            ),
            Padding(padding: const EdgeInsets.all(8.0),
              child: CircleAvatar(
                backgroundImage: NetworkImage(imageUrl),
              ),
            ),
          ],
        ),
      ]
    

    Btw: You don't need new. It is since Dart 2.0 optional.