type 'RxList<Map<String, String>>' is not a subtype of type 'RxList<Faq>' of 'function result'

90 Views Asked by At

I want to fetch data from firestore but i get this error:

type 'RxList<Map<String, String>>' is not a subtype of type 'RxList' of 'function result'

i try with to solve but i got nothing so use getx for my management state this is my controller code

import 'package:get/get.dart';
import 'package:cloud_firestore/cloud_firestore.dart';

class Faqs {
  final String quetions;
  final String answers;

  Faqs({required this.quetions, required this.answers});
}

class FaqController extends GetxController {
  var faqList = <Faqs>[].obs;
  FirebaseFirestore firestore = FirebaseFirestore.instance;

  @override
  void onInit() {
    super.onInit();
    fetchFaqList();
  }

  Future<void> fetchFaqList() async {
    CollectionReference faqs = firestore.collection('faqs');
    QuerySnapshot querySnapshot = await faqs.get();

    List<Faqs> fetchedFaqList = querySnapshot.docs.map((doc) {
      Map<String, dynamic> data = doc.data()! as Map<String, dynamic>;
      return Faqs(
        quetions: data['quetions'],
        answers: data['answer'],
      );
    }).toList();

    faqList.assignAll(fetchedFaqList);
  }
}

0

There are 0 best solutions below