Skip to content

Commit

Permalink
fix: use conditional imports for web platform
Browse files Browse the repository at this point in the history
  • Loading branch information
JVMerkle committed Dec 4, 2024
1 parent f7f73b4 commit fcd03ab
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 2 deletions.
4 changes: 2 additions & 2 deletions kitchenowl/lib/cubits/auth_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import 'package:kitchenowl/services/api/api_service.dart';
import 'package:kitchenowl/services/storage/mem_storage.dart';
import 'package:kitchenowl/services/storage/storage.dart';
import 'package:kitchenowl/services/transaction_handler.dart';
import 'dart:html' as html;
import 'package:kitchenowl/platform/dart_html/dart_html.dart' as html;

class AuthCubit extends Cubit<AuthState> {
bool _forcedOfflineMode = false;
Expand All @@ -33,7 +33,7 @@ class AuthCubit extends Cubit<AuthState> {
url = kIsWeb
? kDebugMode
? "http://localhost:5000"
: html.document.baseUri.toString()
: html.getBaseUri()
: await PreferenceStorage.getInstance().read(key: 'URL') ??
Config.defaultServer;
final token = await SecureStorage.getInstance().read(key: 'TOKEN');
Expand Down
1 change: 1 addition & 0 deletions kitchenowl/lib/platform/dart_html/dart_html.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export 'dart_non_web.dart' if (dart.library.html) 'dart_web.dart';
3 changes: 3 additions & 0 deletions kitchenowl/lib/platform/dart_html/dart_non_web.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
String getBaseUri() {
return '';
}
5 changes: 5 additions & 0 deletions kitchenowl/lib/platform/dart_html/dart_web.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import 'dart:html' as html;

String getBaseUri() {
return html.document.baseUri.toString();
}

0 comments on commit fcd03ab

Please sign in to comment.