Skip to content

Commit

Permalink
Fix web build
Browse files Browse the repository at this point in the history
  • Loading branch information
buenaflor committed Nov 14, 2023
1 parent 76065c7 commit 908d619
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 6 deletions.
2 changes: 2 additions & 0 deletions flutter/example/lib/drift/connection/connection.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export 'unsupported.dart'
if (dart.library.ffi) 'native.dart';
7 changes: 7 additions & 0 deletions flutter/example/lib/drift/connection/native.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import 'package:drift/backends.dart';
import 'package:drift/drift.dart';
import 'package:drift/native.dart';

QueryExecutor inMemoryExecutor() {
return NativeDatabase.memory();
}
16 changes: 16 additions & 0 deletions flutter/example/lib/drift/connection/unsupported.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import 'package:drift/drift.dart';

Never _unsupported() {
throw UnsupportedError(
'No suitable database implementation was found on this platform.');
}

// Depending on the platform the app is compiled to, the following stubs will
// be replaced with the methods in native.dart or web.dart

QueryExecutor inMemoryExecutor() {
return _unsupported();
}
Future<void> validateDatabaseSchema(GeneratedDatabase database) async {
_unsupported();
}
3 changes: 0 additions & 3 deletions flutter/example/lib/drift/database.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import 'dart:io';

import 'package:drift/drift.dart';
import 'package:drift/native.dart';

part 'database.g.dart';

Expand Down
6 changes: 3 additions & 3 deletions flutter/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import 'dart:async';
import 'dart:convert';

import 'package:drift/native.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
Expand All @@ -19,6 +18,7 @@ import 'package:universal_platform/universal_platform.dart';
import 'package:feedback/feedback.dart' as feedback;
import 'package:provider/provider.dart';
import 'drift/database.dart';
import 'drift/connection/connection.dart';
import 'user_feedback_dialog.dart';
import 'package:dio/dio.dart';
import 'package:sentry_dio/sentry_dio.dart';
Expand Down Expand Up @@ -153,7 +153,7 @@ class MainScaffold extends StatelessWidget {
children: [
if (_isIntegrationTest) const IntegrationTestWidget(),
const Center(child: Text('Trigger an action:\n')),
// For simplicity sake we skip the web set up.
// For simplicity sake we skip the web set up for now.
if (!UniversalPlatform.isWeb)
ElevatedButton(
onPressed: () => driftTest(),
Expand Down Expand Up @@ -486,7 +486,7 @@ class MainScaffold extends StatelessWidget {
);

final executor = SentryQueryExecutor(
() => NativeDatabase.memory(),
() async => inMemoryExecutor(),
databaseName: 'sentry_inmemory_db',
);

Expand Down

0 comments on commit 908d619

Please sign in to comment.