-
Notifications
You must be signed in to change notification settings - Fork 82
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
HttpAssetLoader() #29
Comments
Maybe this can help. The files will have to be put similar to the way RootBundleLoader expects. Here JSON is used, you could change it to use YAML. Let's say one of you support two languages, then you can do something like this. runApp(
ProviderScope(
child: EasyLocalization(
supportedLocales: const [
Locale('en', 'US'),
Locale('en', 'CA'),
],
path: 'http://localhost:8000/', // Base path is given, file expected to be at 'http://localhost:8000/en-US.json'
fallbackLocale: const Locale('en', 'US'),
assetLoader: NetworkAssetLoader(),
child: const App(),
),
),
); import 'dart:convert';
import 'dart:developer';
import 'dart:ui';
import 'package:easy_localization/easy_localization.dart';
import 'package:http/http.dart' as http;
class NetworkAssetLoader extends AssetLoader {
@override
Future<Map<String, dynamic>> load(String path, Locale locale) async {
log('easy localization loader: load http $path');
print('Loading ${locale.toLanguageTag()}');
try {
var url = Uri.parse(
'$path${locale.toLanguageTag()}.json',
);
return http
.get(url)
.then((response) => json.decode(response.body.toString()));
} catch (e) {
// Catch network exceptions
return Future.value({});
}
}
} |
Hello there. Could anyone describe it more? Does it affect launch screen time? What happened if fetch request would failed? Would it fallbacked to local file or what? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I am having 3 Yaml files to load over Http
How the HttpAssetLoader() is working? What files does it expect?
The text was updated successfully, but these errors were encountered: