localizely_sdk 1.2.0
localizely_sdk: ^1.2.0 copied to clipboard
Localizely SDK for Flutter enables Over-the-air translations update from Localizely cloud platform
Localizely SDK #
SDK setup #
- Update
pubspec.yaml
file:
dependencies: ... localizely_sdk: ^1.2.0 flutter_intl: ... localizely: ota_enabled: true # Required for Over-the-air translation updates
-
Trigger localization files generation by Flutter Intl IDE plugin or by intl_utils library
-
Initialize Localizely SDK (e.g.
main.dart
file):
import 'package:flutter/material.dart'; import 'package:flutter_localizations/flutter_localizations.dart'; import 'package:localizely_sdk/localizely_sdk.dart'; // Import sdk package import 'generated/l10n.dart'; void main() { Localizely.init('<SDK_TOKEN>', '<DISTRIBUTION_ID>'); // Init sdk Localizely.setPreRelease(true); // Add this only if you want to use prereleases Localizely.setAppVersion('<APP_VERSION>'); // Add this only if you want to explicitly set the application version, or in cases when automatic detection is not possible (e.g. Flutter web apps) runApp(MaterialApp( onGenerateTitle: (context) => S.of(context).appTitle, localizationsDelegates: [ S.delegate, GlobalMaterialLocalizations.delegate, GlobalWidgetsLocalizations.delegate, GlobalCupertinoLocalizations.delegate, ], supportedLocales: S.delegate.supportedLocales, home: HomePage())); } class HomePage extends StatefulWidget { @override State<StatefulWidget> createState() => _HomePageState(); } class _HomePageState extends State<HomePage> { bool _isLoading = true; @override void initState() { super.initState(); Localizely.updateTranslations().then( // Call 'updateTranslations' after localization delegates initialization (response) => setState(() { _isLoading = false; }), onError: (error) => setState(() { _isLoading = false; })); } @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar(title: Text(S.of(context).pageHomeTitle)), body: Center( child: _isLoading ? CircularProgressIndicator() : Column(children: <Widget>[Text(S.of(context).welcome)]))); } }