class Profile {
final List<String> photos;
final String name;
......
Profile({
this.photos,
this.name,
......
});
}
final List<Profile> demoProfiles = [
Profile (
photos: [
"https:...",
],
name: "Fatih",
age: 22,
distance: 4,
education: "Hacettepe University"
),
Profile (
photos: [
"https:...",
"https:...",
],
name: "Elysium",
age: 23,
distance: 2,
bio: "Test bio"
)
];
如何从Firestore检索数据,然后更新List demoProfiles并在main_controller.dart中使用它?我真的很陌生,有人可以帮助我吗?谢谢。
final MatchEngine matchEngine = MatchEngine (
matches:demoProfiles.map((Profile profile) => Match(profile: profile)).toList()
);
答案 0 :(得分:0)
您可以像下面这样尝试吗?
Future<Profile> fetchData() async {...}
答案 1 :(得分:0)
您可以这样做
List<Profile> demoProfiles = [];
@override
void initState() {
super.initState();
loadDataMethod();
}
void loadDataMethod() async {
demoProfiles = await fetchData();
setState(() {});
}
Future<List<Profile>> fetchData() async {
List<Profile> list;
// Fetch Data Logic
return list;
}
或类似
List<Profile> demoProfiles = fetchData() as List<Profile>;