简体   繁体   中英

flutterfire RTDB failed on android but work in web

after create new flutter app i try to follow flutterfire as documented in https://firebase.flutter.dev/docs . I use firebase auth, realtime database, and it only work when using flutter run in web browser, but not work in android.i try to print console to check if firebase is initiate in android and it show result that firebase is initiate, i also found firebase auth successfuly login, but i cant get any result from console from Realtime Database ( in android only ), is there any clue to debug it? any help would be greatly appreciated.

here is the code i use

class SpcStreamer {
  final _database = FirebaseDatabase.instance.ref();

  Stream<List<SpesialisModel>> getSpesialisStream() {
    print('call getspesialis');
    final specStrean = _database.child('specialities');
    Query qrdoc = specStrean.orderByChild('ondisplay').equalTo('yes');
    final snap = qrdoc.onValue;
    final spcStream = snap.map((event) {
      final specMap = Map<String, dynamic>.from(
          event.snapshot.value as Map<String, dynamic>);
      final specList = specMap.entries.map((e) {
        return SpesialisModel.fromRTDB(Map<String, dynamic>.from(e.value));
      }).toList();
      return specList;
    });
    return spcStream;
  }
}

and use the class in screen..

                   StreamBuilder(
                   stream: SpcStreamer().getSpesialisStream(),
                      builder: (context, snapshot) {
                        final splist = <SizedBox>[];
                        if (snapshot.hasData) {
                          final dsSpesial =
                              snapshot.data as List<SpesialisModel>;
                          splist.addAll(
                            dsSpesial.map(
                              (spc) {
                                return SizedBox(
                                  width: 250,
                                  height: 250,
                                  child: SpecialityCard(
                                    specid: spc.id!,
                                    specialtyName: spc.specialityName,
                                    specialtyDoctorCount:
                                        spc.specialityDoctorCount,
                                    specialtyImagePath: spc.specialityImagePath,
                                  ),
                                );
                              },
                            ),
                          );
                        }
                        return SizedBox(
                          height: 180,
                          child: ScrollConfiguration(
                            behavior: MyCustomScrollBehavior(),
                            child: ListView(
                              scrollDirection: Axis.horizontal,
                              children: splist,
                            ),
                          ),
                        );
                      },
                    ),

work in web but not in android.

i found the answer, because the Map can work in web but not in android. i update the following Stream..

final specMap = Map<String, dynamic>.from(
          event.snapshot.value as Map<String, dynamic>);

to

final specMap = Map<String, dynamic>.from(
          event.snapshot.value as Map);

Web still show result in this Map<String,Dynamic>, but in android will result null

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM