1

Problem: The method 'query' can't be unconditionally invoked because the receiver can be 'null'.

1 - I already checked that the _database is not null. How do I get around this?

2 - I'm not sure how to add my returned Rung object to mylist.

 Future<Object?> get database async {
    if (_database != null) {
      dev.log('1 My db is NOT null: $_database', name: 'db_helper.dart');

      final List<Map<String, dynamic>> maps = await _database.query('dbtable');
      return List.generate(maps.length, (i) {
        return Rung(
          rungId: maps[i]['colId'],
          name: maps[i]['colTask'] ?? 'unknown',
          done: maps[i]['colDone'] ?? 'false',
          boldTitle: maps[i]['colBold'] ?? 'false',
          info: maps[i]['colInfo'] ?? '',

        );
      });


      // Rung rung = Rung(rungId: colId, name: colTask, done: colDone.toLowerCase()=='true', boldTitle: colBold.toLowerCase()=='true', info: colInfo);
      //Rung.myList.add(rung);

1 Answer 1

1

This seems to be a case when you simply can use a bang ! operator because you can be sure that database is not null:

final List<Map<String, dynamic>> maps = await _database!.query('dbtable');

Not the answer you're looking for? Browse other questions tagged or ask your own question.