前提
Flutterで、通知一覧となるページを実装しています。
通知のタイトルを押下したら、BottomSheetで詳細内容を表示できるような仕様にしたいです。
実現したいこと
・通知のタイトルをListViewで表示させ、IconButtonでBottomSheetを表示させたい。
発生している問題・エラーメッセージ
IconButton内に記載したBottomSheetが表示されない。
該当のソースコード
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: '通知', 14 theme: ThemeData( 15 primarySwatch: Colors.orange, 16 ), 17 home: InfoListPage(), 18 ); 19 } 20} 21class InfoListPage extends StatefulWidget { 22 const InfoListPage({Key? key}) : super(key: key); 23 24 25 State<InfoListPage> createState() => _InfoListPageState(); 26} 27 28class _InfoListPageState extends State<InfoListPage> { 29 30 31 Widget build(BuildContext context){ 32 return Scaffold( 33 body: ListView( 34 children: <Widget>[ 35 Card( 36 child: ListTile( 37 leading: Text("${DateTime.now().month}/${DateTime.now().day}"), 38 title: Text('通知タイトルを表示'), 39 trailing: IconButton( 40 onPressed: (){ 41 showBottomSheet( 42 context: context, 43 builder: (BuildContext context){ 44 return Container( 45 child: Text('ここに詳細内容を表示'), 46 alignment: Alignment.center, 47 height: 500, 48 width: double.infinity, 49 decoration: BoxDecoration( 50 color: Colors.white, 51 boxShadow: [ 52 BoxShadow( 53 color: Colors.grey, 54 blurRadius: 20, 55 ), 56 ]), 57 ); 58 }); 59 }, 60 icon: Icon(Icons.account_balance_wallet_outlined), 61 ), 62 ), 63 ), 64 ], 65 ), 66 ); 67 } 68} 69
試したこと
・IconButtonを使わずに、ListTileのonTapで直接呼び出す。
→BottomSheetの反映なし。
・https://stackoverflow.com/questions/49778866/close-modal-bottom-sheet-programmatically-in-flutter
の回答を基にNavigatorでの記述を試す
→BottomSheetの反映なし。
ListTileの中でBottomSheetを表示させるのは難しいのでしょうか。
何か解決策をご存じであればご教示いただけますと幸いです。
よろしくお願いいたします。
補足情報(FW/ツールのバージョンなど)
Android Studio Dolphin | 2021.3.1
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2022/11/22 08:18