問題点
以下のようなプログラムをflutter firebase provderを使って作っています。
⓵でCardをタップしたらタップされたドキュメントIDを使い⓶でデータを取得し③で表示したいのですが、コンソールには出力できるのですが、③のページに表示できません。
ご教授よろしくお願いいたします。
①
dart
1 body: Consumer<TeaProvider>(builder: (context, model, child) { 2 final todoList = model.todoList; 3 return ListView( 4 children: todoList 5 .map( 6 (todo) => Card( 7 margin: const EdgeInsets.only(left:20,right:20,top:5,bottom:5), 8 elevation: 3, 9 child: InkWell( 10 onTap: ()async{ 11 await deleteBook(context , model , todo); 12 Navigator.push( 13 context, 14 MaterialPageRoute(builder: (context) => ViewPage())); 15 }, 16 child: Container( 17 height: MediaQuery.of(context).size.height * 0.15, 18 child: Row( 19 mainAxisAlignment: MainAxisAlignment.start, 20 children: [ 21 Column( 22 mainAxisAlignment: MainAxisAlignment.spaceAround, 23 crossAxisAlignment: CrossAxisAlignment.center, 24 children: [ 25 Padding( 26 padding: const EdgeInsets.only(right:10.0,left:10.0), 27 child: Container( 28 width: 50, 29 height: 50, 30 decoration: BoxDecoration( 31 color: Colors.red, 32 shape: BoxShape.circle 33 ), 34 ), 35 ), 36 Padding( 37 padding: const EdgeInsets.only( 38 right: 10.0, left: 10.0), 39 child: Text(todo.name, 40 ), 41 ), 42 ], 43 ), 44 Container( 45 height: 80, 46 child: VerticalDivider( 47 color: Colors.black54, 48 ) 49 ), 50 Flexible( 51 child: Column( 52 crossAxisAlignment: CrossAxisAlignment.start, 53 mainAxisAlignment: MainAxisAlignment.start, 54 children: [ 55 Padding( 56 padding: const EdgeInsets.only(bottom:4.0), 57 child: Text(todo.recipe, 58 overflow: TextOverflow.ellipsis, 59 maxLines: 2, 60 style: TextStyle( 61 fontWeight: FontWeight.bold, 62 fontSize: 17 63 ),), 64 ), 65 Text(todo.title, 66 overflow: TextOverflow.ellipsis, 67 maxLines: 2, 68 ), 69 Text( '調理時間:'+todo.time+'min') 70 ], 71 ), 72 ) 73 ], 74 ) 75 ), 76 ), 77 78 ), 79 ).toList(), 80 ); 81 }),
⓶
dart
1※抜粋しています 2class TeaProvider extends ChangeNotifier { 3 Future getTapmodel(Todo todo) async{ 4 final snapshoted = await FirebaseFirestore.instance 5 .collection('todoList') 6 .doc(todo.documentID) 7 .get(); 8 notifyListeners(); 9 viewText = snapshoted['title']; 10 viewTodo = snapshoted['name']; 11 viewItem = snapshoted['recipe']; 12 viewTime = snapshoted['time']; 13 viewName = snapshoted['material']; 14 print(viewText); 15 print(viewTime); 16 print(viewTodo); 17 print(viewName); 18 print(viewItem); 19 notifyListeners(); 20 } 21 String viewText; 22 String viewTodo; 23 String viewItem; 24 String viewTime; 25 String viewName; 26 27}
⓷
dart
1class ViewPage extends StatelessWidget { 2 3 4 Widget build(BuildContext context) { 5 return ChangeNotifierProvider<TeaProvider>( 6 create: (_) => TeaProvider(), 7 child: Scaffold( 8 appBar: AppBar( 9 backgroundColor: Colors.green, 10 title: Text('Tea App'), 11 centerTitle: true, 12 ), 13 body: Consumer<TeaProvider>(builder: (context, model, child) { 14 return Container( 15 child: Center( 16 child: Column( 17 children: [ 18 Text(model.viewItem??'データなし'), 19 Text(model.viewName??'データなし'), 20 Text(model.viewTodo??'データなし'), 21 Text(model.viewTime??'データなし'), 22 Text(model.viewText??'データなし'), 23 ] 24 ), 25 ) 26 ); 27 }, 28 ) 29 ), 30 ); 31 } 32} 33
あなたの回答
tips
プレビュー