Why Firestore on FLutter causing “reciever can be null” Error?

I watched the Tutorial from Google about Firestore, but i came up with problems about “null exception”. I imported the package and all, but i dont get the answer.

Main Page

StreamBuilder(
          stream: FirebaseFirestore.instance.collection("testCity").snapshots(),
          builder: (context, snapshot) {
            if (snapshot.connectionState == ConnectionState.waiting) {
              return const Text("Bitte Warten");
            }

            return ListView.separated(

              padding: const EdgeInsets.fromLTRB(24, 16, 24, 24),
              physics: const NeverScrollableScrollPhysics(),
              shrinkWrap: true,

              itemCount: snapshot.data.docs.length,
              itemBuilder: (context, int index) {
                return NormalCard(database: snapshot.data.docs[index]);
              },

              separatorBuilder: (BuildContext context, int index)
              => const Divider(
                height: 32,
                thickness: 4,
                color: Color(0xFF484848),
              ),
            );
          },
        )

Normalcard Widget

class NormalCard extends StatefulWidget {
  const NormalCard({Key? key, required this.database}) : super(key: key);

  final DocumentSnapshot database;

  @override
  State<NormalCard> createState() => _NormalCardState();
}

class _NormalCardState extends State<NormalCard> {

  @override
  Widget build(BuildContext context) {

    DocumentSnapshot database = widget.database;

    return LayoutBuilder(
      ...
    );
  }
}

Following Errors occured:
at Problems Tab:
“The property ‘docs’ can’t be unconditionally accessed because the receiver can be ‘null’.”

at run:
lib/Pages/page_startseite.dart:80:40: Error: Property ‘docs’ cannot be accessed on ‘QuerySnapshot<Map<String, dynamic>>?’ because it is potentially null.

  • ‘QuerySnapshot’ is from ‘package:cloud_firestore/cloud_firestore.dart’ (‘../../../AppData/Local/Pub/Cache/hosted/pub.dev/cloud_firestore-4.14.0/lib/cloud_firestore.dart’).
  • ‘Map’ is from ‘dart:core’.
    Try accessing using ?. instead.
    itemCount: snapshot.data.docs.length,
    ^^^^
    lib/Pages/page_startseite.dart:82:59: Error: Property ‘docs’ cannot be accessed on ‘QuerySnapshot<Map<String, dynamic>>?’ because it is potentially null.
  • ‘QuerySnapshot’ is from ‘package:cloud_firestore/cloud_firestore.dart’ (‘../../../AppData/Local/Pub/Cache/hosted/pub.dev/cloud_firestore-4.14.0/lib/cloud_firestore.dart’).
  • ‘Map’ is from ‘dart:core’.
    Try accessing using ?. instead.
    return NormalCard(database: snapshot.data.docs[index]);
    ^^^^
    lib/Pages/page_exploreseite.dart:112:40: Error: Required named parameter ‘database’ must be provided.
    return const NormalCard();
    ^
    lib/Widgets/card_restaurantNormal.dart:5:9: Context: Found this candidate, but the arguments don’t match.
    const NormalCard({Key? key, required this.database}) : super(key: key);
    ^^^^^^^^^^

Can anyone help me with this problems so i can implement my Database from Firestore as Backend of my Project?

New contributor

Nikolai is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật