[flutter] 플러터 DropdownButton 예제 코드
import 'package:flutter/material.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: Text('DropdownButton 예제'),
        ),
        body: Center(
          child: _buildDropdownButton(),
        ),
      ),
    );
  }

  Widget _buildDropdownButton() {
    return DropdownButton<String>(
      value: 'One',
      items: <String>['One', 'Two', 'Three', 'Four']
          .map<DropdownMenuItem<String>>((String value) {
        return DropdownMenuItem<String>(
          value: value,
          child: Text(value),
        );
      }).toList(),
      onChanged: (String? newValue) {
        // Do something with the selected value
      },
    );
  }
}

이 코드는 DropdownButton을 포함하는 간단한 플러터 앱을 만드는 방법을 보여줍니다. 위젯은 ‘One’, ‘Two’, ‘Three’, ‘Four’ 중 하나를 선택할 수 있는 드롭다운 버튼을 만들고, 사용자가 다른 옵션을 선택하면 onChanged 콜백 함수가 호출됩니다.

이 코드를 실행하면 드롭다운 버튼이 표시되고 사용자가 옵션을 선택할 수 있습니다. 선택한 옵션은 onChanged 콜백 함수에서 처리할 수 있습니다.