title: Late initialising error in flutter while working with firebase
body: <p>I'm working on this app to help people find the fitting wine for their meal. Now I wanted the user to be able to select the specific meal he or she is currently enjoying to have a better prediction what wine fits best. Now I tried implementing that but I'm getting this late error field must be initialised... I think I know where its coming from but I dont know how to solve it this is the code of the screen:</p>
  <pre><code>class _AskSomellierStep4ScreenState extends State&lt;AskSomellierStep4Screen&gt; {
    late QueryDocumentSnapshot&lt;Map&lt;String, dynamic&gt;&gt; _selectedSnapshot;
    List&lt;String&gt; dataLabel = [
      'Home',
      'Search',
      'Account',
    ];
    late Future resultsLoaded;
  
    getResults() async {
      var data = await FirebaseFirestore.instance
          .collection(widget.wineOrMeal)
          .where('type', isEqualTo: widget.selectedCuisine)
          .get();
      setState(() {
        allResults = data.docs;
      });
      filterResultsList();
      return data.docs;
    }
    
    @override
    Widget build(BuildContext context) {
      return Scaffold(
        backgroundColor: Theme.of(context).scaffoldBackgroundColor,
        body: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
  ...
  Padding(
                padding: const EdgeInsets.only(
                  left: 35,
                  top: 5,
                ),
                child: SizedBox(
                  height: 370,
                  width: 320,
                  child: Center(
                    child: ListView.builder(
                      dragStartBehavior: DragStartBehavior.down,
                      scrollDirection: Axis.vertical,
                      itemCount: filteredResults.length,
                      itemBuilder: (context, index) =&gt; widget.mealVSWine
                          ? PrefInformationCardWine(
                              snapShotDocument: filteredResults[index],
                              cardColor: Theme.of(context).primaryColor,
                              isSelected:
                                  filteredResults[index] == _selectedSnapshot,
                              onSelected: () {
                                setState(() {
                                  _selectedSnapshot = filteredResults[index];
                                });
                              },
                            )
                          : PrefInformationCardMeal(
                              snapShotDocument: filteredResults[index],
                              cardColor: Theme.of(context).primaryColor,
                              isSelected:
                                  filteredResults[index] == _selectedSnapshot,
                              onSelected: () {
                                setState(() {
                                  _selectedSnapshot = filteredResults[index];
                                });
                              },
                            ),
                    ),
                  ),
                )),
            Padding(
              padding: const EdgeInsets.only(
                left: 35,
                top: 25,
              ),
              child: SubmitSettingChangesButton(
                buttonText: 'Continue',
                cancelText: 'Cancel',
                cancelOnTap: () {
                  Navigator.pop(context);
                },
                continueOnTap: () {
                  Navigator.pushAndRemoveUntil(
                      context,
                      createRoute(FindingRecommendationScreen(
                        snapshotName: _selectedSnapshot,
                      )),
                      (route) =&gt; false);
                },
              ),
            ),
  ...
  </code></pre>
  <p>If you need any further information just give me a note. I would be very thankful if you could help me with this:)</p>
  <hr />
  <p>Code Screen 4:</p>
  <pre><code> class AskSomellierStep4Screen extends StatefulWidget {
        const AskSomellierStep4Screen({
          Key? key,
          required this.stepDescription,
          required this.wineOrMeal,
          required this.mealVSWine,
          required this.selectedCuisine,
        }) : super(key: key);
      
        final String wineOrMeal;
        final String stepDescription;
        final bool mealVSWine;
        final String selectedCuisine;
      
        @override
        State&lt;AskSomellierStep4Screen&gt; createState() =&gt;
            _AskSomellierStep4ScreenState();
      }
      
      class _AskSomellierStep4ScreenState extends State&lt;AskSomellierStep4Screen&gt; {
        QueryDocumentSnapshot&lt;Map&lt;String, dynamic&gt;&gt;? _selectedSnapshot;
        List&lt;String&gt; dataLabel = [
          'Home',
          'Search',
          'Account',
        ];
        late Future resultsLoaded;
        List&lt;IconData&gt; data = [
          CustomIcons.home,
          CustomIcons.search,
          CustomIcons.user,
        ];
      
        getResults() async {
          var data = await FirebaseFirestore.instance
              .collection(widget.wineOrMeal)
              .where('type', isEqualTo: widget.selectedCuisine)
              .get();
          setState(() {
            allResults = data.docs;
          });
          filterResultsList();
          return data.docs;
        }
      
        List allResults = [];
      
        List filteredResults = [];
      
        onSearchChanged() {
          print(searchController.text);
          filterResultsList();
        }
      
        filterResultsList() {
          var showResults = [];
      
          if (searchController.text != '') {
            // we have a search parameter
            for (var searchSnapshot in allResults) {
              var name = searchSnapshot['name'].toLowerCase();
      
              if (name.contains(searchController.text.toLowerCase())) {
                showResults.add(searchSnapshot);
              }
            }
          } else {
            // we do not have a search parameter
            showResults = List.from(allResults);
          }
          setState(() {
            filteredResults = showResults;
          });
        }
      
        TextEditingController searchController = TextEditingController();
      
        @override
        void initState() {
          super.initState();
          searchController.addListener(onSearchChanged);
        }
      
        @override
        void dispose() {
          searchController.removeListener(onSearchChanged);
          searchController.dispose();
          super.dispose();
        }
      
        @override
        void didChangeDependencies() {
          super.didChangeDependencies();
          resultsLoaded = getResults();
        }
      
        @override
        Widget build(BuildContext context) {
          return Scaffold(
            backgroundColor: Theme.of(context).scaffoldBackgroundColor,
            body: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                HomeScreenHeader(
                  subText: 'Wine and Food',
                  mainText: 'Ask your Somellier',
                  boxWidth: 238,
                ),
                Padding(
                  padding: const EdgeInsets.only(
                    left: 172,
                    top: 92,
                  ),
                  child: Text(
                    'Step 4',
                    style: GoogleFonts.poppins(
                      textStyle: TextStyle(
                        color: Theme.of(context).indicatorColor,
                        fontSize: 16,
                        fontWeight: FontWeight.bold,
                      ),
                    ),
                  ),
                ),
                Padding(
                  padding: const EdgeInsets.only(
                    left: 97,
                  ),
                  child: Text(
                    widget.stepDescription,
                    style: GoogleFonts.poppins(
                      textStyle: TextStyle(
                        color: Theme.of(context).primaryColorLight,
                        fontSize: 14,
                        fontWeight: FontWeight.w600,
                      ),
                    ),
                  ),
                ),
                Padding(
                  padding: const EdgeInsets.only(
                    left: 35,
                    top: 25,
                  ),
                  child: Stack(
                    children: [
                      Container(
                        height: 35,
                        width: 320,
                        decoration: BoxDecoration(
                          color: Theme.of(context).primaryColor,
                          borderRadius: BorderRadius.circular(20.0),
                        ),
                      ),
                      Positioned(
                        left: 10,
                        top: 14.5,
                        child: SizedBox(
                          height: 21,
                          width: 300,
                          child: TextField(
                            controller: searchController,
                            style: GoogleFonts.poppins(
                                textStyle: const TextStyle(
                                    color: Colors.white,
                                    fontSize: 14,
                                    fontWeight: FontWeight.bold)),
                            decoration: InputDecoration(
                              hintText: 'Search',
                              hintStyle: GoogleFonts.poppins(
                                textStyle: TextStyle(
                                    color: Theme.of(context).hintColor,
                                    fontSize: 16,
                                    fontWeight: FontWeight.bold),
                              ),
                              border: InputBorder.none,
                            ),
                          ),
                        ),
                      ),
                      Positioned(
                        left: 320 - 35,
                        top: 119 - 110,
                        child: SizedBox(
                          height: 17,
                          width: 17,
                          child: SvgPicture.asset(
                            'assets/icons/general/search.svg',
                            color: Theme.of(context).indicatorColor,
                          ),
                        ),
                      ),
                    ],
                  ),
                ),
                Padding(
                  padding: const EdgeInsets.only(
                    left: 35,
                    top: 15,
                  ),
                  child: Text(
                    'Popular Choices',
                    style: GoogleFonts.poppins(
                      textStyle: const TextStyle(
                        color: Colors.white,
                        fontSize: 14,
                        fontWeight: FontWeight.w600,
                      ),
                    ),
                  ),
                ),
                Padding(
                    padding: const EdgeInsets.only(
                      left: 35,
                      top: 5,
                    ),
                    child: SizedBox(
                      height: 370,
                      width: 320,
                      child: Center(
                        child: ListView.builder(
                          dragStartBehavior: DragStartBehavior.down,
                          scrollDirection: Axis.vertical,
                          itemCount: filteredResults.length,
                          itemBuilder: (context, index) =&gt; widget.mealVSWine
                              ? PrefInformationCardWine(
                                  snapShotDocument: filteredResults[index],
                                  cardColor: Theme.of(context).primaryColor,
                                  isSelected:
                                      filteredResults[index] == _selectedSnapshot,
                                  onSelected: () {
                                    setState(() {
                                      _selectedSnapshot = filteredResults[index];
                                    });
                                  },
                                )
                              : PrefInformationCardMeal(
                                  snapShotDocument: filteredResults[index],
                                  cardColor: Theme.of(context).primaryColor,
                                  isSelected:
                                      filteredResults[index] == _selectedSnapshot,
                                  onSelected: () {
                                    setState(() {
                                      _selectedSnapshot = filteredResults[index];
                                    });
                                  },
                                ),
                        ),
                      ),
                    )),
                Padding(
                  padding: const Ed
  
  geInsets.only(
                left: 35,
                top: 25,
              ),
              child: SubmitSettingChangesButton(
                buttonText: 'Continue',
                cancelText: 'Cancel',
                cancelOnTap: () {
                  Navigator.pop(context);
                },
                continueOnTap: () {
                  _selectedSnapshot != null
                      ? () {
                          Navigator.pushAndRemoveUntil(
                              context,
                              createRoute(FindingRecommendationScreen(
                                snapshotName: _selectedSnapshot,
                              )),
                              (route) =&gt; false);
                        }
                      : null;
                },
              ),
            ),
            Padding(
              padding: const EdgeInsets.only(
                top: 15,
                left: 171,
              ),
              child: GestureDetector(
                onTap: () {
                  Navigator.pop(context);
                },
                child: SizedBox(
                  height: 16,
                  width: 47,
                  child: Center(
                    child: Text(
                      'Go Back',
                      style: GoogleFonts.poppins(
                        textStyle: TextStyle(
                          color: Theme.of(context).indicatorColor,
                          fontSize: 11,
                          fontWeight: FontWeight.bold,
                        ),
                      ),
                    ),
                  ),
                ),
              ),
            ),
          ],
        ),
      );
    }
  }
  </code></pre>
  <p>Code Screen 5:</p>
  <pre><code>class FindingRecommendationScreen extends StatefulWidget {
    const FindingRecommendationScreen({
      Key? key,
      required this.snapshotName,
    }) : super(key: key);
    final QueryDocumentSnapshot&lt;Map&lt;String, dynamic&gt;&gt;? snapshotName;
    @override
    State&lt;FindingRecommendationScreen&gt; createState() =&gt;
        _FindingRecommendationScreenState();
  }
  
  class _FindingRecommendationScreenState
      extends State&lt;FindingRecommendationScreen&gt; {
    bool progressDone = true;
    late Future&lt;IconData&gt; iconSnapshot;
    Future&lt;bool&gt; animationDone() async {
      await Future.delayed(const Duration(milliseconds: 3000), () {
        setState(() {
          progressDone = true;
        });
      });
      return progressDone;
    }
  
    Future&lt;IconData&gt; iconData(Future&lt;bool&gt; progress) async {
      if (await progress == true) {
        return Icons.home;
      }
      print('function used');
      return Icons.done;
    }
  
    @override
    Widget build(BuildContext context) {
      return Scaffold(
        backgroundColor: Theme.of(context).scaffoldBackgroundColor,
        body: Column(
          children: [
            Padding(
              padding: const EdgeInsets.symmetric(
                horizontal: 35,
                vertical: 100,
              ),
              child: Text(
                'Your Somellier is searching...',
                textAlign: TextAlign.center,
                style: GoogleFonts.poppins(
                  textStyle: TextStyle(
                    color: Theme.of(context).indicatorColor,
                    fontSize: 24,
                    fontWeight: FontWeight.bold,
                  ),
                ),
              ),
            ),
            Padding(
              padding: EdgeInsets.only(
                left: (MediaQuery.of(context).size.width - 200) / 2,
                right: (MediaQuery.of(context).size.width - 200) / 2,
                top: 50,
              ),
              child: CircularPercentIndicator(
                radius: 120,
                lineWidth: 4.0,
                circularStrokeCap: CircularStrokeCap.round,
                animation: true,
                animationDuration: 3000,
                percent: 1,
                // center: FutureBuilder&lt;IconData&gt;(
                //   future: iconData(animationDone()),
                //   builder: (context, snapshot) {
                //     return Icon(
                //       snapshot.data,
                //       color: Colors.white,
                //     );
                //   },
                // ),
                // center: const Icon(
                //   Icons.done_rounded,
                //   color: Colors.white,
                //   size: 90,
                // ),
                center: Text(
                  'Finding Wine ',
                  style: GoogleFonts.poppins(
                    textStyle: const TextStyle(
                      color: Colors.white,
                      fontSize: 18,
                      fontWeight: FontWeight.bold,
                    ),
                  ),
                ),
                progressColor: Theme.of(context).indicatorColor,
              ),
            ),
            Padding(
              padding: const EdgeInsets.only(
                left: 35,
                right: 35,
                top: 200,
              ),
              child: GestureDetector(
                onTap: () {
                  Navigator.pushAndRemoveUntil(
                      context,
                      createRoute(const SomellierResultScreen()),
                      (route) =&gt; false);
                },
                child: Container(
                  height: 50,
                  width: MediaQuery.of(context).size.width - 70,
                  decoration: BoxDecoration(
                    borderRadius: BorderRadius.circular(
                      25,
                    ),
                    color: Theme.of(context).primaryColor,
                  ),
                  child: Center(
                    child: Text(
                      widget.snapshotName?['name'],
                      style: GoogleFonts.poppins(
                        textStyle: TextStyle(
                          color: Theme.of(context).indicatorColor,
                          fontSize: 18,
                          fontWeight: FontWeight.bold,
                        ),
                      ),
                    ),
                  ),
                ),
              ),
            ),
          ],
        ),
      );
    }
  }
  </code></pre>
  <p><a href="https://i.stack.imgur.com/eE2EQ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/eE2EQ.png" alt="Errormessage" /></a></p>