Purpose
- add new class
SmartNetworkAssetLoader
that able to fetch localization using online .json
files from provided url.
- add configurable cache from network assets using
Duration(..)
class
- add Failover system to local assets when there is a failure when fetching the online
.json
and no caches stored
- inspired by and resolved #30 , #29 , #17
Types of changes
What types of changes does your code introduce?
Put an x
in the boxes that apply
- [ ] Bugfix (non-breaking change which fixes an issue)
- [X] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
- [ ] Documentation Update (if none of the other choices apply)
How to Test
Just use this class in the assetLoader
attribute of EasyLocalization
and configure it as you want
SmartNetworkAssetLoader(
assetsPath: 'assets/translations',
localCacheDuration: Duration(days: 1),
localeUrl: (String localeName) => Constants.appLangUrl,
timeout: Duration(seconds: 30)
)
Environment
Please define your environment to test this, you can choose multiple options. Put an x in the boxes that apply
- [X] Production
- [X] Development
- [X] Testing
- [X] Android
- [X] iOS
Attach your `flutter doctor -v` inside code block:
[✓] Flutter (Channel stable, 2.5.3, on macOS 12.3.1 21E258 darwin-arm, locale en-ID)
• Flutter version 2.5.3 at /Users/ariefwijaya/fvm/versions/2.5.3
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision 18116933e7 (6 months ago), 2021-10-15 10:46:35 -0700
• Engine revision d3ea636dc5
• Dart version 2.14.4
[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0-rc2)
• Android SDK at /Users/ariefwijaya/Library/Android/sdk
• Platform android-31, build-tools 33.0.0-rc2
• Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 11.0.11+0-b60-7772763)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS
• Xcode at /Applications/Xcode.app/Contents/Developer
• Xcode 13.3.1, Build version 13E500a
• CocoaPods version 1.11.2
[✓] Chrome - develop for the web
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[✓] Android Studio (version 2021.1)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 11.0.11+0-b60-7772763)
[✓] IntelliJ IDEA Community Edition (version 2020.3.4)
• IntelliJ at /Applications/IntelliJ IDEA CE.app
• Flutter plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/6351-dart
[✓] VS Code (version 1.66.2)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.38.1
[✓] Connected device (1 available)
• Chrome (web) • chrome • web-javascript • Google Chrome 100.0.4896.127
• No issues found!
Expected Results
- able to fetch localization data from provided url, otherwise get data from
assetsPath
- When the data has been fetched, it can be use even in offline because caches system