Skip to content

Commit f807317

Browse files
committed
Update for testing
1 parent 1f233c4 commit f807317

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

lib/src/local_db.dart

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ import 'package:flutter_local_db/src/service/local_db_result.dart';
88

99
import 'core/log.dart';
1010
import 'database/database.dart';
11+
import 'database/database_mock.dart';
1112
import 'model/local_db_request_model.dart';
13+
import 'utils/system_utils.dart';
1214

1315
/// A comprehensive local database management utility.
1416
///
@@ -28,7 +30,10 @@ class LocalDB {
2830
static DatabaseInterface get _platformDatabase {
2931
if (_database != null) return _database!;
3032

31-
if (kIsWeb) {
33+
// Use mock database in test environment to avoid FFI issues
34+
if (SystemUtils.isTest) {
35+
_database = DatabaseMock.instance;
36+
} else if (kIsWeb) {
3237
_database = DatabaseWeb.instance;
3338
} else {
3439
_database = DatabaseNative.instance;

lib/src/widgets/local_db_lifecycle_manager.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import 'package:flutter/foundation.dart';
22
import 'package:flutter/widgets.dart';
33
import '../core/log.dart';
44
import '../local_db.dart';
5+
import '../utils/system_utils.dart';
56

67
/// A widget that automatically manages LocalDB lifecycle during hot restart
78
/// and app lifecycle changes. This helps prevent crashes during development.
@@ -31,8 +32,8 @@ class _LocalDbLifecycleManagerState extends State<LocalDbLifecycleManager>
3132
super.initState();
3233
WidgetsBinding.instance.addObserver(this);
3334

34-
// In debug mode, listen for hot restart
35-
if (kDebugMode) {
35+
// In debug mode, listen for hot restart (but not during tests)
36+
if (kDebugMode && !SystemUtils.isTest) {
3637
_setupHotRestartListener();
3738
}
3839
}

0 commit comments

Comments
 (0)