diff --git a/example/lib/network_example.dart b/example/lib/network_example.dart index 74037b0..68f4cb9 100644 --- a/example/lib/network_example.dart +++ b/example/lib/network_example.dart @@ -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 @@ -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"}), ), ); diff --git a/lib/loaders/file_translation_loader.dart b/lib/loaders/file_translation_loader.dart index e267b81..ea44ef9 100644 --- a/lib/loaders/file_translation_loader.dart +++ b/lib/loaders/file_translation_loader.dart @@ -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; @@ -34,7 +34,7 @@ class FileTranslationLoader extends TranslationLoader implements IFileContent { ]; FileTranslationLoader( - {this.fallbackFile = "en", + {this.fallbackFile = null, this.basePath = "assets/flutter_i18n", this.separator = "_", this.useCountryCode = false, @@ -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'); }