【发布时间】:2021-10-25 00:34:23
【问题描述】:
为什么这个 Dart 代码给出“操作数不能为空,所以条件总是为真。删除条件”?
import 'package:sqflite/sqflite.dart';
class DatabaseHelper {
static final DatabaseHelper instance = DatabaseHelper._privateConstructor();
static late Database _database;
DatabaseHelper._privateConstructor();
Future<Database> get database async {
if (_database != null) return _database; // HERE: "The operand can't be null, so the condition is always true. Remove the condition"
_database = await _initDatabase();
return _database;
}
Future<Database> _initDatabase() async {
Database _db = await openDatabase('my_db.db');
return _db;
}
}
【问题讨论】:
-
你对错误信息的理解到底是什么?