Skip to content

Fix remote config post #60

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

Merged
merged 2 commits into from
Aug 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
19 changes: 17 additions & 2 deletions lib/app_configuration/bloc/app_configuration_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,26 @@ class AppConfigurationBloc
AppConfigurationUpdated event,
Emitter<AppConfigurationState> emit,
) async {
if (state.originalRemoteConfig == null) {
emit(
state.copyWith(
status: AppConfigurationStatus.failure,
exception: const UnknownException(
'Original remote config is not available.',
),
),
);
return;
}
emit(state.copyWith(status: AppConfigurationStatus.loading));
try {
final configToUpdate = event.remoteConfig.copyWith(
createdAt: state.originalRemoteConfig!.createdAt,
updatedAt: DateTime.now(),
);
Comment on lines +60 to +76

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

For improved null safety and code clarity, it's best to avoid the null assertion operator (!). You can assign state.originalRemoteConfig to a local variable. After the null check, the compiler will know the local variable is not null, making the code safer and easier to read.

    final originalConfig = state.originalRemoteConfig;
    if (originalConfig == null) {
      emit(
        state.copyWith(
          status: AppConfigurationStatus.failure,
          exception: const UnknownException(
            'Original remote config is not available.',
          ),
        ),
      );
      return;
    }
    emit(state.copyWith(status: AppConfigurationStatus.loading));
    try {
      final configToUpdate = event.remoteConfig.copyWith(
        createdAt: originalConfig.createdAt,
        updatedAt: DateTime.now(),
      );

final updatedConfig = await _remoteConfigRepository.update(
id: event.remoteConfig.id,
item: event.remoteConfig,
id: configToUpdate.id,
item: configToUpdate,
);
emit(
state.copyWith(
Expand Down
2 changes: 1 addition & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import 'package:flutter_news_app_web_dashboard_full_source_code/app/config/confi
import 'package:flutter_news_app_web_dashboard_full_source_code/bootstrap.dart';

// Define the current application environment (production/development/demo).
const AppEnvironment appEnvironment = AppEnvironment.demo;
const AppEnvironment appEnvironment = AppEnvironment.development;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Hardcoding the application environment can be risky, as it might be accidentally merged and deployed to production. A more robust approach is to use compile-time variables with String.fromEnvironment. This allows you to specify the environment during the build process (e.g., flutter build --dart-define=APP_ENVIRONMENT=production) and avoids having environment-specific changes in version control.

final AppEnvironment appEnvironment = AppEnvironment.values.firstWhere(
  (e) => e.name == const String.fromEnvironment('APP_ENVIRONMENT', defaultValue: 'demo'),
  orElse: () => AppEnvironment.demo,
);


@JS('removeSplashFromWeb')
external void removeSplashFromWeb();
Expand Down
6 changes: 3 additions & 3 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ packages:
description:
path: "."
ref: HEAD
resolved-ref: "7a1b54f8c0f94f6c04af3404c8110181e080b5c4"
resolved-ref: f648500814ec636a2930498756029d29b363194a
url: "https://github.com/flutter-news-app-full-source-code/core.git"
source: git
version: "0.0.0"
Expand Down Expand Up @@ -269,10 +269,10 @@ packages:
dependency: "direct main"
description:
name: go_router
sha256: c489908a54ce2131f1d1b7cc631af9c1a06fac5ca7c449e959192089f9489431
sha256: "8b1f37dfaf6e958c6b872322db06f946509433bec3de753c3491a42ae9ec2b48"
url: "https://pub.dev"
source: hosted
version: "16.0.0"
version: "16.1.0"
google_fonts:
dependency: "direct main"
description:
Expand Down
Loading