Skip to content

Commit

Permalink
Merge pull request #36 from wednesday-solutions/support_for_web
Browse files Browse the repository at this point in the history
Adding support for web
  • Loading branch information
aliHafizji authored Oct 28, 2022
2 parents c592de6 + 1c5a641 commit 48fbff2
Show file tree
Hide file tree
Showing 26 changed files with 381 additions and 166 deletions.
2 changes: 1 addition & 1 deletion ios/Podfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Uncomment this line to define a global platform for your project
# platform :ios, '9.0'
# platform :ios, '11.0'

# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
ENV['COCOAPODS_DISABLE_STATS'] = 'true'
Expand Down
5 changes: 3 additions & 2 deletions lib/app.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'dart:io';

import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_displaymode/flutter_displaymode.dart';
Expand Down Expand Up @@ -42,7 +43,7 @@ Future _initialiseApp() async {

EasyLocalization.logger.printer = customEasyLogger;

if (Platform.isAndroid) {
if (!kIsWeb && Platform.isAndroid) {
try {
FlutterDisplayMode.setHighRefreshRate();
} on PlatformException catch (exception) {
Expand All @@ -67,4 +68,4 @@ void _initialiseGetIt() {
..interactorModule()
..presentationModule()
..navigationModule();
}
}
1 change: 0 additions & 1 deletion lib/domain/entity/base/datetime/date.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import 'package:flutter/foundation.dart';
import 'package:freezed_annotation/freezed_annotation.dart';

part 'date.freezed.dart';
Expand Down
1 change: 0 additions & 1 deletion lib/domain/entity/base/datetime/date_time.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import 'package:flutter/foundation.dart';
import 'package:freezed_annotation/freezed_annotation.dart';

part 'date_time.freezed.dart';
Expand Down
1 change: 0 additions & 1 deletion lib/domain/entity/base/datetime/time.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import 'package:flutter/foundation.dart';
import 'package:freezed_annotation/freezed_annotation.dart';

part 'time.freezed.dart';
Expand Down
1 change: 0 additions & 1 deletion lib/domain/entity/base/result/result.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import 'package:flutter/foundation.dart';
import 'package:freezed_annotation/freezed_annotation.dart';

part 'result.freezed.dart';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import 'package:flutter/foundation.dart';
import 'package:flutter_template/presentation/entity/intent/intent.dart';
import 'package:freezed_annotation/freezed_annotation.dart';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import 'package:flutter/foundation.dart';
import 'package:flutter_template/presentation/entity/base/ui_list_item.dart';
import 'package:flutter_template/presentation/entity/base/ui_toolbar.dart';
import 'package:flutter_template/presentation/entity/screen/screen_state.dart';
Expand Down
1 change: 0 additions & 1 deletion lib/presentation/entity/base/ui_result.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import 'package:flutter/foundation.dart';
import 'package:freezed_annotation/freezed_annotation.dart';

part 'ui_result.freezed.dart';
Expand Down
1 change: 0 additions & 1 deletion lib/presentation/entity/effect/effect.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:freezed_annotation/freezed_annotation.dart';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import 'package:flutter/foundation.dart';
import 'package:flutter_template/presentation/entity/base/ui_list_item.dart';
import 'package:freezed_annotation/freezed_annotation.dart';

Expand Down
1 change: 0 additions & 1 deletion lib/presentation/entity/weather/ui_weather.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import 'package:flutter/foundation.dart';
import 'package:flutter_template/presentation/entity/base/ui_list_item.dart';
import 'package:freezed_annotation/freezed_annotation.dart';

Expand Down
21 changes: 3 additions & 18 deletions lib/services/base/database/app_database.dart
Original file line number Diff line number Diff line change
@@ -1,23 +1,18 @@
import 'dart:io';

import 'package:drift/drift.dart';
import 'package:drift/native.dart';
import 'package:flutter_template/flavors/flavor_config.dart';
import 'package:flutter_template/services/base/database/migrations.dart';
import 'package:flutter_template/services/entity/open_weather/current_weather/local/local_current_weather.dart';
import 'package:flutter_template/services/entity/open_weather/geo_coding/local/local_location.dart';
import 'package:flutter_template/services/weather/local/weather_local_service_impl.dart';
import 'package:path/path.dart' as p;
import 'package:path_provider/path_provider.dart';
export 'connection/connection.dart';

part 'app_database.g.dart';

@DriftDatabase(
tables: [LocalLocation, LocalCurrentWeather],
daos: [WeatherLocalServiceImpl],
daos: [WeatherLocalServiceImpl]
)
class AppDatabase extends _$AppDatabase {
AppDatabase() : super(_openConnection());
AppDatabase(QueryExecutor e) : super(e);

@override
int get schemaVersion => 1;
Expand All @@ -26,13 +21,3 @@ class AppDatabase extends _$AppDatabase {
MigrationStrategy get migration => migrations();
}

LazyDatabase _openConnection() {
return LazyDatabase(() async {
final dbFolder = await getApplicationDocumentsDirectory();
final file = File(p.join(dbFolder.path, 'template_app_db.sqlite'));
return NativeDatabase(
file,
logStatements: FlavorConfig.instance.values.logSqlStatements,
);
});
}
3 changes: 3 additions & 0 deletions lib/services/base/database/connection/connection.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export 'unsupported.dart'
if (dart.library.js) 'web.dart'
if (dart.library.ffi) 'mobile.dart';
20 changes: 20 additions & 0 deletions lib/services/base/database/connection/mobile.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import 'dart:io';
import 'package:drift/drift.dart';
import 'package:flutter_template/flavors/flavor_config.dart';
import 'package:flutter_template/services/base/database/app_database.dart';
import 'package:path_provider/path_provider.dart';
import 'package:drift/native.dart';
import 'package:path/path.dart' as p;

AppDatabase connect() {
final db = LazyDatabase(() async {
final dbFolder = await getApplicationDocumentsDirectory();
final file = File(p.join(dbFolder.path, 'template_app_db.sqlite'));
return NativeDatabase(
file,
logStatements: FlavorConfig.instance.values.logSqlStatements,
);
});

return AppDatabase(db);
}
6 changes: 6 additions & 0 deletions lib/services/base/database/connection/unsupported.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import 'package:flutter_template/services/base/database/app_database.dart';

AppDatabase connect() {
throw UnsupportedError(
'No suitable database implementation was found on this platform.');
}
7 changes: 7 additions & 0 deletions lib/services/base/database/connection/web.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

import 'package:drift/web.dart';
import 'package:flutter_template/services/base/database/app_database.dart';

AppDatabase connect() {
return AppDatabase(WebDatabase('db'));
}
2 changes: 1 addition & 1 deletion lib/services/di/service_module.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ extension ServiceModule on GetIt {
);

// Drift
registerLazySingleton<AppDatabase>(() => AppDatabase());
registerLazySingleton<AppDatabase>(() => connect());

// Shared Preferences
registerLazySingleton<PreferencesService>(() => PreferencesServiceImpl(
Expand Down
Loading

0 comments on commit 48fbff2

Please sign in to comment.