Skip to content

Commit d1300c8

Browse files
authored
Merge pull request #50 from headlines-toolkit/feature_custom_envirement_messages
Feature_custom_envirement_messages
2 parents a684f63 + c12d944 commit d1300c8

File tree

11 files changed

+108
-25
lines changed

11 files changed

+108
-25
lines changed

lib/app/bloc/app_bloc.dart

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import 'package:flex_color_scheme/flex_color_scheme.dart';
66
import 'package:flutter/material.dart';
77
import 'package:ht_auth_repository/ht_auth_repository.dart';
88
import 'package:ht_data_repository/ht_data_repository.dart';
9+
import 'package:ht_main/app/config/config.dart' as local_config;
910
import 'package:ht_shared/ht_shared.dart'; // Import shared models and exceptions
1011

1112
part 'app_event.dart';
@@ -15,24 +16,23 @@ class AppBloc extends Bloc<AppEvent, AppState> {
1516
AppBloc({
1617
required HtAuthRepository authenticationRepository,
1718
required HtDataRepository<UserAppSettings> userAppSettingsRepository,
18-
required HtDataRepository<AppConfig> appConfigRepository, // Added
19-
}) : _authenticationRepository = authenticationRepository,
20-
_userAppSettingsRepository = userAppSettingsRepository,
21-
_appConfigRepository = appConfigRepository, // Added
22-
// Initialize with default state, load settings after user is known
23-
// Provide a default UserAppSettings instance
24-
super(
25-
// AppConfig will be null initially, fetched later
26-
const AppState(
27-
settings: UserAppSettings(id: 'default'),
28-
selectedBottomNavigationIndex: 0,
29-
appConfig: null,
30-
),
31-
) {
19+
required HtDataRepository<AppConfig> appConfigRepository,
20+
required local_config.AppEnvironment environment, // Added
21+
}) : _authenticationRepository = authenticationRepository,
22+
_userAppSettingsRepository = userAppSettingsRepository,
23+
_appConfigRepository = appConfigRepository,
24+
super(
25+
AppState(
26+
settings: const UserAppSettings(id: 'default'),
27+
selectedBottomNavigationIndex: 0,
28+
appConfig: null,
29+
environment: environment, // Pass environment to AppState
30+
),
31+
) {
3232
on<AppUserChanged>(_onAppUserChanged);
3333
on<AppSettingsRefreshed>(_onAppSettingsRefreshed);
3434
on<AppConfigFetchRequested>(_onAppConfigFetchRequested);
35-
on<AppUserAccountActionShown>(_onAppUserAccountActionShown); // Added
35+
on<AppUserAccountActionShown>(_onAppUserAccountActionShown);
3636
on<AppLogoutRequested>(_onLogoutRequested);
3737
on<AppThemeModeChanged>(_onThemeModeChanged);
3838
on<AppFlexSchemeChanged>(_onFlexSchemeChanged);

lib/app/bloc/app_state.dart

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ class AppState extends Equatable {
3434
this.status = AppStatus.initial,
3535
this.user, // User is now nullable and defaults to null
3636
this.locale, // Added locale
37-
this.appConfig, // Added AppConfig
37+
this.appConfig,
38+
this.environment,
3839
});
3940

