Skip to content

Commit

Permalink
Refactored some changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Eldar2021 committed Jul 2, 2024
1 parent 794d981 commit 823dfd8
Show file tree
Hide file tree
Showing 19 changed files with 140 additions and 39 deletions.
44 changes: 33 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,56 +26,78 @@ My Quran Hatim Aplication.
### Getting Started

## Requirements

- Dart sdk: ">=3.3.0 <4.0.0"
- Flutter: "3.19.5"
- Android: minSdkVersion 19
- iOS: --ios-language swift, Xcode version >= 15.0.0

## Melos

[Melos](https://melos.invertase.dev/) splitting up large code bases into separate independently versioned packages is extremely useful for code sharing. However, making changes across many repositories is messy and difficult to track, and testing across repositories gets complicated really fast.
To solve these (and many other) problems, some projects will organize their code bases into multi-package repositories (sometimes called [monorepos](https://en.wikipedia.org/wiki/Monorepo)).

* Install melos
- Install melos

```shell
dart pub global activate melos
```

Setup

```shell
melos bootstrap
```

## Run App
* If you have an AVD or real device attached, you can do

- If you have an AVD or real device attached, you can do

```shell
melos run-app
```

## Run tests
* run all tests from the command line:

- run all tests from the command line:

```shell
melos test
```

## Integration tests
* run integration tests in `test_driver` directory:

- run integration tests in `test_driver` directory:

```shell
melos integration-test
```

## Fmt
`dartfmt` lacks config file support, which implies that customizations need to be done by users individually. The default
limit of 80 characters line length conflicts with the deeply nested structure of flutter's declarative code for designing

`dartfmt` lacks config file support, which implies that customizations need to be done by users individually. The default
limit of 80 characters line length conflicts with the deeply nested structure of flutter's declarative code for designing
widgets. This causes many unwanted linebreaks that reduce the readability of flutter code. Hence, we increase the line
length of the code to 120.

* Settings > Dart > Line length 120.
* Autoformat on save: Settings > Languages and Frameworks > then tick: `Format code on save`, `Organize imports on save`.
* Format the whole codebase with:
- Settings > Dart > Line length 120.
- Autoformat on save: Settings > Languages and Frameworks > then tick: `Format code on save`, `Organize imports on save`.
- Format the whole codebase with:

```shell
melos format-all
```

## Generate
* Re generate .g files run:

- Re generate .g files run:

```shell
melos run-build-runner-all
```
```

### Installing iOS Dependencies

```sh
./scripts/pod_install.sh
```
5 changes: 1 addition & 4 deletions app/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, '12.0'
platform :ios, '13.0'

# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
ENV['COCOAPODS_DISABLE_STATS'] = 'true'
Expand Down Expand Up @@ -32,9 +32,6 @@ target 'Runner' do
use_modular_headers!

flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__))
# target 'RunnerTests' do
# inherit! :search_paths
# end
end

post_install do |installer|
Expand Down
12 changes: 6 additions & 6 deletions app/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,10 @@ PODS:
- GTMAppAuth (4.1.1):
- AppAuth/Core (~> 1.7)
- GTMSessionFetcher/Core (< 4.0, >= 3.3)
- GTMSessionFetcher (3.5.0):
- GTMSessionFetcher/Full (= 3.5.0)
- GTMSessionFetcher/Core (3.5.0)
- GTMSessionFetcher/Full (3.5.0):
- GTMSessionFetcher (3.4.1):
- GTMSessionFetcher/Full (= 3.4.1)
- GTMSessionFetcher/Core (3.4.1)
- GTMSessionFetcher/Full (3.4.1):
- GTMSessionFetcher/Core
- just_audio (0.0.1):
- Flutter
Expand Down Expand Up @@ -309,7 +309,7 @@ SPEC CHECKSUMS:
GoogleSignIn: d4281ab6cf21542b1cfaff85c191f230b399d2db
GoogleUtilities: ea963c370a38a8069cc5f7ba4ca849a60b6d7d15
GTMAppAuth: f69bd07d68cd3b766125f7e072c45d7340dea0de
GTMSessionFetcher: 5aea5ba6bd522a239e236100971f10cb71b96ab6
GTMSessionFetcher: 8000756fc1c19d2e5697b90311f7832d2e33f6cd
just_audio: baa7252489dbcf47a4c7cc9ca663e9661c99aafa
nanopb: 438bc412db1928dac798aa6fd75726007be04262
package_info_plus: 58f0028419748fad15bf008b270aaa8e54380b1c
Expand All @@ -323,6 +323,6 @@ SPEC CHECKSUMS:
sqflite: 673a0e54cc04b7d6dba8d24fb8095b31c3a99eec
url_launcher_ios: 6116280ddcfe98ab8820085d8d76ae7449447586

PODFILE CHECKSUM: 0805b11bfb13bd44fc55fe52946ce14f22a2998e
PODFILE CHECKSUM: cc1f88378b4bfcf93a6ce00d2c587857c6008d3b

COCOAPODS: 1.15.2
4 changes: 4 additions & 0 deletions app/lib/app/data/repository/auth_repositoty_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ final class AuthRepositoryImpl implements AuthRepository {
await remoteDataSource.saveUserData(userEntity);
await localDataSource.saveUserData(userEntity);
} catch (e, s) {
MqCrashlytics.report(e, s);
log('setUserData error $e,\n$s');
}
}
Expand All @@ -49,6 +50,7 @@ final class AuthRepositoryImpl implements AuthRepository {
);
} catch (e, s) {
log('signWithGoogle: error: $e\n$s');
MqCrashlytics.report(e, s);
return Left(AuthenticationExc(message: e.toString()));
}
}
Expand All @@ -72,6 +74,7 @@ final class AuthRepositoryImpl implements AuthRepository {
),
);
} catch (e, s) {
MqCrashlytics.report(e, s);
log('signWithGoogle: error: $e\n$s');
return Left(AuthenticationExc(message: e.toString()));
}
Expand Down Expand Up @@ -109,6 +112,7 @@ final class AuthRepositoryImpl implements AuthRepository {
await remoteDataSource.logoutRemote();
await localDataSource.logoutLocal();
} catch (e, s) {
MqCrashlytics.report(e, s);
log('logout error: $e\n$s');
}
}
Expand Down
4 changes: 3 additions & 1 deletion app/lib/config/router/parse_parameters.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'dart:developer';

import 'package:meta/meta.dart';
import 'package:my_quran/core/core.dart';

@immutable
final class ParseParams {
Expand All @@ -12,7 +13,8 @@ final class ParseParams {
final p1 = args['pages'] ?? '[1]';
final pages = p1.substring(1, p1.length - 1).split(',').map(int.parse).toList();
return (pages, isHatim);
} catch (e) {
} catch (e, s) {
MqCrashlytics.report(e, s);
log(e.toString());
return ([1], false);
}
Expand Down
10 changes: 7 additions & 3 deletions app/lib/core/auth/soccial_auth.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/foundation.dart';
import 'package:google_sign_in/google_sign_in.dart';
import 'package:my_quran/core/core.dart';
import 'package:sign_in_with_apple/sign_in_with_apple.dart';

@immutable
Expand All @@ -20,7 +21,8 @@ class SoccialAuth {

final userCredential = await FirebaseAuth.instance.signInWithCredential(credential);
return userCredential;
} catch (error) {
} catch (e, s) {
MqCrashlytics.report(e, s);
rethrow;
}
}
Expand All @@ -39,7 +41,8 @@ class SoccialAuth {
);
final userCredential = await FirebaseAuth.instance.signInWithCredential(oauthCredential);
return userCredential;
} catch (e) {
} catch (e, s) {
MqCrashlytics.report(e, s);
rethrow;
}
}
Expand All @@ -48,7 +51,8 @@ class SoccialAuth {
try {
await FirebaseAuth.instance.signOut();
await _googleSignIn.signOut();
} catch (error) {
} catch (e, s) {
MqCrashlytics.report(e, s);
rethrow;
}
}
Expand Down
9 changes: 6 additions & 3 deletions app/lib/core/client/remote_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ class RemoteClient {
try {
final model = fromJson(jsonDecode(response.body) as Map<String, dynamic>);
return Right(model);
} catch (e) {
} catch (e, s) {
MqCrashlytics.report(e, s);
return Left(ConvertExc(message: '$e'));
}

Expand Down Expand Up @@ -65,7 +66,8 @@ class RemoteClient {
} else {
return const Left(NetworkExc());
}
} catch (e) {
} catch (e, s) {
MqCrashlytics.report(e, s);
log(e.toString());
return const Left(ServerExc(null));
}
Expand All @@ -90,7 +92,8 @@ class RemoteClient {
} else {
return const Left(NetworkExc());
}
} catch (e) {
} catch (e, s) {
MqCrashlytics.report(e, s);
log(e.toString());
return const Left(ServerExc(null));
}
Expand Down
1 change: 1 addition & 0 deletions app/lib/core/core.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export 'auth/soccial_auth.dart';
export 'client/network_client.dart';
export 'client/remote_client.dart';
export 'crashlytics/mq_crashlytics.dart';
export 'either/either.dart';
export 'exceptions/network_exception.dart';
export 'exceptions/server_exception.dart';
Expand Down
42 changes: 42 additions & 0 deletions app/lib/core/crashlytics/mq_crashlytics.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import 'package:firebase_crashlytics/firebase_crashlytics.dart';
import 'package:flutter/material.dart';

@immutable
final class MqCrashlytics {
const MqCrashlytics._();

static void report(
dynamic exception,
StackTrace? stack, {
dynamic reason,
Iterable<Object> information = const [],
bool? printDetails,
bool fatal = false,
}) {
crashlytics.recordError(
exception,
stack,
reason: reason,
information: information,
printDetails: printDetails,
fatal: fatal,
);
}

static void recordFlutterError(
FlutterErrorDetails flutterErrorDetails, {
bool fatal = false,
}) {
crashlytics.recordFlutterError(flutterErrorDetails, fatal: fatal);
}

static Future<void> setUserIdentifier(String identifier) {
return crashlytics.setUserIdentifier(identifier);
}

static Future<void> setCrashlyticsCollectionEnabled({required bool enabled}) {
return crashlytics.setCrashlyticsCollectionEnabled(enabled);
}

static FirebaseCrashlytics get crashlytics => FirebaseCrashlytics.instance;
}
5 changes: 5 additions & 0 deletions app/lib/core/launch/app_launch.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'dart:developer';

import 'package:flutter/material.dart';
import 'package:my_quran/core/core.dart';
import 'package:url_launcher/url_launcher.dart';

@immutable
Expand All @@ -18,6 +19,7 @@ final class AppLaunch {
ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text(snackBarText)));
}
} catch (e, s) {
MqCrashlytics.report(e, s);
log('launch Error: $e, \n launch StackTrace: $s');
}
}
Expand All @@ -36,6 +38,7 @@ final class AppLaunch {
ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text(snackBarText)));
}
} catch (e, s) {
MqCrashlytics.report(e, s);
log('launch Error: $e, \n launch StackTrace: $s');
}
}
Expand All @@ -54,6 +57,7 @@ final class AppLaunch {
ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text(snackBarText)));
}
} catch (e, s) {
MqCrashlytics.report(e, s);
log('launch Error: $e, \n launch StackTrace: $s');
}
}
Expand All @@ -69,6 +73,7 @@ final class AppLaunch {
ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text(snackBarText)));
}
} catch (e, s) {
MqCrashlytics.report(e, s);
log('launch Error: $e, \n launch StackTrace: $s');
}
}
Expand Down
9 changes: 4 additions & 5 deletions app/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import 'dart:developer';

import 'package:connectivity_plus/connectivity_plus.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:firebase_crashlytics/firebase_crashlytics.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
Expand All @@ -25,12 +24,12 @@ Future<void> main({AppConfig? appConfig}) async {
options: DefaultFirebaseOptions.currentPlatform,
);

FlutterError.onError = (errorDetails) {
FirebaseCrashlytics.instance.recordFlutterFatalError(errorDetails);
};
await MqCrashlytics.setCrashlyticsCollectionEnabled(enabled: kDebugMode);

FlutterError.onError = MqCrashlytics.recordFlutterError;

PlatformDispatcher.instance.onError = (error, stack) {
FirebaseCrashlytics.instance.recordError(error, stack, fatal: true);
MqCrashlytics.report(error, stack, fatal: true);
return true;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ class HatimRemoteDataSource {
);

return res.fold((l) => throw l, (r) => r);
} catch (e) {
} catch (e, s) {
MqCrashlytics.report(e, s);
throw Exception(e);
}
}
Expand Down
2 changes: 2 additions & 0 deletions app/lib/modules/hatim/presentation/bloc/hatim_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'dart:developer';
import 'package:equatable/equatable.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:meta/meta.dart';
import 'package:my_quran/core/core.dart';
import 'package:my_quran/modules/hatim/hatim.dart';

part 'hatim_event.dart';
Expand Down Expand Up @@ -57,6 +58,7 @@ class HatimBloc extends Bloc<HatimEvent, HatimState> {
emit(state.copyWith(userPagesState: const HatimUserPagesLoading()));
repo.sinkHatimUserPages();
} catch (e, s) {
MqCrashlytics.report(e, s);
log('_onGetHatimDashBoardEvent: $e\n$s');
emit(state.copyWith(dashBoardState: HatimDashBoardFailed(Exception(e))));
}
Expand Down
Loading

0 comments on commit 823dfd8

Please sign in to comment.