initialize static method
void
initialize({
- bool enabled = !_isProduct && !_isProfile,
- bool readOnly = false,
- InspectorLimits limits = const InspectorLimits(),
- Set<
String> sensitiveColumns = const {}, - bool allowInReleaseMode = false,
- List<
InspectorDatabase> databases = const [],
Enables the inspector and registers databases.
DbInspector.initialize(
enabled: kDebugMode,
databases: [
InspectorDatabase(name: 'app_database', adapter: SqliteAdapter(db)),
InspectorDatabase(name: 'cache', adapter: HiveAdapter([box])),
],
);
Databases opened later can still be added with registerDatabase.
When the inspector is disabled, databases are not registered (nothing
keeps a reference to them).
enabled defaults to true only in debug builds. In release builds the
inspector stays disabled even when enabled: true is passed, unless
allowInReleaseMode is also set (release builds have no VM service, so
this only matters for custom embedders).
Implementation
static void initialize({
bool enabled = !_isProduct && !_isProfile,
bool readOnly = false,
InspectorLimits limits = const InspectorLimits(),
Set<String> sensitiveColumns = const {},
bool allowInReleaseMode = false,
List<InspectorDatabase> databases = const [],
}) {
final ids = <String>{};
for (final db in databases) {
if (!ids.add(DbRegistry.idFor(db.name))) {
throw ArgumentError.value(
db.name,
'databases',
'is listed more than once',
);
}
}
if (!enabled || (_isProduct && !allowInReleaseMode)) {
_config = _config.copyWith(mode: InspectorMode.disabled);
return;
}
// Register before exposing the extension so the first client sees them.
for (final db in databases) {
registerDatabase(
name: db.name, adapter: db.adapter, readOnly: db.readOnly);
}
_config = InspectorConfig(
mode: readOnly ? InspectorMode.readOnly : InspectorMode.fullAccess,
limits: limits,
sensitiveColumns: sensitiveColumns,
);
registerInspectorServiceExtension(router);
developer.log(
'Flutter DB Inspector enabled (${_config.mode.name})',
name: 'flutter_db_inspector',
);
}