Unexpected null value ! flutter sqflite database

Hello guys i’m a beginner in flutter and dart. I try to code an application which stock some recitations those who are in primary school using sqfilt. but when i try to debung I got error. But my code doesn’t show an error.

My database file

import 'package:flutter/widgets.dart';
import 'package:flutter_cepe_project/pages/recitation.dart';
// ignore: depend_on_referenced_packages
import 'package:path/path.dart';
// ignore: depend_on_referenced_packages
import 'package:sqflite/sqflite.dart';

class RecitationDataBase {
  RecitationDataBase._();

  static final RecitationDataBase instance = RecitationDataBase._();

  static Database? _database;
  Future<Database?> get database async {
    if (_database != null) return _database;
    _database = await initDB();
    return _database;
  }

  initDB() async {
    WidgetsFlutterBinding.ensureInitialized();
    return await openDatabase(
      join(await getDatabasesPath(), 'recitation_database.db'),
      onCreate: (db, version) {
        return db.execute(
          "CREATE TABLE recitation(title TEXT PRIMARY KEY, auteur TEXT, image TEXT, description TEXT, isFavorite INTEGER, favoriteCount INTEGER)",
        );
      },
      version: 1,
    );
  }

  void insertRecitation(Recitation recitation) async {
    final Database? db = await database;

    await db?.insert(
      'recitation',
      recitation.toMap(),
      conflictAlgorithm: ConflictAlgorithm.replace,
    );
  }

  void updateRecitation(Recitation recitation) async {
    final Database? db = await database;
    await db?.update("recitation", recitation.toMap(),
        where: "title = ?", whereArgs: [recitation.title]);
  }

  void deleteRecitation(String title) async {
    final Database? db = await database;
    db?.delete("recitation", where: "title = ?", whereArgs: [title]);
  }

  Future<List<Recitation>> recitations() async {
    final Database? db = await database;
    final List<Map<String, Object?>>? maps = await db?.query('recitation');
    List<Recitation> recitations = List.generate(maps!.length, (i) {
      return Recitation.fromMap(maps[i]);
    });

    if (recitations.isEmpty) {
      for (Recitation recitation in defaultRecitations) {
        insertRecitation(recitation);
      }

      recitations = defaultRecitations;
    }

    return recitations;
  }

  static final List<Recitation> defaultRecitations = [
    Recitation(
        "l'enfant et l'oiseau",
        "Par Gloire BEMBA",
        "images/enfant.jpg",
        "Papa je t'aime énormement tu est le seul dans maivie.n dhhhhhhhhhhhhhhhhhhhhhhhhhhhhnddddddddddd",
        false,
        50),
    Recitation(
        "A ma mère",
        "Camara laye",
        "assets/images/lamp.png",
        "Femme noire, femme africaine,Ô toi ma mère, je pense à toi...Ô Daman, ô ma Mère,Toi qui me portas sur le dos,Toi qui m'allaitas, toi qui gouvernas mes premiers pas,Toi qui la première m'ouvris les yeux aux prodiges de la terre,Je pense à toi... Ô toi Daman, Ô ma mère,Toi qui essuyas mes larmes Toi qui me réjouissais le cœur,Toi qui, patiemment, supportais mes caprices,Comme j'aimerais encore être près de toi, Etre enfant près de toi !Femme simple, femme de la résignation Ô toi ma mère, je pense à toi.Ô Daman, Daman de la grande famille des forgerons, Ma pensée toujours se tourne vers toi,La tienne à chaque pas m'accompagne, Ô Daman, ma mère, Comme j'aimerais encore être dans ta chaleur,Etre enfant près de toi... Femme noire, femme africaine, Ô toi ma mère,Merci, merci pour tout ce que tu fis pour moi,Ton fils si loin, si près de toi.Femme des champs, femme des rivièresfemme du grand fleuve, ô toi, ma mèreJe pense à toi...",
        false,
        50),
    Recitation(
        "Les lignes de nos mains",
        "Par Gloire BEMBA",
        "assets/images/main.png",
        "hdddddddddddddddddddddddddddddddddddddddddddddddddddd.n dhhhhhhhhhhhhhhhhhhhhhhhhhhhhnddddddddddd",
        false,
        50),
    Recitation(
        "Le corbeau et le renard",
        "Jean de La Fontaine",
        "assets/images/corbeau.png",
        "Maître Corbeau, sur un arbre perché,Tenait en son bec un fromage. Maître Renard, par l’odeur alléché, Lui tint à peu près ce langage : « Hé ! bonjour, Monsieur du Corbeau. Que vous êtes joli ! que vous me semblez beau ! Sans mentir, si votre ramage Se rapporte à votre plumage,Vous êtes le Phénix des hôtes de ces bois. » A ces mots le Corbeau ne se sent pas de joie ; Et pour montrer sa belle voix, Il ouvre un large bec, laisse tomber sa proie. Le Renard s’en saisit, et dit : « Mon bon Monsieur, Apprenez que tout flatteur Vit aux dépens de celui qui l’écoute : Cette leçon vaut bien un fromage, sans doute. » Le Corbeau, honteux et confus,Jura, mais un peu tard, qu’on ne l’y prendrait plus.",
        false,
        50),
    Recitation(
        "Comme ton pasteur",
        "Par Gloire BEMBA",
        "assets/images/lamp.png",
        "1-hdddddddddddddddddddddddddddddddddddddddddddddddddddd. n n 2- dhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhnddddddddddd",
        false,
        50),
    Recitation(
        "Le départ pour l'école",
        "Par Gloire BEMBA",
        "assets/images/depart.jpg",
        "hdddddddddddddddddddddddddddddddddddddddddddddddddddd.n dhhhhhhhhhhhhhhhhhhhhhhhhhhhhnddddddddddd",
        false,
        50),
    Recitation(
        "Ma main",
        "Par Gloire BEMBA",
        "assets/images/main.png",
        "hdddddddddddddddddddddddddddddddddddddddddddddddddddd.n dhhhhhhhhhhhhhhhhhhhhhhhhhhhhnddddddddddd",
        false,
        50),
  ];
}

