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

Lokalise Flutter SDK over-the-air translations updates. This package provides new translations from lokalise.com without a new app release.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:lokalise_flutter_sdk/lokalise_flutter_sdk.dart'; // Imports the SDK
import 'l10n/generated/l10n.dart'; // Imports the generated Lt class

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  // Configures the SDK
  await Lokalise.init(
    projectId: 'Project ID',
    sdkToken: 'Lokalise SDK Token',
    // Add this only if you want to use prereleases. Use the Bundle freeze functionality in production
    preRelease: true,
  );
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Lokalise SDK',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: const MyHomePage(),
      localizationsDelegates: Lt.localizationsDelegates,
      supportedLocales: Lt.supportedLocales,
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key});

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> with WidgetsBindingObserver {
  bool _isLoading = true;

  @override
  void initState() {
    super.initState();
    WidgetsBinding.instance.addObserver(this);
    _updateTranslations();
  }

  void _updateTranslations() {
    setState(() => _isLoading = true);
    // Ensures the application has the latest translations
    Lokalise.instance.update().then(
          (_) => setState(() => _isLoading = false),
          onError: (error) => setState(() => _isLoading = false),
        );
  }

  @override
  void didChangeAppLifecycleState(AppLifecycleState state) {
    super.didChangeAppLifecycleState(state);
    if (state == AppLifecycleState.resumed) {
      _updateTranslations();
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(Lt.of(context).title), // Gets the translation
      ),
      body: Center(
        child: _isLoading
            ? const CircularProgressIndicator()
            : Center(
                child: Text(Lt.of(context).helloWorld), // Gets the translation
              ),
      ),
    );
  }
}
16
likes
160
pub points
92%
popularity

Publisher

verified publisherlokalise.com

Lokalise Flutter SDK over-the-air translations updates. This package provides new translations from lokalise.com without a new app release.

Homepage

Documentation

API reference

License

BSD-3-Clause (license)

Dependencies

archive, dart_style, flutter, http, intl, intl_translation, logger, package_info_plus, path, petitparser, shared_preferences, yaml

More

Packages that depend on lokalise_flutter_sdk