'Can't get data from document when getting through dynamic value but can get easily with constant value

enter image description here

This piece of code works fine for just one document ID which is passed statically.

class _ImagesHomeTileState extends State<ImagesHomeTile> {
  List<dynamic> pointList = [];
  bool kuchhai = false;
  getdata() async {
    await FirebaseFirestore.instance
        .collection("Past Papers")
        .doc('XZ15GgU1vuXRDUauOb5w')
        .get()
        .then((value) {
      setState(() {
        value.data() == null ? kuchhai = false : kuchhai = true;
        value.data() == null
            ? kuchhai = false
            : pointList = value.data()!['ImagesLinks'];
      });
    });
  }

  @override
  void initState() {
    getdata();
    super.initState();
  }
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        body: kuchhai
            ? GridView.count(
                crossAxisCount: 2,
                crossAxisSpacing: 4.0,
                mainAxisSpacing: 8.0,
                children: [Text(pointList.toString())])
            : const Center(
                child: CircularProgressIndicator(),
              ));
  }
}

This returns the actual values in the array but the following code returns nothing why?

class ImagesHomeTile extends StatefulWidget {
  final String docId;
  ImagesHomeTile({required this.docId});

  @override
  State<ImagesHomeTile> createState() => _ImagesHomeTileState();
}

class _ImagesHomeTileState extends State<ImagesHomeTile> {
  List<dynamic> pointList = [];
  bool kuchhai = false;
  getdata() async {
    await FirebaseFirestore.instance
        .collection("Past Papers")
        .doc(widget.docId)
        .get()
        .then((value) {
      setState(() {
        value.data() == null ? kuchhai = false : kuchhai = true;
        value.data() == null
            ? kuchhai = false
            : pointList = value.data()!['ImagesLinks'];
      });
    });
  }

  @override
  void initState() {
    getdata();

super.initState(); }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        body: kuchhai
            ? GridView.count(
                crossAxisCount: 2,
                crossAxisSpacing: 4.0,
                mainAxisSpacing: 8.0,
                children: [Text(pointList.toString())])
            : const Center(
                child: CircularProgressIndicator(),
              ));
  }
}

Getting values from Firestore gives not in dynamic values. What could be the possible error?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source