我正在努力将Flutter Flappy Search Bar连接到Firebase集合。现在花了几天时间,似乎无法弄清楚。在控制台中出现以下错误:
VERBOSE-2:ui_dart_state.cc(157)]未处理的异常:类型 “ PlatformException”不是“错误”类型的子类型
我仍在学习绳索,因此,如果有人可以向我提供任何帮助,将不胜感激。
class SellHousesPage extends StatelessWidget {
Database database;
House house;
Future<List<House>> getHouses(String name) async {
List houseList;
await Future.delayed(Duration(seconds: 2));
final List<DocumentSnapshot> documents =
(await Firestore.instance.collection('houses').getDocuments()).documents;
houseList = documents.map((documentSnapshot) => documentSnapshot[house.name]).toList();
return houseList;
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 20),
child: SearchBar<House>(
onSearch: getHouses,
onItemFound: (House house, int index) {
return Container(
color: Colors.indigo,
child: ListTile(
title: Text(house.name),
),
);
},
),
),
),
);
}
}
答案 0 :(得分:0)
尝试一下:
class SellHousesPage extends StatelessWidget {
Database database;
House house;
Future<List<dynamic>> getHouses(String name) async {
QuerySnapshot response = await Firestore.instance
.collection('houses')
.getDocuments();
return response.documents.map((house) => house).toList();
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 20),
child: SearchBar<House>(
onSearch: getHouses,
onItemFound: (House house, int index) {
return Container(
color: Colors.indigo,
child: ListTile(
title: Text(house["name"]),
),
);
},
),
),
),
);
}
}