the errors that i'm getting are as follows: The non-nullable local variable 'basicdic'…
- User
the errors that i'm getting are as follows: The non-nullable local variable 'basic_dic' must be assigned before it can be used. and The argument type 'Map<dynamic, dynamic>' can't be assigned to the parameter type 'Map<String, dynamic>'.
following is my flutter code for what i'm getting the above mentioned errors: import 'package:flutter/services.dart'; import 'package:sqflite/sqflite.dart'; import 'package:path/path.dart' as path; import 'package:path_provider/path_provider.dart'; import 'dart:io' as io;
import 'db_model.dart';
class DictionaryDataBaseHelper { late Database _db;
Future init() async { io.Directory applicationDirectory = await getApplicationDocumentsDirectory();
codeString dbPathEnglish = path.join(applicationDirectory.path, "dic.db"); bool dbExistsEnglish = await io.File(dbPathEnglish).exists(); if (!dbExistsEnglish) { // Copy from asset ByteData data = await rootBundle.load(path.join("assets", "dic.db")); List<int> bytes = data.buffer.asUint8List(data.offsetInBytes, data.lengthInBytes); // Write and flush the bytes written await io.File(dbPathEnglish).writeAsBytes(bytes, flush: true); } this._db = await openDatabase(dbPathEnglish);}
/// get all the words from english dictionary Future<List> getAllTheWordsEnglish() async { if (_db == null) { throw "bd is not initiated, initiate using [init(db)] function"; } List basic_dic;
codeawait _db.transaction((txn) async { basic_dic = await txn.query( "basic_dic", columns: [ "head_word", "meaning", ], ); }); return basic_dic.map((e) => EnglishWord.fromJson(e)).toList();} }
- Assistant
The first error you are getting "The non-nullable local variable 'basic_dic' must be assigned before it can be used" is because you have declared the variable as but you are not assigning any value to it before using it. To fix this error, you can assign an empty list initially:
- User
how to show the data from dic.db
- Assistant
To show the data from the
dic.dbfile, you can use thegetAllTheWordsEnglish()method that retrieves all the words from the database. You can then display the data in your Flutter application UI.Here's an example of how you can show the data in a
ListViewwidget:dart