4041
/// The index of the currently selected item in the bottom navigation bar.
@@ -66,7 +67,10 @@ class AppState extends Equatable {
6667
final Locale? locale; // Added locale
6768

6869
/// The global application configuration (remote config).
69-
final AppConfig? appConfig; // Added AppConfig
70+
final AppConfig? appConfig;
71+
72+
/// The current application environment (e.g., production, development, demo).
73+
final local_config.AppEnvironment? environment;
7074

7175
/// Creates a copy of the current state with updated values.
7276
AppState copyWith({
@@ -79,10 +83,12 @@ class AppState extends Equatable {
7983
User? user,
8084
UserAppSettings? settings, // Add settings to copyWith
8185
Locale? locale, // Added locale
82-
AppConfig? appConfig, // Added AppConfig
86+
AppConfig? appConfig,
87+
local_config.AppEnvironment? environment, // Added AppEnvironment
8388
bool clearFontFamily = false,
8489
bool clearLocale = false, // Added to allow clearing locale
8590
bool clearAppConfig = false, // Added to allow clearing appConfig
91+
bool clearEnvironment = false, // Added to allow clearing environment
8692
}) {
8793
return AppState(
8894
selectedBottomNavigationIndex:
@@ -95,7 +101,9 @@ class AppState extends Equatable {
95101
user: user ?? this.user,
96102
settings: settings ?? this.settings, // Copy settings
97103
locale: clearLocale ? null : locale ?? this.locale, // Added locale
98-
appConfig: clearAppConfig ? null : appConfig ?? this.appConfig, // Added
104+
appConfig: clearAppConfig ? null : appConfig ?? this.appConfig,
105+
environment:
106+
clearEnvironment ? null : environment ?? this.environment, // Added
99107
);
100108
}
101109

@@ -110,6 +118,7 @@ class AppState extends Equatable {
110118
user,
111119
settings, // Include settings in props
112120
locale, // Added locale to props
113-
appConfig, // Added AppConfig to props
121+
appConfig,
122+
environment,
114123
];
115124
}

lib/app/view/app.dart

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import 'package:ht_auth_repository/ht_auth_repository.dart'; // Auth Repository
99
import 'package:ht_data_repository/ht_data_repository.dart'; // Generic Data Repository
1010
import 'package:ht_kv_storage_service/ht_kv_storage_service.dart'; // KV Storage Interface
1111
import 'package:ht_main/app/bloc/app_bloc.dart';
12+
import 'package:ht_main/app/config/app_environment.dart';
1213
import 'package:ht_main/authentication/bloc/authentication_bloc.dart';
1314
import 'package:ht_main/l10n/app_localizations.dart';
1415
import 'package:ht_main/l10n/l10n.dart';
@@ -30,6 +31,7 @@ class App extends StatelessWidget {
3031
htUserContentPreferencesRepository,
3132
required HtDataRepository<AppConfig> htAppConfigRepository,
3233
required HtKVStorageService kvStorageService,
34+
required AppEnvironment environment, // Added
3335
super.key,
3436
}) : _htAuthenticationRepository = htAuthenticationRepository,
3537
_htHeadlinesRepository = htHeadlinesRepository,
@@ -39,7 +41,8 @@ class App extends StatelessWidget {
3941
_htUserAppSettingsRepository = htUserAppSettingsRepository,
4042
_htUserContentPreferencesRepository = htUserContentPreferencesRepository,
4143
_htAppConfigRepository = htAppConfigRepository,
42-
_kvStorageService = kvStorageService;
44+
_kvStorageService = kvStorageService,
45+
_environment = environment; // Added
4346

4447
final HtAuthRepository _htAuthenticationRepository;
4548
final HtDataRepository<Headline> _htHeadlinesRepository;
@@ -51,6 +54,7 @@ class App extends StatelessWidget {
5154
_htUserContentPreferencesRepository;
5255
final HtDataRepository<AppConfig> _htAppConfigRepository;
5356
final HtKVStorageService _kvStorageService;
57+
final AppEnvironment _environment; // Added
5458

5559
@override
5660
Widget build(BuildContext context) {
@@ -76,8 +80,9 @@ class App extends StatelessWidget {
7680
authenticationRepository: context.read<HtAuthRepository>(),
7781
userAppSettingsRepository:
7882
context.read<HtDataRepository<UserAppSettings>>(),
79-
appConfigRepository: // Added
80-
context.read<HtDataRepository<AppConfig>>(), // Added
83+
appConfigRepository:
84+
context.read<HtDataRepository<AppConfig>>(),
85+
environment: _environment, // Pass environment
8186
),
8287
),
8388
BlocProvider(
@@ -97,6 +102,7 @@ class App extends StatelessWidget {
97102
htUserContentPreferencesRepository:
98103
_htUserContentPreferencesRepository,
99104
htAppConfigRepository: _htAppConfigRepository,
105+
environment: _environment, // Pass environment
100106
),
101107
),
102108
);
@@ -113,6 +119,7 @@ class _AppView extends StatefulWidget {
113119
required this.htUserAppSettingsRepository,
114120
required this.htUserContentPreferencesRepository,
115121
required this.htAppConfigRepository,
122+
required this.environment, // Added
116123
});
117124

118125
final HtAuthRepository htAuthenticationRepository;
@@ -124,6 +131,7 @@ class _AppView extends StatefulWidget {
124131
final HtDataRepository<UserContentPreferences>
125132
htUserContentPreferencesRepository;
126133
final HtDataRepository<AppConfig> htAppConfigRepository;
134+
final AppEnvironment environment; // Added
127135

128136
@override
129137
State<_AppView> createState() => _AppViewState();

lib/authentication/view/email_code_verification_page.dart

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import 'package:flutter/material.dart';
22
import 'package:flutter/services.dart';
33
import 'package:flutter_bloc/flutter_bloc.dart';
4+
import 'package:ht_main/app/bloc/app_bloc.dart'; // Added
5+
import 'package:ht_main/app/config/config.dart'; // Added for AppEnvironment
46
import 'package:ht_main/authentication/bloc/authentication_bloc.dart';
57
import 'package:ht_main/l10n/l10n.dart';
68
import 'package:ht_main/shared/constants/app_spacing.dart';
@@ -72,6 +74,30 @@ class EmailCodeVerificationPage extends StatelessWidget {
7274
), // Softer color
7375
textAlign: TextAlign.center,
7476
),
77+
// Display demo code if in demo environment
78+
BlocSelector<AppBloc, AppState, AppEnvironment?>(
79+
selector: (state) => state.environment,
80+
builder: (context, environment) {
81+
if (environment == AppEnvironment.demo) {
82+
return Column(
83+
children: [
84+
const SizedBox(height: AppSpacing.md),
85+
Text(
86+
l10n.demoVerificationCodeMessage(
87+
'123456',
88+
), // Demo code
89+
style: textTheme.bodyMedium?.copyWith(
90+
color: colorScheme.secondary,
91+
fontWeight: FontWeight.bold,
92+
),
93+
textAlign: TextAlign.center,
94+
),
95+
],
96+
);
97+
}
98+
return const SizedBox.shrink();
99+
},
100+
),
75101
const SizedBox(
76102
height: AppSpacing.xl,
77103
), // Increased spacing

lib/bootstrap.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ import 'package:ht_main/shared/localization/en_timeago_messages.dart';
1919
import 'package:ht_shared/ht_shared.dart';
2020
import 'package:timeago/timeago.dart' as timeago;
2121

22-
Future<Widget> bootstrap(app_config.AppConfig appConfig) async {
22+
Future<Widget> bootstrap(
23+
app_config.AppConfig appConfig,
24+
app_config.AppEnvironment environment, // Added
25+
) async {
2326
WidgetsFlutterBinding.ensureInitialized();
2427
Bloc.observer = const AppBlocObserver();
2528

@@ -215,5 +218,6 @@ Future<Widget> bootstrap(app_config.AppConfig appConfig) async {
215218
htUserContentPreferencesRepository: userContentPreferencesRepository,
216219
htAppConfigRepository: appConfigRepository,
217220
kvStorageService: kvStorage,
221+
environment: environment, // Pass environment to App
218222
);
219223
}

lib/l10n/app_localizations.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1381,6 +1381,12 @@ abstract class AppLocalizations {
13811381
/// In en, this message translates to:
13821382
/// **'Start following categories to see them here.'**
13831383
String get followedCategoriesEmptySubheadline;
1384+
1385+
/// Message shown in demo mode to provide the verification code
1386+
///
1387+
/// In en, this message translates to:
1388+
/// **'Demo Mode: Use code {code}'**
1389+
String demoVerificationCodeMessage(String code);
13841390
}
13851391

13861392
class _AppLocalizationsDelegate

lib/l10n/app_localizations_ar.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -705,4 +705,9 @@ class AppLocalizationsAr extends AppLocalizations {
705705
@override
706706
String get followedCategoriesEmptySubheadline =>
707707
'Start following categories to see them here.';
708+
709+
@override
710+
String demoVerificationCodeMessage(String code) {
711+
return 'وضع العرض التوضيحي: استخدم الرمز $code';
712+
}
708713
}

lib/l10n/app_localizations_en.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -707,4 +707,9 @@ class AppLocalizationsEn extends AppLocalizations {
707707
@override
708708
String get followedCategoriesEmptySubheadline =>
709709
'Start following categories to see them here.';
710+
711+
@override
712+
String demoVerificationCodeMessage(String code) {
713+
return 'Demo Mode: Use code $code';
714+
}
710715
}

lib/l10n/arb/app_ar.arb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -895,5 +895,15 @@
895895
"savedHeadlinesEmptySubheadline": "لم تقم بحفظ أي مقالات بعد. ابدأ الاستكشاف!",
896896
"@savedHeadlinesEmptySubheadline": {
897897
"description": "Subheadline for empty state on saved headlines page"
898+
},
899+
"demoVerificationCodeMessage": "وضع العرض التوضيحي: استخدم الرمز {code}",
900+
"@demoVerificationCodeMessage": {
901+
"description": "رسالة تظهر في وضع العرض التوضيحي لتوفير رمز التحقق",
902+
"placeholders": {
903+
"code": {
904+
"type": "String",
905+
"example": "123456"
906+
}
907+
}
898908
}
899909
}

lib/l10n/arb/app_en.arb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -911,5 +911,15 @@
911911
"followedCategoriesEmptySubheadline": "Start following categories to see them here.",
912912
"@followedCategoriesEmptySubheadline": {
913913
"description": "Subheadline for empty state on followed categories page"
914+
},
915+
"demoVerificationCodeMessage": "Demo Mode: Use code {code}",
916+
"@demoVerificationCodeMessage": {
917+
"description": "Message shown in demo mode to provide the verification code",
918+
"placeholders": {
919+
"code": {
920+
"type": "String",
921+
"example": "123456"
922+
}
923+
}
914924
}
915925
}

0 commit comments

Comments
 (0)