fts_system_locale 0.0.2 copy "fts_system_locale: ^0.0.2" to clipboard
fts_system_locale: ^0.0.2 copied to clipboard

Change the system locale for your app. You might need this when you localize your flutter app and it includes a native view.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:fts_system_locale/fts_system_locale.dart';

import 'i18n/i18n.dart';

void main() {
  runApp(const MyApp());
}

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

  @override
  State<MyApp> createState() => _MyAppState();
}

const methodChannel = MethodChannel('com.example.example');

class _MyAppState extends State<MyApp> {
  @override
  void initState() {
    super.initState();
    Fts.onSystemLocaleChanged.addListener(() {
      setState(() {
        Fts.locale = Fts.onSystemLocaleChanged.value;
      });
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      localizationsDelegates: const [
        Fts.delegate,
        GlobalMaterialLocalizations.delegate,
        GlobalWidgetsLocalizations.delegate,
        GlobalCupertinoLocalizations.delegate,
      ],
      supportedLocales: AppLocales.supportedLocales,
      home: Scaffold(
        appBar: AppBar(title: Text(Strings.home.title.tr())),
        body: Center(
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.center,
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              DropdownButton<Locale>(
                items: AppLocales.supportedLocales
                    .map((e) =>
                        DropdownMenuItem(value: e, child: Text(e.languageCode)))
                    .toList(),
                onChanged: (value) {
                  setState(() {
                    Fts.locale = value ?? Fts.deviceLocale;
                  });
                  FtsSystemLocale().setLocale(value?.languageCode);
                },
                value: Fts.locale,
              ),
              TextButton(
                onPressed: () => methodChannel
                    .invokeMethod('navigateToActivity')
                    .then((value) => debugPrint(value.toString())),
                child: Text(Strings.home.navigateTo.tr()),
              ),
            ],
          ),
        ),
      ),
    );
  }
}
3
likes
140
pub points
38%
popularity

Publisher

unverified uploader

Change the system locale for your app. You might need this when you localize your flutter app and it includes a native view.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (LICENSE)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on fts_system_locale