and the view who is showing errors

import 'package:flutter/material.dart';
import 'package:flutter_cepe_project/pages/recitation.dart';
import 'package:flutter_cepe_project/pages/recitationDatabase.dart';
import 'package:flutter_cepe_project/pages/recitationEcran.dart';

class RecitationListeEcran extends StatefulWidget {
  const RecitationListeEcran({super.key});

  @override
  State<StatefulWidget> createState() {
    return RecitationListState();
  }
}

class RecitationListState extends State<RecitationListeEcran> {
  @override
  Widget build(BuildContext context) {
    return FutureBuilder<List<Recitation>>(
        future: RecitationDataBase.instance.recitations(),
        builder:
            (BuildContext context, AsyncSnapshot<List<Recitation>> snapshot) {
        
            List<Recitation>? recitations = snapshot.data;
            return ListView.builder(
              itemCount: recitations?.length,
              itemBuilder: (context, index) {
                final recitation = recitations![index];
                return Dismissible(
                    key: Key(recitation.title),
                    onDismissed: (direction) {
                      setState(() {
                        RecitationDataBase.instance
                            .deleteRecitation(recitation.title);
                      });
                      ScaffoldMessenger.of(context).showSnackBar(SnackBar(
                          content: Text("${recitation.title} supprimé")));
                    },
                    background: Container(color: Colors.red),
                    child: RecitationItemWidget(recitation: recitation));
              },
            );
          
        });
  }
}

class RecitationItemWidget extends StatelessWidget {
  const RecitationItemWidget({Key? key, required this.recitation})
      : super(key: key);
  final Recitation recitation;

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: () {
        Navigator.push(
            context,
            PageRouteBuilder(
                pageBuilder: (context, animation, secondaryAnimation) =>
                    RecitationEcran(recitation: recitation),
                transitionsBuilder:
                    ((context, animation, secondaryAnimation, child) {
                  animation =
                      CurvedAnimation(parent: animation, curve: Curves.ease);

                  return FadeTransition(
                    opacity: animation,
                    child: child,
                  );
                })));
      },
      child: Card(
        margin: const EdgeInsets.all(2),
        elevation: 8,
        child: Row(children: [
          Hero(
            tag: "imageRecitation" + recitation.title,
            child: Image.asset(
              recitation.image,
              width: 100,
              height: 100,
              fit: BoxFit.cover,
            ),
          ),
          Padding(
            padding: const EdgeInsets.all(10),
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Container(
                    padding: const EdgeInsets.only(bottom: 8),
                    child: Text(
                      recitation.title,
                      style: const TextStyle(
                          fontWeight: FontWeight.bold, fontSize: 20),
                    )),
                Text(
                  recitation.auteur,
                  style: TextStyle(color: Colors.grey[400], fontSize: 20),
                )
              ],
            ),
          )
        ]),
      ),
    );
  }
}

Try to help me please

I want to see all default recitation in the first page

New contributor

Melan Gloire Régis BEMBA 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