Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Mobile App] Code Cleanup & Enhancements #1037

Merged
merged 22 commits into from
Feb 16, 2025
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions recipients_app/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ translations after you changed something run:
flutter gen-l10n
```

To use a translated string in the code use:
`AppLocalizations.of(context).helloWorld` and import:
To use a translated string in the code use: `context.l10n.helloWorld`
and import:
`import 'package:flutter_gen/gen_l10n/app_localizations.dart';`

### Upgrade flutter version
Expand Down
3 changes: 2 additions & 1 deletion recipients_app/l10n.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
arb-dir: lib/l10n
arb-dir: lib/l10n/arb
template-arb-file: app_en.arb
output-localization-file: app_localizations.dart
untranslated-messages-file: untranslated_messages.txt
nullable-getter: false
86 changes: 78 additions & 8 deletions recipients_app/lib/data/models/payment/payment_ui_status.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,80 @@
import "package:app/ui/configs/app_colors.dart";
import "package:flutter/material.dart";

enum PaymentUiStatus {
confirmed,
contested,
toReview,
recentToReview,
onHoldContested,
onHoldToReview,
toBePaid,
empty,
/// blue label, white font, confirm icon
confirmed(
color: AppColors.primaryColor,
icon: Icons.check_rounded,
textColor: Colors.white,
iconColor: Colors.white,
),

/// yellow label, dark font, warning icon
contested(
color: AppColors.yellowColor,
icon: Icons.priority_high_rounded,
textColor: AppColors.fontColorDark,
iconColor: AppColors.fontColorDark,
),

/// yellow label, dark font, warning icon
toReview(
color: AppColors.yellowColor,
icon: Icons.priority_high_rounded,
textColor: AppColors.fontColorDark,
iconColor: AppColors.fontColorDark,
),

/// blue label, white font, question mark icon
recentToReview(
color: AppColors.primaryColor,
icon: Icons.question_mark_rounded,
textColor: Colors.white,
iconColor: Colors.white,
),

/// red label, dark font, close icon
onHoldContested(
color: AppColors.redColor,
icon: Icons.close_rounded,
textColor: AppColors.fontColorDark,
iconColor: AppColors.fontColorDark,
),

/// red label, dark font, close icon
onHoldToReview(
color: AppColors.redColor,
icon: Icons.close_rounded,
textColor: AppColors.fontColorDark,
iconColor: AppColors.fontColorDark,
),

/// backgroundColor label, dark font, no visbible icon (That's why iconColor is same as color)
toBePaid(
color: AppColors.backgroundColor,
icon: Icons.timer_outlined,
textColor: AppColors.fontColorDark,
iconColor: AppColors.backgroundColor,
),

/// backgroundColor label, dark font, no visbible icon (That's why iconColor is same as color)
empty(
color: AppColors.backgroundColor,
icon: Icons.question_mark_rounded,
textColor: AppColors.fontColorDark,
iconColor: AppColors.backgroundColor,
);

final Color color;
final IconData icon;
final Color textColor;
final Color iconColor;

const PaymentUiStatus({
required this.color,
required this.icon,
required this.textColor,
required this.iconColor,
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import "dart:developer";
import "package:sentry_flutter/sentry_flutter.dart";

class CrashReportingRepository {
CrashReportingRepository();
const CrashReportingRepository();

Future<void> logError(Exception exception, StackTrace stackTrace) async {
log("--- SENTRY: Logging error: $exception");
Expand All @@ -12,7 +12,6 @@ class CrashReportingRepository {

Future<void> logInfo(String message) async {
log("--- SENTRY: Logging info: $message");

Sentry.captureMessage(message);
}
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
import "package:app/data/datasource/demo/organization_demo_data_source.dart";
import "package:app/data/datasource/organization_data_source.dart";
import "package:app/data/datasource/remote/organization_remote_data_source.dart";
import "package:app/data/models/organization.dart";
import "package:app/demo_manager.dart";
import "package:cloud_firestore/cloud_firestore.dart";

class OrganizationRepository {
late OrganizationDataSource remoteDataSource = OrganizationRemoteDataSource(firestore: firestore);
late OrganizationDataSource demoDataSource = OrganizationDemoDataSource();
final OrganizationDataSource remoteDataSource;
final OrganizationDataSource demoDataSource;

final DemoManager demoManager;
final FirebaseFirestore firestore;

OrganizationRepository({
required this.firestore,
const OrganizationRepository({
required this.demoManager,
required this.remoteDataSource,
required this.demoDataSource,
});

OrganizationDataSource get _activeDataSource => demoManager.isDemoEnabled ? demoDataSource : remoteDataSource;
Expand Down
13 changes: 5 additions & 8 deletions recipients_app/lib/data/repositories/payment_repository.dart
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
import "package:app/data/datasource/demo/payment_demo_data_source.dart";
import "package:app/data/datasource/payment_data_source.dart";
import "package:app/data/datasource/remote/payment_remote_data_source.dart";
import "package:app/data/models/models.dart";
import "package:app/demo_manager.dart";
import "package:cloud_firestore/cloud_firestore.dart";

class PaymentRepository {
late PaymentDataSource remoteDataSource = PaymentRemoteDataSource(firestore: firestore);
late PaymentDataSource demoDataSource = PaymentDemoDataSource();
final PaymentDataSource remoteDataSource;
final PaymentDataSource demoDataSource;

final DemoManager demoManager;
final FirebaseFirestore firestore;

PaymentRepository({
required this.firestore,
const PaymentRepository({
required this.remoteDataSource,
required this.demoDataSource,
required this.demoManager,
});

Expand Down
15 changes: 6 additions & 9 deletions recipients_app/lib/data/repositories/survey_repository.dart
Original file line number Diff line number Diff line change
@@ -1,24 +1,21 @@
import "package:app/data/datasource/demo/survey_demo_data_source.dart";
import "package:app/data/datasource/remote/survey_remote_data_source.dart";
import "package:app/data/datasource/survey_data_source.dart";
import "package:app/data/models/models.dart";
import "package:app/data/models/survey/survey.dart";
import "package:app/demo_manager.dart";
import "package:cloud_firestore/cloud_firestore.dart";

class SurveyRepository {
late SurveyDataSource remoteDataSource = SurveyRemoteDataSource(firestore: firestore);
late SurveyDataSource demoDataSource = SurveyDemoDataSource();
final SurveyDataSource remoteDataSource;
final SurveyDataSource demoDataSource;

final DemoManager demoManager;
final FirebaseFirestore firestore;

SurveyRepository({
required this.firestore,
const SurveyRepository({
required this.remoteDataSource,
required this.demoDataSource,
required this.demoManager,
});

SurveyDataSource get _activeDataSource => demoManager.isDemoEnabled ? demoDataSource : remoteDataSource;
SurveyDataSource get _activeDataSource => demoManager.isDemoEnabled ? demoDataSource : remoteDataSource;

Future<List<Survey>> fetchSurveys({
required String recipientId,
Expand Down
15 changes: 5 additions & 10 deletions recipients_app/lib/data/repositories/user_repository.dart
Original file line number Diff line number Diff line change
@@ -1,24 +1,19 @@
import "dart:async";

import "package:app/data/datasource/demo/user_demo_data_source.dart";
import "package:app/data/datasource/remote/user_remote_data_source.dart";
import "package:app/data/datasource/user_data_source.dart";
import "package:app/data/models/models.dart";
import "package:app/demo_manager.dart";
import "package:cloud_firestore/cloud_firestore.dart";
import "package:firebase_auth/firebase_auth.dart";

class UserRepository {
late UserDataSource remoteDataSource = UserRemoteDataSource(firestore: firestore, firebaseAuth: firebaseAuth);
late UserDataSource demoDataSource = UserDemoDataSource();
final UserDataSource remoteDataSource;
final UserDataSource demoDataSource;

final DemoManager demoManager;
final FirebaseFirestore firestore;
final FirebaseAuth firebaseAuth;

UserRepository({
required this.firestore,
required this.firebaseAuth,
const UserRepository({
required this.remoteDataSource,
required this.demoDataSource,
required this.demoManager,
});

Expand Down
8 changes: 8 additions & 0 deletions recipients_app/lib/l10n/l10n.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import "package:flutter/widgets.dart";
import "package:flutter_gen/gen_l10n/app_localizations.dart";

export "package:flutter_gen/gen_l10n/app_localizations.dart";

extension AppLocalizationsX on BuildContext {
AppLocalizations get l10n => AppLocalizations.of(this);
}
30 changes: 28 additions & 2 deletions recipients_app/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
import "package:app/core/helpers/custom_bloc_observer.dart";
import "package:app/data/datasource/demo/organization_demo_data_source.dart";
import "package:app/data/datasource/demo/payment_demo_data_source.dart";
import "package:app/data/datasource/demo/survey_demo_data_source.dart";
import "package:app/data/datasource/demo/user_demo_data_source.dart";
import "package:app/data/datasource/remote/organization_remote_data_source.dart";
import "package:app/data/datasource/remote/payment_remote_data_source.dart";
import "package:app/data/datasource/remote/survey_remote_data_source.dart";
import "package:app/data/datasource/remote/user_remote_data_source.dart";
import "package:app/demo_manager.dart";
import "package:app/my_app.dart";
import "package:cloud_firestore/cloud_firestore.dart";
Expand Down Expand Up @@ -34,6 +42,18 @@ Future<void> main() async {
final messaging = FirebaseMessaging.instance;
final demoManager = DemoManager();

final userRemoteDataSource = UserRemoteDataSource(firestore: firestore, firebaseAuth: firebaseAuth);
final userDemoDataSource = UserDemoDataSource();

final paymentRemoteDataSource = PaymentRemoteDataSource(firestore: firestore);
final paymentDemoDataSource = PaymentDemoDataSource();

final surveyRemoteDataSource = SurveyRemoteDataSource(firestore: firestore);
final surveyDemoDataSource = SurveyDemoDataSource();

final organizationRemoteDataSource = OrganizationRemoteDataSource(firestore: firestore);
final organizationDemoDataSource = OrganizationDemoDataSource();

if (appFlavor == "dev") {
firestore.useFirestoreEmulator("localhost", 8080);
firebaseAuth.useAuthEmulator("localhost", 9099);
Expand All @@ -51,10 +71,16 @@ Future<void> main() async {
},
appRunner: () => runApp(
MyApp(
firebaseAuth: firebaseAuth,
firestore: firestore,
messaging: messaging,
demoManager: demoManager,
userRemoteDataSource: userRemoteDataSource,
userDemoDataSource: userDemoDataSource,
paymentRemoteDataSource: paymentRemoteDataSource,
paymentDemoDataSource: paymentDemoDataSource,
surveyRemoteDataSource: surveyRemoteDataSource,
surveyDemoDataSource: surveyDemoDataSource,
organizationRemoteDataSource: organizationRemoteDataSource,
organizationDemoDataSource: organizationDemoDataSource,
),
),
);
Expand Down
49 changes: 37 additions & 12 deletions recipients_app/lib/my_app.dart
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
import "package:app/core/cubits/auth/auth_cubit.dart";
import "package:app/core/cubits/settings/settings_cubit.dart";
import "package:app/data/datasource/demo/organization_demo_data_source.dart";
import "package:app/data/datasource/demo/payment_demo_data_source.dart";
import "package:app/data/datasource/demo/survey_demo_data_source.dart";
import "package:app/data/datasource/demo/user_demo_data_source.dart";
import "package:app/data/datasource/remote/organization_remote_data_source.dart";
import "package:app/data/datasource/remote/payment_remote_data_source.dart";
import "package:app/data/datasource/remote/survey_remote_data_source.dart";
import "package:app/data/datasource/remote/user_remote_data_source.dart";
import "package:app/data/repositories/repositories.dart";
import "package:app/demo_manager.dart";
import "package:app/kri_intl.dart";
import "package:app/ui/configs/configs.dart";
import "package:app/view/pages/main_app_page.dart";
import "package:app/view/pages/terms_and_conditions_page.dart";
import "package:app/view/pages/welcome_page.dart";
import "package:cloud_firestore/cloud_firestore.dart";
import "package:firebase_auth/firebase_auth.dart";
import "package:firebase_messaging/firebase_messaging.dart";
import "package:flutter/material.dart";
import "package:flutter_bloc/flutter_bloc.dart";
Expand All @@ -17,17 +23,33 @@ import "package:flutter_localizations/flutter_localizations.dart";
import "package:flutter_native_splash/flutter_native_splash.dart";

class MyApp extends StatelessWidget {
final FirebaseAuth firebaseAuth;
final FirebaseFirestore firestore;
final FirebaseMessaging messaging;
final DemoManager demoManager;

final UserRemoteDataSource userRemoteDataSource;
final UserDemoDataSource userDemoDataSource;

final PaymentRemoteDataSource paymentRemoteDataSource;
final PaymentDemoDataSource paymentDemoDataSource;

final SurveyRemoteDataSource surveyRemoteDataSource;
final SurveyDemoDataSource surveyDemoDataSource;

final OrganizationRemoteDataSource organizationRemoteDataSource;
final OrganizationDemoDataSource organizationDemoDataSource;

const MyApp({
super.key,
required this.firebaseAuth,
required this.firestore,
required this.messaging,
required this.demoManager,
required this.userRemoteDataSource,
required this.userDemoDataSource,
required this.paymentRemoteDataSource,
required this.paymentDemoDataSource,
required this.surveyRemoteDataSource,
required this.surveyDemoDataSource,
required this.organizationRemoteDataSource,
required this.organizationDemoDataSource,
});

// This widget is the root of your application.
Expand All @@ -45,29 +67,32 @@ class MyApp extends StatelessWidget {
),
RepositoryProvider(
create: (context) => UserRepository(
firebaseAuth: firebaseAuth,
firestore: firestore,
remoteDataSource: userRemoteDataSource,
demoDataSource: userDemoDataSource,
demoManager: demoManager,
),
),
RepositoryProvider(
create: (context) => CrashReportingRepository(),
create: (context) => const CrashReportingRepository(),
),
RepositoryProvider(
create: (context) => PaymentRepository(
firestore: firestore,
remoteDataSource: paymentRemoteDataSource,
demoDataSource: paymentDemoDataSource,
demoManager: demoManager,
),
),
RepositoryProvider(
create: (context) => SurveyRepository(
firestore: firestore,
remoteDataSource: surveyRemoteDataSource,
demoDataSource: surveyDemoDataSource,
demoManager: demoManager,
),
),
RepositoryProvider(
create: (context) => OrganizationRepository(
firestore: firestore,
remoteDataSource: organizationRemoteDataSource,
demoDataSource: organizationDemoDataSource,
demoManager: demoManager,
),
),
Expand Down
Loading
Loading