Skip to content

Commit

Permalink
Fixed analyze issues
Browse files Browse the repository at this point in the history
  • Loading branch information
prijindal committed Oct 17, 2024
1 parent cc01ba3 commit 35b6fe9
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 6 deletions.
1 change: 1 addition & 0 deletions lib/helpers/constants.dart
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
const statsIntervalPreference = "STATS_INTERVAL_PREFERENCE";
const appThemeMode = "APP_THEME_MODE";
const dbFileName = "habbit_tracker.sqlite";
2 changes: 1 addition & 1 deletion lib/models/core.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class HabbitEntry extends Table {

// this annotation tells drift to prepare a database class that uses both of the
// tables we just defined. We'll see how to use that database class in a moment.
@DriftDatabase(tables: [HabbitEntry])
@DriftDatabase(tables: [HabbitEntry, Habbit])
class SharedDatabase extends _$SharedDatabase {
SharedDatabase(super.e);

Expand Down
3 changes: 1 addition & 2 deletions lib/models/core.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion lib/models/native.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ import 'package:drift/native.dart';
import 'package:path/path.dart' as p;
import 'package:path_provider/path_provider.dart';

import '../helpers/constants.dart';
import '../helpers/logger.dart';
import "./core.dart";

SharedDatabase constructDb() {
final db = LazyDatabase(() async {
final dbFolder = await getApplicationDocumentsDirectory();
final path = p.join(dbFolder.path, 'habbit_tracker.sqlite');
final path = p.join(dbFolder.path, dbFileName);
AppLogger.instance.d("Db Path: $path");
final file = File(path);
return NativeDatabase(file);
Expand Down
26 changes: 24 additions & 2 deletions lib/models/web.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,29 @@
import 'package:drift/web.dart';
import 'package:drift/drift.dart';
import 'package:drift/wasm.dart';

import '../helpers/constants.dart';
import './core.dart';

DatabaseConnection connectOnWeb() {
return DatabaseConnection.delayed(Future(() async {
final result = await WasmDatabase.open(
databaseName: dbFileName,
sqlite3Uri: Uri.parse('sqlite3.wasm'),
driftWorkerUri: Uri.parse('drift_worker.dart.js'),
);

if (result.missingFeatures.isNotEmpty) {
// Depending how central local persistence is to your app, you may want
// to show a warning to the user if only unrealiable implemetentations
// are available.
// print('Using ${result.chosenImplementation} due to missing browser '
// 'features: ${result.missingFeatures}');
}

return result.resolvedExecutor;
}));
}

SharedDatabase constructDb() {
return SharedDatabase(WebDatabase('db'));
return SharedDatabase(connectOnWeb());
}

0 comments on commit 35b6fe9

Please sign in to comment.