Skip to content

Commit 908d619

Browse files
committed
Fix web build
1 parent 76065c7 commit 908d619

File tree

5 files changed

+28
-6
lines changed

5 files changed

+28
-6
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export 'unsupported.dart'
2+
if (dart.library.ffi) 'native.dart';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import 'package:drift/backends.dart';
2+
import 'package:drift/drift.dart';
3+
import 'package:drift/native.dart';
4+
5+
QueryExecutor inMemoryExecutor() {
6+
return NativeDatabase.memory();
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import 'package:drift/drift.dart';
2+
3+
Never _unsupported() {
4+
throw UnsupportedError(
5+
'No suitable database implementation was found on this platform.');
6+
}
7+
8+
// Depending on the platform the app is compiled to, the following stubs will
9+
// be replaced with the methods in native.dart or web.dart
10+
11+
QueryExecutor inMemoryExecutor() {
12+
return _unsupported();
13+
}
14+
Future<void> validateDatabaseSchema(GeneratedDatabase database) async {
15+
_unsupported();
16+
}

flutter/example/lib/drift/database.dart

-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
import 'dart:io';
2-
31
import 'package:drift/drift.dart';
4-
import 'package:drift/native.dart';
52

63
part 'database.g.dart';
74

flutter/example/lib/main.dart

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import 'dart:async';
44
import 'dart:convert';
55

6-
import 'package:drift/native.dart';
76
import 'package:flutter/foundation.dart';
87
import 'package:flutter/material.dart';
98
import 'package:flutter/services.dart';
@@ -19,6 +18,7 @@ import 'package:universal_platform/universal_platform.dart';
1918
import 'package:feedback/feedback.dart' as feedback;
2019
import 'package:provider/provider.dart';
2120
import 'drift/database.dart';
21+
import 'drift/connection/connection.dart';
2222
import 'user_feedback_dialog.dart';
2323
import 'package:dio/dio.dart';
2424
import 'package:sentry_dio/sentry_dio.dart';
@@ -153,7 +153,7 @@ class MainScaffold extends StatelessWidget {
153153
children: [
154154
if (_isIntegrationTest) const IntegrationTestWidget(),
155155
const Center(child: Text('Trigger an action:\n')),
156-
// For simplicity sake we skip the web set up.
156+
// For simplicity sake we skip the web set up for now.
157157
if (!UniversalPlatform.isWeb)
158158
ElevatedButton(
159159
onPressed: () => driftTest(),
@@ -486,7 +486,7 @@ class MainScaffold extends StatelessWidget {
486486
);
487487

488488
final executor = SentryQueryExecutor(
489-
() => NativeDatabase.memory(),
489+
() async => inMemoryExecutor(),
490490
databaseName: 'sentry_inmemory_db',
491491
);
492492

0 commit comments

Comments
 (0)