Skip to content

[web]: PopupMenuItem height property not working correctly #37890

@lrmoorejr

Description

@lrmoorejr

Setting the height property on a PopupMenuItem does not work correctly. Looks like the vertical start position is misaligned.

PopupMenuItemBug

import 'package:flutter_web/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatelessWidget {
  MyHomePage({Key key, this.title}) : super(key: key);

  final String title;

  @override
  Widget build(BuildContext context) {
    // This works fine if it is set to the default value of 48
    final double itemHeight = 20;

    List<PopupMenuItem<int>> dropDownItems = List<PopupMenuItem<int>>();
    for(int i = 0; i < 10; ++i) {
      dropDownItems.add(PopupMenuItem<int>(
        height:itemHeight,
        value:0, 
        child:SizedBox(
          child:Text(i.toString()), 
          height:itemHeight)
      ),);
    }

    return Scaffold(
      appBar: AppBar(
        title: Text(title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            GestureDetector(
              child:Text('Click me'),
              onTapDown:(TapDownDetails tapDownDetails) async {
                await showMenu<int>(
                  context: context,
                  initialValue: 0,
                  position: RelativeRect.fromLTRB(
                    tapDownDetails.globalPosition.dx, 
                    tapDownDetails.globalPosition.dy, 
                    tapDownDetails.globalPosition.dx + 100, 
                    tapDownDetails.globalPosition.dx + 100),
                  items: dropDownItems,
                );
              },
            ),
          ],
        ),
      ),
    );
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions