• Taha Tesser's avatar
    Add `PopupMenuButton.iconColor`, `PopupMenuTheme.iconSize` and fix button icon... · b77b149d
    Taha Tesser authored
    Add `PopupMenuButton.iconColor`, `PopupMenuTheme.iconSize` and fix button icon using unexpected color propert (#132054)
    
    fixes [PopupMenuButton uses color property for icon color](https://github.com/flutter/flutter/issues/127802) 
    fixes [`popup_menu_test.dart` lacks default icon color tests.](https://github.com/flutter/flutter/issues/132050) 
    
    ### Description
    - Add  `PopupMenuButton..iconColor` and fix the PopupMenu button icon using an unexpected color property.
    - Add the missing `PopupMenuTheme.iconSize`.
    - Clean up some tests and minor improvements.
    
    ### Code sample
    
    <details> 
    <summary>expand to view the code sample</summary> 
    
    ```dart
    import 'package:flutter/material.dart';
    
    /// Flutter code sample for [PopupMenuButton].
    
    // This is the type used by the popup menu below.
    enum SampleItem { itemOne, itemTwo, itemThree }
    
    void main() => runApp(const PopupMenuApp());
    
    class PopupMenuApp extends StatelessWidget {
      const PopupMenuApp({super.key});
    
      @override
      Widget build(BuildContext context) {
        return MaterialApp(
          theme: ThemeData(
            popupMenuTheme: PopupMenuThemeData(
              // iconSize: 75,
              // iconColor: Colors.amber,
              color: Colors.deepPurple[100],
            ),
          ),
          home: const PopupMenuExample(),
        );
      }
    }
    
    class PopupMenuExample extends StatefulWidget {
      const PopupMenuExample({super.key});
    
      @override
      State<PopupMenuExample> createState() => _PopupMenuExampleState();
    }
    
    class _PopupMenuExampleState extends State<PopupMenuExample> {
      SampleItem? selectedMenu;
    
      @override
      Widget build(BuildContext context) {
        return Scaffold(
          appBar: AppBar(title: const Text('PopupMenuButton')),
          body: Center(
            child: PopupMenuButton<SampleItem>(
              iconSize: 75,
              // iconColor: Colors.amber,
              color: Colors.deepPurple[100],
              initialValue: selectedMenu,
              // Callback that sets the selected popup menu item.
              onSelected: (SampleItem item) {
                setState(() {
                  selectedMenu = item;
                });
              },
              itemBuilder: (BuildContext context) => <PopupMenuEntry<SampleItem>>[
                const PopupMenuItem<SampleItem>(
                  value: SampleItem.itemOne,
                  child: Text('Item 1'),
                ),
                const PopupMenuItem<SampleItem>(
                  value: SampleItem.itemTwo,
                  child: Text('Item 2'),
                ),
                const PopupMenuDivider(),
                const CheckedPopupMenuItem<SampleItem>(
                  value: SampleItem.itemThree,
                  checked: true,
                  child: Text('Item 3'),
                ),
              ],
            ),
          ),
        );
      }
    }
    
    ``` 
    	
    </details>
    
    ![Group 2](https://github.com/flutter/flutter/assets/48603081/eb5404ae-2a07-4374-9821-66a0bbea041e)
    
    ![Group 1](https://github.com/flutter/flutter/assets/48603081/464e3957-1afb-4118-abcc-aad12591dc51)
    b77b149d
popup_menu_test.dart 120 KB