Skip to content

Commit

Permalink
fix: make fallbackfile nullable
Browse files Browse the repository at this point in the history
  • Loading branch information
ilteoood committed Jul 10, 2024
1 parent 1d391d5 commit 0cc58e9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions example/lib/network_example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import 'package:flutter_i18n/loaders/decoders/json_decode_strategy.dart';
import 'package:flutter_localizations/flutter_localizations.dart';

class CustomNetworkFileTranslationLoader extends NetworkFileTranslationLoader {
CustomNetworkFileTranslationLoader({required baseUri})
CustomNetworkFileTranslationLoader(Uri baseUri)
: super(baseUri: baseUri, decodeStrategies: [JsonDecodeStrategy()]);

@override
Expand All @@ -19,7 +19,7 @@ Future main() async {
WidgetsFlutterBinding.ensureInitialized();
final FlutterI18nDelegate flutterI18nDelegate = FlutterI18nDelegate(
translationLoader: CustomNetworkFileTranslationLoader(
baseUri: Uri.https("postman-echo.com", "get",
Uri.https("postman-echo.com", "get",
{"title": "Basic network example", "content": "Translated content"}),
),
);
Expand Down
6 changes: 3 additions & 3 deletions lib/loaders/file_translation_loader.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import '../utils/message_printer.dart';

/// Loads translation files from JSON, YAML or XML format
class FileTranslationLoader extends TranslationLoader implements IFileContent {
final String fallbackFile;
final String? fallbackFile;
final String basePath;
final String separator;
final bool useCountryCode;
Expand Down Expand Up @@ -51,8 +51,8 @@ class FileTranslationLoader extends TranslationLoader implements IFileContent {
final fileName = composeFileName();
await this._defineLocale();
_decodedMap.addAll(await _loadTranslation(fileName, false));
if (fileName != fallbackFile) {
final Map fallbackMap = await _loadTranslation(fallbackFile, true);
if (fallbackFile != null && fileName != fallbackFile) {
final Map fallbackMap = await _loadTranslation(fallbackFile!, true);
_decodedMap = _deepMergeMaps(fallbackMap, _decodedMap);
MessagePrinter.debug('Fallback maps have been merged');
}
Expand Down

0 comments on commit 0cc58e9

Please sign in to comment.