lokalise_flutter_sdk 0.0.5 copy "lokalise_flutter_sdk: ^0.0.5" to clipboard
lokalise_flutter_sdk: ^0.0.5 copied to clipboard

outdated

Lokalise Flutter SDK over-the-air translations update

Lokalise Flutter SDK #

This package provides Over-the-Air translation updates

Over-the-air translation updates #

Update translations for your Flutter applications over the air. Learn more

Getting started #

Initialize Lokalise SDK (main.dart file)

Usage #

import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:lokalise_flutter_sdk/lokalise_flutter_sdk.dart'; // Import sdk package
import 'generated/l10n.dart';

void main() {
  Lokalise.init('<SDK_TOKEN>', '<PROJECT ID>'); // Init sdk 
  Lokalise.setPreRelease(true); // Add this only if you want to use prereleases
  

  runApp(MaterialApp(
      onGenerateTitle: (context) => Tr.of(context).appTitle,
      localizationsDelegates: [
        Tr.delegate,
        GlobalMaterialLocalizations.delegate,
        GlobalWidgetsLocalizations.delegate,
        GlobalCupertinoLocalizations.delegate,
      ],
      supportedLocales: Tr.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();

    Lokalise.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(Tr.of(context).pageHomeTitle)),
        body: Center(
            child: _isLoading ? CircularProgressIndicator() : Column(children: <Widget>[Text(Tr.of(context).welcome)])));
  }
}

Additional information #

Generate localization files

flutter pub run lokalise_flutter_sdk:g