Skip to content

Commit

Permalink
feat: added hive to template (#196)
Browse files Browse the repository at this point in the history
Co-authored-by: Nicolás Lantean <[email protected]>
  • Loading branch information
f7deleon and nicolantean authored May 14, 2024
1 parent 539be40 commit d0c255d
Show file tree
Hide file tree
Showing 18 changed files with 164 additions and 383 deletions.
4 changes: 0 additions & 4 deletions .fvm/fvm_config.json

This file was deleted.

3 changes: 3 additions & 0 deletions .fvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"flutter": "3.13.9"
}
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ mason-lock.json
# The .vscode folder contains launch configuration and tasks you configure in
# VS Code which you may wish to be included in version control, so this line
# is commented out by default.
#.vscode/
.vscode/settings.json

# Flutter/Dart/Pub related
**/doc/api/
Expand Down Expand Up @@ -54,7 +54,7 @@ app.*.map.json
*.env.default

# Fvm
.fvm/flutter_sdk
.fvm/

# fastlane specific
**/fastlane/report.xml
Expand Down
3 changes: 3 additions & 0 deletions lib/core/common/config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import 'package:flutter_template/core/common/environments.dart';
import 'package:flutter_template/core/common/extension/string_extensions.dart';
import 'package:flutter_template/core/common/helper/enum_helpers.dart';
import 'package:flutter_template/core/common/helper/env_helper.dart';
import 'package:path_provider/path_provider.dart';

interface class Config {
static const String environmentFolder = 'environments';
Expand All @@ -15,6 +16,7 @@ interface class Config {

static late String apiBaseUrl;
static late String supabaseApiKey;
static late String appDirectoryPath;

static final _environment = enumFromString(
Environments.values,
Expand All @@ -25,6 +27,7 @@ interface class Config {
static Future<void> initialize() async {
await _EnvConfig._setupEnv(_environment);
_initializeEnvVariables();
appDirectoryPath = (await getApplicationDocumentsDirectory()).path;
}

static void _initializeEnvVariables() {
Expand Down
4 changes: 0 additions & 4 deletions lib/core/di/app_providers_module.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import 'package:flutter_template/core/source/common/app_database.dart';
import 'package:get_it/get_it.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:flutter_template/core/source/common/local_shared_preferences_storage.dart';
Expand All @@ -20,9 +19,6 @@ class AppProvidersModule {

extension _GetItDiModuleExtensions on GetIt {
void _setupModule() {
registerSingletonAsync(
() => $FloorAppDatabase.databaseBuilder('app_database.db').build(),
);
registerLazySingleton(FlutterSecureStorage.new);
registerSingletonAsync(() => SharedPreferences.getInstance());

Expand Down
6 changes: 3 additions & 3 deletions lib/core/di/di_repository_module.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import 'package:flutter_template/core/repository/project_repository.dart';
import 'package:flutter_template/core/repository/session_repository.dart';
import 'package:flutter_template/core/source/auth_local_source.dart';
import 'package:flutter_template/core/source/auth_remote_source.dart';
import 'package:flutter_template/core/source/common/app_database.dart';
import 'package:flutter_template/core/source/common/auth_interceptor.dart';
import 'package:flutter_template/core/source/common/http_service.dart';
import 'package:flutter_template/core/source/project_local_source.dart';
import 'package:flutter_template/core/source/project_remote_source.dart';
import 'package:get_it/get_it.dart';

Expand All @@ -30,14 +30,14 @@ extension _GetItDiModuleExtensions on GetIt {
}

void _setupRepositories() {
registerLazySingleton(() => SessionRepository(get(), get(), get()));
registerLazySingleton(() => SessionRepository(get(), get()));
registerLazySingleton(() => ProjectRepository(get(), get()));
}

void _setupSources() {
registerLazySingleton(() => AuthLocalSource(get()));
registerLazySingleton(() => AuthRemoteSource(get()));
registerLazySingleton(() => get<AppDatabase>().projectLocalSource);
registerLazySingleton(() => ProjectLocalSource());
registerLazySingleton(() => ProjectRemoteSource(get()));
}
}
21 changes: 0 additions & 21 deletions lib/core/model/db/repository_db_entity.dart

This file was deleted.

38 changes: 0 additions & 38 deletions lib/core/model/serializer/project_serializer.dart

This file was deleted.

11 changes: 5 additions & 6 deletions lib/core/repository/project_repository.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import 'package:flutter_template/core/model/db/repository_db_entity.dart';
import 'package:flutter_template/core/model/project.dart';
import 'package:flutter_template/core/model/serializer/project_serializer.dart';
import 'package:flutter_template/core/source/project_local_source.dart';
import 'package:flutter_template/core/source/project_remote_source.dart';
import 'package:stock/stock.dart';
Expand All @@ -19,10 +17,11 @@ class ProjectRepository {
fetcher: Fetcher.ofFuture(
(_) => _projectRemoteSource.getProjects(),
),
sourceOfTruth: SourceOfTruth<dynamic, List<ProjectDbEntity>>(
reader: (_) => _projectLocalSource.getProjects(),
writer: (_, value) => _projectLocalSource.replaceProjects(value),
).mapToUsingMapper(ProjectListStockTypeMapper()),
sourceOfTruth: SourceOfTruth<dynamic, List<Project>>(
reader: (_) => _projectLocalSource.getElementsStream(),
writer: (_, value) =>
_projectLocalSource.replaceProjects(value ?? []),
),
);

Stream<List<Project>?> getProjects() => _store
Expand Down
6 changes: 2 additions & 4 deletions lib/core/repository/session_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@ import 'package:flutter_template/core/model/authentication_status.dart';
import 'package:flutter_template/core/model/user.dart';
import 'package:flutter_template/core/source/auth_local_source.dart';
import 'package:flutter_template/core/source/auth_remote_source.dart';
import 'package:flutter_template/core/source/common/app_database.dart';
import 'package:hive/hive.dart';

class SessionRepository {
final AuthLocalSource _authLocalSource;
final AuthRemoteSource _authRemoteSource;
final AppDatabase _appDataBase;

SessionRepository(
this._appDataBase,
this._authLocalSource,
this._authRemoteSource,
);
Expand All @@ -36,7 +34,7 @@ class SessionRepository {
}

Future<void> logOut() async {
await _appDataBase.clearAllTables();
await Hive.deleteFromDisk();
await _authLocalSource.saveUserToken(null);
await _authLocalSource.saveUserInfo(null);
}
Expand Down
19 changes: 0 additions & 19 deletions lib/core/source/common/app_database.dart

This file was deleted.

167 changes: 0 additions & 167 deletions lib/core/source/common/app_database.g.dart

This file was deleted.

Loading

0 comments on commit d0c255d

Please sign in to comment.