Skip to content

Actions in a scaffold are a different height than the menu/back icon #7185

Closed

Description

@DaveShuckerow

Steps to Reproduce

new Scaffold(
...
drawer: () => _buildADrawerSoTheAppHasAMenuButton(),
actions: () => [new Switch(...)],
);

I'm measuring the action item and menu item, and the action widget is squished up towards the top of the space it can occupy, and it takes up less vertical space. The switch and the menu appear to be top-aligned, which makes them look imbalanced.

An example:
action button: go/hsv/5051009483145216?node=95
menu button: go/hsv/5051009483145216?node=93

Activity

  1. eseidelGoogle commented on Dec 8, 2016

    @eseidelGoogle
    Contributor

    I had a similar problem last night when I tried to use an Icon widget instead of an IconButton widget in AppBar.actions. IconButton aligned properly, but Icon did not. Not sure if that's related to this or not.

    Is this blocking you?

  2. eseidelGoogle commented on Dec 8, 2016

    @eseidelGoogle
    Contributor

    Looks like our layout computation for AX information may be wrong: #7205 If you're going to use a lot of that tool, we might want to improve our AX information a bit. ;)

  3. DaveShuckerow commented on Dec 9, 2016

    @DaveShuckerow
    ContributorAuthor

    Not a blocker, but it's a UI cleanup that we'd like to do before EOY (EO next week, essentially).

    We only use it in the first page of the leafy app, as seen in the screenshot I sent you.

  4. eseidelGoogle commented on Dec 9, 2016

    @eseidelGoogle
    Contributor

    For clarity: Which alignment would you expect? Baseline? Center? @Hixie is probably the right person to ask about alignment questions. I don't see any the AppBar attempting any specific alignment:
    https://github.com/flutter/flutter/blob/master/packages/flutter/lib/src/material/app_bar.dart#L59

  5. DaveShuckerow commented on Dec 9, 2016

    @DaveShuckerow
    ContributorAuthor

    We expect a center alignment here.

  6. HansMuller commented on Dec 14, 2016

    @HansMuller
    Contributor

    Here's a test case.

    I've explicitly centered the switch so that it lines up with the center of the appbar's hamburger-title-actions row. As far as I can tell, the hamburger (the drawer icon on the left) is positioned correctly.

    I agree that the app bar should vertically center its action widgets by default however this should easy to workaround for the moment.

    import 'package:flutter/material.dart';
    import 'package:flutter/rendering.dart';
    
    class AppBarAlignment extends StatefulWidget {
      @override
      _AppBarAlignmentState createState() => new _AppBarAlignmentState();
    }
    
    class _AppBarAlignmentState extends State<AppBarAlignment> {
      static final List<String> _dropdownItems = <String>['One', 'Two', 'Free', 'Four'];
      String _dropdownValue = 'One';
      bool _switchValue = true;
    
      @override
      Widget build(BuildContext context) {
        debugPaintSizeEnabled = true;
        return new Scaffold(
          appBar: new AppBar(
            title: new Theme(
              data: new ThemeData(brightness: Brightness.dark),
              child: new SizedBox(
                width: 200.0,
                child: new DropdownButton<String>(
                  value: _dropdownValue,
                  onChanged: (String newValue) {
                    setState(() {
                      _dropdownValue = newValue;
                    });
                  },
                  items: _dropdownItems.map((String value) {
                    return new DropdownMenuItem<String>(
                      value: value,
                      child: new Text(value),
                    );
                  }).toList(),
                ),
              ),
            ),
            actions: <Widget>[
              new Theme(
                data: new ThemeData(brightness: Brightness.dark),
                child: new Center(
                  child: new Switch(
                    value: _switchValue,
                    onChanged: (bool value) {
                      setState(() {
                        _switchValue = value;
                      });
                    }
                  ),
                ),
              ),
            ],
          ),
          drawer: new Center(
            child: new Text('Hello World'),
          ),
          body: new Center(
            child: new Text('Hello World'),
          ),
        );
      }
    }
    
    void main() {
      runApp(new MaterialApp(home: new AppBarAlignment()));
    }
    
  7. Hixie commented on Dec 14, 2016

    @Hixie
    Contributor

    I think the solution is just to put a cross axis alignment of center here in the actions row in the appbar:
    https://github.com/flutter/flutter/blob/master/packages/flutter/lib/src/material/app_bar.dart#L409

  8. self-assigned this
    on Dec 14, 2016
  9. HansMuller commented on Dec 14, 2016

    @HansMuller
    Contributor

    I agree. Working on a test.

  10. github-actions commented on Sep 5, 2021

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  11. locked as resolved and limited conversation to collaborators on Sep 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

p: material_uimaterial_ui package in flutter/packages

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions