This is a demo app that demonstrates language and theme support using the easy_localisation
package along with a custom language loader to load languages from a URL. It also includes a feature to load ThemeData
from a server and switch between different themes.
-
Clone the repository:
git clone [email protected]:antiv/demo_localization.git
-
Navigate to the project directory:
cd demo-localization
-
Install the dependencies using
pub
(Dart package manager):pub get
-
Launch the app:
flutter run
-
The app will start with the default language (usually English) and theme loaded from the local configuration files.
The demo app uses a custom language loader to fetch language JSON files from a URL at runtime. This allows you to dynamically load translations without rebuilding the app.
The custom language loader implementation can be found in the lib/im_loader.dart
file. It fetches the language JSON files asynchronously and initializes the translations using the easy_localisation
package.
If response status is not 200, it will load the default language from the assets folder.
The demo app includes a custom theme loader that fetches data from a server and use json_theme
lib to convert it in ThemeData
object. It fetches the theme data asynchronously and applies it to the app's UI dynamically.
The custom theme loader implementation can be found in the lib/theme/theme_service.dart
file. It fetches the theme data from the specified URL and applies it using the provider
package.
In general, you can use any state management solution to apply the theme data to the app's UI.
The main files and folders relevant to the language and theme support functionality in this demo app are:
lib/main.dart
: Contains the app's entry point and configuration foreasy_localisation
andThemeServicer
.lib/lit_loader.dart
: Implements the custom language loader for fetching language JSON files from a URL.lib/theme/theme_service.dart
: Implements the custom theme loader for fetching data from a server and convert it toThemeData
usingjson_theme
lib.
Contributions are welcome! If you find any issues or have suggestions for improvement, please open an issue or submit a pull request on the repository.
This demo app is licensed under the MIT License.