Home > Enterprise >  Setting the height of the actions inside appbar in flutter
Setting the height of the actions inside appbar in flutter

Time:01-06

I want to be able to set the height of the individual actions to be a desired height not greater than the appbar height, but it isn't letting me do that, as it forces the height to be exactly the same as the appbar.

Here's a screenshot : -

Here's a reproducible code:

class HomeScreen extends StatelessWidget{
const HomeScreen({Key key}) : super(key: key);
@override
    Widget build(BuildContext context) {
        return Scaffold(
            appBar:AppBar(
            title:Text('Home'),
            actions:[
                Container(color:Colors.red,height:20,child:Text('HI'))
            ]
            ),
        );
    }
}

CodePudding user response:

Try below code and use alignment inside Container hope its help to you

 AppBar(
      title: Text('Home'),
      actions: [
        SizedBox(
          width: 20.0,
          height: 20.0,
          child: Align(
            alignment: Alignment.center,
            child: Container(
              alignment: Alignment.center,
              width: 20.0,
              height: 20.0,
              color: Colors.red,
              child: const Text('HI'),
            ),
          ),
        ),
        const Icon(Icons.person),
        const Icon(Icons.notifications),
      ],
    ),

Result-> image

  • Related