• Ian Hickson's avatar
    Add `DropdownMenu.focusNode` (#142516) · 16e014e8
    Ian Hickson authored
    fixes [`DropdownMenu` doesn't have a focusNode](https://github.com/flutter/flutter/issues/142384)
    
    ### Code sample
    
    <details>
    <summary>expand to view the code sample</summary> 
    
    ```dart
    import 'package:flutter/material.dart';
    
    enum TShirtSize {
      s('S'),
      m('M'),
      l('L'),
      xl('XL'),
      xxl('XXL'),
      ;
    
      const TShirtSize(this.label);
      final String label;
    }
    
    void main() => runApp(const MyApp());
    
    class MyApp extends StatefulWidget {
      const MyApp({super.key});
    
      @override
      State<MyApp> createState() => _MyAppState();
    }
    
    class _MyAppState extends State<MyApp> {
      final FocusNode _focusNode = FocusNode();
    
      @override
      void dispose() {
        _focusNode.dispose();
        super.dispose();
      }
    
      @override
      Widget build(BuildContext context) {
        return MaterialApp(
          debugShowCheckedModeBanner: false,
          home: Scaffold(
            appBar: AppBar(
              title: const Text('DropdownMenu Sample'),
            ),
            body: Center(
              child: DropdownMenu<TShirtSize>(
                focusNode: _focusNode,
                initialSelection: TShirtSize.m,
                label: const Text('T-Shirt Size'),
                dropdownMenuEntries: TShirtSize.values.map((e) {
                  return DropdownMenuEntry<TShirtSize>(
                    value: e,
                    label: e.label,
                  );
                }).toList(),
              ),
            ),
            floatingActionButton: FloatingActionButton.extended(
              onPressed: () {
                _focusNode.requestFocus();
              },
              label: const Text('Request Focus on DropdownMenu'),
            ),
          ),
        );
      }
    }
    ```
    
    </details>
    16e014e8
Name
Last commit
Last update
.github Loading commit data...
.vscode Loading commit data...
bin Loading commit data...
dev Loading commit data...
examples Loading commit data...
packages Loading commit data...
.ci.yaml Loading commit data...
.gitattributes Loading commit data...
.gitignore Loading commit data...
AUTHORS Loading commit data...
CODEOWNERS Loading commit data...
CODE_OF_CONDUCT.md Loading commit data...
CONTRIBUTING.md Loading commit data...
LICENSE Loading commit data...
PATENT_GRANT Loading commit data...
README.md Loading commit data...
TESTOWNERS Loading commit data...
analysis_options.yaml Loading commit data...
dartdoc_options.yaml Loading commit data...
flutter_console.bat Loading commit data...