以下が私のコードです。項目を選択しても反映されません。解決方法を教えていただけると有難いです。
dart
1 2import 'package:flutter/cupertino.dart'; 3import 'package:flutter/material.dart'; 4 5void main() => runApp(const MyApp()); 6 7class MyApp extends StatelessWidget { 8 const MyApp({Key? key}) : super(key: key); 9 10 11 Widget build(BuildContext context) { 12 return MaterialApp( 13 home: Scaffold( 14 body: const Center( 15 child: MyStatefulWidget(), 16 ), 17 ), 18 ); 19 } 20} 21 22class MyStatefulWidget extends StatefulWidget { 23 const MyStatefulWidget({Key? key}) : super(key: key); 24 25 26 State<MyStatefulWidget> createState() => _MyStatefulWidgetState(); 27} 28 29class _MyStatefulWidgetState extends State<MyStatefulWidget> { 30 final items = ['Japanese', 'English']; 31 String? isSelectedItem = 'Japanese'; 32 33 34 Widget build(BuildContext context) { 35 return Scaffold( 36 body: Center( 37 child: ElevatedButton( 38 child: Text('Button'), 39 onPressed: () { 40 openDialog(); 41 }, 42 ), 43 ), 44 ); 45 } 46 47 Future openDialog() => showDialog( 48 context: context, 49 builder: (context) => AlertDialog( 50 shape: RoundedRectangleBorder( 51 borderRadius: BorderRadius.all(Radius.circular(0))), 52 titlePadding: EdgeInsets.all(0.0), 53 title: Container( 54 padding: EdgeInsets.all(8.0), 55 color: Colors.blue, 56 child: Row( 57 mainAxisAlignment: MainAxisAlignment.center, 58 children: [ 59 Text('Title', style: TextStyle(color: Colors.white)) 60 ], 61 ), 62 ), 63 content: Column( 64 mainAxisSize: MainAxisSize.min, 65 crossAxisAlignment: CrossAxisAlignment.start, 66 mainAxisAlignment: MainAxisAlignment.start, 67 children: [ 68 69 Text('Laungage'), 70 Container( 71 child: DropdownButton<String>( 72 underline: Container( 73 height: 0, 74 color: Colors.grey, 75 ), 76 value: isSelectedItem, 77 icon: Icon(Icons.arrow_drop_down, color: Colors.grey), 78 isExpanded: true, 79 items: <String>[ 80 'Japanese', 81 'English', 82 ].map<DropdownMenuItem<String>>((String value) { 83 return DropdownMenuItem( 84 value: value, child: Text(value)); 85 }).toList(), 86 // items: items.map(buildMenuItem).toList(), 87 onChanged: (String? value) { 88 setState(() { 89 isSelectedItem = value; 90 }); 91 }), 92 ), 93 Divider( 94 height: 1, 95 color: Colors.grey[500], 96 indent: 0, 97 endIndent: 0, 98 thickness: 1, 99 ) 100 ], 101 ), 102 actions: [ 103 TextButton( 104 onPressed: () => Navigator.pop(context), 105 child: Text('CLOSE')), 106 ElevatedButton( 107 onPressed: () => Navigator.pop(context), child: Text('SEND')), 108 ], 109 )); 110 111 DropdownMenuItem<String> buildMenuItem(String item) => DropdownMenuItem( 112 value: item, 113 child: Text(item, 114 style: TextStyle(fontWeight: FontWeight.normal, fontSize: 16)), 115 ); 116} 117
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2022/05/26 02:33