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.