実現したいこと
ドロップダウンリストで選択した値を取得したい
発生している問題・エラーメッセージ
Conditions must have a static type of 'bool'.
と表示されておりビルドが通らない
該当のソースコード
dart
1import 'package:flutter/material.dart'; 2 3void main() { 4 runApp(const MyApp()); 5} 6 7class MyApp extends StatelessWidget { 8 const MyApp({Key? key}) : super(key: key); 9 10 11 Widget build(BuildContext context) { 12 return MaterialApp( 13 title: 'Flutter Demo', 14 theme: ThemeData( 15 16 primarySwatch: Colors.blue, 17 ), 18 home: const MyHomePage(title: 'Flutter Demo Home Page'), 19 ); 20 } 21} 22 23class MyHomePage extends StatefulWidget { 24 const MyHomePage({Key? key, required this.title}) : super(key: key); 25 26 27 final String title; 28 29 30 State<MyHomePage> createState() => _MyHomePageState(); 31} 32 33 34 35 36class _MyHomePageState extends State<MyHomePage> { 37 int _counter = 0; 38 39 String? isSelectedItemhourB; 40 41 42 Widget DropMenuCreateHourB() { 43 return DropdownButton( 44 items: [ 45 DropdownMenuItem( 46 child: Text('09'), 47 value: '09B', 48 ), 49 DropdownMenuItem( 50 child: Text('10'), 51 value: '10B', 52 ), 53 DropdownMenuItem( 54 child: Text('11'), 55 value: '11B', 56 ), 57 DropdownMenuItem( 58 child: Text('12'), 59 value: '12B', 60 ), 61 DropdownMenuItem( 62 child: Text('13'), 63 value: '13B', 64 ), 65 DropdownMenuItem( 66 child: Text('14'), 67 value: '14B', 68 ), 69 DropdownMenuItem( 70 child: Text('15'), 71 value: '15B', 72 ), 73 ], 74 onChanged: (String? value){ 75 setState((){ 76 isSelectedItemhourB = value; 77 }); 78 }, 79 value: isSelectedItemhourB, 80 ); 81 } 82 83 84 Widget build(BuildContext context) { 85 86 return Scaffold( 87 appBar: AppBar( 88 89 title: Text(widget.title), 90 ), 91 body: Column( 92 children: [ 93 Center( 94 child: DropMenuCreateHourB(), 95 ), 96 Text(isSelectedItemhourB?), 97 ], 98 )// This trailing comma makes auto-formatting nicer for build methods. 99 ); 100 } 101}
試したこと
グローバル変数にする
?をはずしてみる
補足情報(FW/ツールのバージョンなど)
ここにより詳細な情報を記載してください。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。