タイトル通りポップアップメニューの項目を選択した時にダイアログ
表示を行いたいです。
ポップアップメニューを選択してもまったくダイアログが表示されません。
Dart
1class Choice { 2 const Choice({this.title, this.icon}); 3 4 final String title; 5 final IconData icon; 6} 7 8class TabBarDemo extends StatelessWidget { 9 void showBasicDialog(BuildContext context) { 10 showDialog( 11 context: context, 12 builder: (BuildContext context) => new AlertDialog( 13 content: new Text("本文"), 14 // ボタンの配置 15 actions: <Widget>[ 16 new FlatButton( 17 child: const Text('キャンセル'), 18 onPressed: () { 19 Navigator.pop(context); 20 }), 21 new FlatButton( 22 child: const Text('OK'), 23 onPressed: () { 24 Navigator.pop(context); 25 }) 26 ], 27 ), 28 ).then<void>((value) { 29 // ボタンタップ時の処理 30 switch (value) { 31 } 32 }); 33 } 34 35 36 37 Widget build(BuildContext context) { 38 return MaterialApp( 39 home: DefaultTabController( 40 length: 3, //タブ数 41 child: Scaffold( 42 appBar: AppBar( 43 actions: <Widget>[ 44 // overflow menu 45 PopupMenuButton<Choice>( 46 onSelected: (Choice) { 47 switch (Choice.title) { 48 case 'プライバシーポリシー': 49 showBasicDialog(context); 50 break; 51 default: 52 break; 53 } 54 }, 55 itemBuilder: (BuildContext context) { 56 return choices.map((Choice choice) { 57 return PopupMenuItem<Choice>( 58 value: choice, 59 child: Text(choice.title), 60 ); 61 }).toList(); 62 }, 63 ), 64 ], 65 ), 66 , 67 ), 68 ), 69 ); 70 } 71}
実行した時のエラーです。
/flutter (11352): [ERROR:flutter/shell/common/shell.cc(181)] Dart Error: Unhandled exception:
E/flutter (11352): No MaterialLocalizations found.
E/flutter (11352): TabBarDemo widgets require MaterialLocalizations to be provided by a Localizations widget ancestor.
E/flutter (11352): Localizations are used to generate many different messages, labels,and abbreviations which are used by the material library.
E/flutter (11352): To introduce a MaterialLocalizations, either use a MaterialApp at the root of your application to include them automatically, or add a Localization widget with a MaterialLocalizations delegate.
E/flutter (11352): The specific widget that could not find a MaterialLocalizations ancestor was:
E/flutter (11352): TabBarDemo
E/flutter (11352): The ancestors of this widget were:
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。