I get this error when I run the app. I have followed a youtube tutorial but in my case, the error A non-null String must be provided to a Text widget always comes up. I've already tried multiple things but nothing happened. I don't know what else I can write... but I can't post the question without giving more detailed information. How can I solve this problem?

import 'package:flutter/material.dart';
import 'package:cloud_firestore/cloud_firestore.dart';

void main() => runApp(MaterialApp(
  debugShowCheckedModeBanner: false,
        theme: ThemeData(
          brightness: Brightness.light,
          primaryColor: Colors.blue,
          accentColor: Colors.orange
    home: MyApp(),

class MyApp extends StatefulWidget {
  _MyAppState createState() => _MyAppState();

class _MyAppState extends State<MyApp> {

  List todos = List();
  String input = "";

  createTodos() {
    DocumentReference documentReference =

    Map<String, String> todos = {"todoTitle": input};

    documentReference.setData(todos).whenComplete(() {
      print("$input created");

  deleteTodos() {


  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('My ToDos'),
      floatingActionButton: FloatingActionButton(
        onPressed: () {
            context: context,
            builder: (BuildContext context) {
              return AlertDialog(
                title: Text('Add ToDo', style: TextStyle(fontWeight: FontWeight.bold),),
                shape: RoundedRectangleBorder(
                  borderRadius: BorderRadius.circular(15)
                content: TextField(
                  onChanged: (String value) {
                    input = value;
                actions: <Widget>[
                      onPressed: () {

                      child: Text('Add'))
        child: Icon(
            color: Colors.white,
      body: StreamBuilder(
          stream: Firestore.instance.collection("MyTodos").snapshots(),
          builder: (context, snapshots){

            if(snapshots.data == null) return CircularProgressIndicator();

        return ListView.builder(
          shrinkWrap: true,
            itemCount: snapshots.data.documents.length,
            itemBuilder: (context, index) {
              DocumentSnapshot documentSnapshot = snapshots.data.documents[index];
              return Dismissible(
                  key: Key(index.toString()),
                  child: Card(
                    elevation: 4,
                    margin: EdgeInsets.all(8),
                    shape: RoundedRectangleBorder(
                        borderRadius: BorderRadius.circular(10)
                    child: ListTile(
                      title: Text(documentSnapshot["todoTitle"]),
                      trailing: IconButton(
                          icon: Icon(
                          color: Colors.red,
                          onPressed: (){
                            setState(() {
                          } ),

Solution 1: CopsOnRoad

Your documentSnapshot["todoTitle"] is returning null and you shouldn't provide any null value to Text widget. So, a solution would be to use something like

Text(documentSnapshot["todoTitle"] ?? "No title found")