質問編集履歴
2
プログラムの修正
title
CHANGED
|
File without changes
|
body
CHANGED
|
@@ -6,37 +6,44 @@
|
|
|
6
6
|
ご教授お願いいたします。
|
|
7
7
|
|
|
8
8
|
---
|
|
9
|
-
```
|
|
9
|
+
```dart
|
|
10
10
|
|
|
11
11
|
class TimerModel extends ChangeNotifier{
|
|
12
12
|
|
|
13
13
|
List<Time> timeList = [];
|
|
14
14
|
String Uid = '';
|
|
15
15
|
|
|
16
|
-
Future getUid
|
|
16
|
+
Future getUid(){
|
|
17
|
-
final snapshot =
|
|
17
|
+
final snapshot = FirebaseAuth.instance.currentUser;
|
|
18
18
|
this.Uid = snapshot.uid;
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
Future gettimerList() async {
|
|
22
22
|
|
|
23
23
|
final snapshot =
|
|
24
|
-
await FirebaseFirestore
|
|
24
|
+
await FirebaseFirestore
|
|
25
|
+
.instance
|
|
25
|
-
.collection('users')
|
|
26
|
+
.collection('users')
|
|
27
|
+
.doc(Uid)
|
|
26
|
-
.collection('timer')
|
|
28
|
+
.collection('timer')
|
|
29
|
+
.get();
|
|
27
30
|
final docs = snapshot.docs;
|
|
28
31
|
final timeList = docs.map((doc) => Time(doc)).toList();
|
|
29
32
|
this.timeList = timeList;
|
|
30
33
|
|
|
31
34
|
notifyListeners();
|
|
35
|
+
|
|
32
36
|
}
|
|
33
37
|
|
|
34
38
|
Future getTeaListRealtime() async {
|
|
35
39
|
|
|
36
40
|
final snapshots =
|
|
37
|
-
await FirebaseFirestore
|
|
41
|
+
await FirebaseFirestore
|
|
42
|
+
.instance
|
|
38
|
-
.collection('users')
|
|
43
|
+
.collection('users')
|
|
44
|
+
.doc(Uid)
|
|
39
|
-
.collection('timer')
|
|
45
|
+
.collection('timer')
|
|
46
|
+
.snapshots();
|
|
40
47
|
snapshots.listen((snapshot){
|
|
41
48
|
final docs = snapshot.docs;
|
|
42
49
|
final timeList = docs.map((doc) => Time(doc)).toList();
|
|
@@ -45,4 +52,59 @@
|
|
|
45
52
|
});
|
|
46
53
|
}
|
|
47
54
|
}
|
|
48
|
-
```
|
|
55
|
+
```
|
|
56
|
+
```dart
|
|
57
|
+
class TimerList extends StatelessWidget {
|
|
58
|
+
@override
|
|
59
|
+
Widget build(BuildContext context) {
|
|
60
|
+
|
|
61
|
+
return Consumer<TimerModel>(builder: (context, model, child) {
|
|
62
|
+
model.getUid();
|
|
63
|
+
return Scaffold(
|
|
64
|
+
appBar: AppBar(
|
|
65
|
+
title: Text('タイマーリスト'),
|
|
66
|
+
centerTitle: true,
|
|
67
|
+
actions: [
|
|
68
|
+
InkWell(
|
|
69
|
+
onTap: ()async{
|
|
70
|
+
print(model.Uid); ※ここでuidを出力できました。
|
|
71
|
+
},
|
|
72
|
+
child: Icon(Icons.favorite_border,
|
|
73
|
+
),
|
|
74
|
+
)
|
|
75
|
+
],
|
|
76
|
+
),
|
|
77
|
+
body:Consumer<TimerModel>(builder: (context, model, child) {
|
|
78
|
+
final timerList = model.timeList;
|
|
79
|
+
return ListView(
|
|
80
|
+
children: timerList
|
|
81
|
+
.map(
|
|
82
|
+
(timelist) => Card(
|
|
83
|
+
child: Center(
|
|
84
|
+
child:Text(timelist.title,
|
|
85
|
+
),
|
|
86
|
+
),
|
|
87
|
+
),
|
|
88
|
+
).toList(),
|
|
89
|
+
);
|
|
90
|
+
}),
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
```
|
|
97
|
+
```dart
|
|
98
|
+
class Time {
|
|
99
|
+
|
|
100
|
+
Time(DocumentSnapshot doc){
|
|
101
|
+
this.time = doc['time'];
|
|
102
|
+
this.title = doc['title'];
|
|
103
|
+
}
|
|
104
|
+
String time;
|
|
105
|
+
String title;
|
|
106
|
+
}
|
|
107
|
+
```
|
|
108
|
+
]
|
|
109
|
+

|
|
110
|
+
usersのdocumentIDはuidです。
|
1
title
CHANGED
|
File without changes
|
body
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
### 問題点
|
|
2
|
-
サインアップ時にfirebaseでuidをdocumentIDとして保存し、
|
|
2
|
+
サインアップ時にfirebaseでuidをdocumentIDとして保存し、ログインしたユーザーのuidを用いてデータを取得したい。
|
|
3
3
|
|
|
4
4
|
currentUserなどを使ってuidを取得し、検索に用いたいのですが、うまくいきませんでした。
|
|
5
5
|
|