Advertisement
yudiwibisono

dropdownmenu

May 26th, 2023
974
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 1.24 KB | None | 0 0
  1. import 'package:flutter/material.dart';
  2.  
  3. void main() {
  4.   runApp(const MyApp());
  5. }
  6.  
  7. //isian dari drop down
  8. List<DropdownMenuEntry<String>> items =
  9.     <String>['pagi', 'siang'].map<DropdownMenuEntry<String>>((String value) {
  10.   return DropdownMenuEntry<String>(
  11.     label: value,
  12.     value: value,
  13.   );
  14. }).toList();
  15.  
  16. class MyApp extends StatefulWidget {
  17.   const MyApp({Key? key}) : super(key: key);
  18.  
  19.   @override
  20.   State<MyApp> createState() => _MyAppState();
  21. }
  22.  
  23. class _MyAppState extends State<MyApp> {
  24.   final TextEditingController salamController = TextEditingController();
  25.   String? pilihanSalam;
  26.   @override
  27.   Widget build(BuildContext context) {
  28.     return MaterialApp(
  29.       home: Scaffold(
  30.           body: Center(
  31.         child: Column(mainAxisSize: MainAxisSize.min, children: [
  32.           DropdownMenu<String>(
  33.             initialSelection: "pagi",
  34.             controller: salamController,
  35.             label: const Text('Salam'),
  36.             dropdownMenuEntries: items,
  37.             onSelected: (String? salam) {
  38.               setState(() {
  39.                 pilihanSalam = salam;
  40.               });
  41.             },
  42.           ),
  43.           Text("Pilihan : $pilihanSalam") //tampilkan hasil
  44.         ]),
  45.       )),
  46.     );
  47.   }
  48. }
  49.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement