【问题标题】:Flutter Flappy SearchFlutter Flappy 搜索
【发布时间】:2020-07-16 18:53:39
【问题描述】:

我正在努力将 Flutter Flappy 搜索栏连接到 firebase 集合。现在花了几天时间,似乎无法弄清楚。在控制台中出现以下错误:

VERBOSE-2:ui_dart_state.cc(157)] 未处理的异常:类型 “PlatformException”不是“Error”类型的子类型

我还在学习中,所以如果有人可以向我提供任何帮助,我将不胜感激。

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),
                ),
              );
            },
          ),
        ),
      ),
    );
  }
} 

【问题讨论】:

    标签: flutter flutter-layout dart-pub


    【解决方案1】:

    试试这个:

    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"]),
                    ),
                  );
                },
              ),
            ),
          ),
        );
      }
    }
    

    【讨论】:

    • 您能否编辑您的答案以解释其工作原理?
    猜你喜欢
    • 2021-03-10
    • 1970-01-01
    • 2020-11-17
    • 2021-02-13
    • 2020-11-01
    • 1970-01-01
    • 2020-10-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多