flutter_device_locale 0.2.0 copy "flutter_device_locale: ^0.2.0" to clipboard
flutter_device_locale: ^0.2.0 copied to clipboard

outdated

A Flutter plugin for retrieving the device locale information.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'dart:async';

import 'package:flutter/services.dart';
import 'package:flutter_device_locale/flutter_device_locale.dart';

void main() => runApp(MyApp());

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  String _deviceLocale = 'Unknown';

  @override
  void initState() {
    super.initState();
    initDeviceLocale();
  }

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initDeviceLocale() async {
    String deviceLocale;
    // Platform messages may fail, so we use a try/catch PlatformException.
    try {
      deviceLocale = (await FlutterDeviceLocale.getCurrentLocale()).toString();
    } on PlatformException {
      deviceLocale = 'Failed to get the device locale.';
    }

    // If the widget was removed from the tree while the asynchronous platform
    // message was in flight, we want to discard the reply rather than calling
    // setState to update our non-existent appearance.
    if (!mounted) return;

    setState(() {
      _deviceLocale = deviceLocale;
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Center(
          child: Text('Current Locale: $_deviceLocale\n'),
        ),
      ),
    );
  }
}
16
likes
0
pub points
54%
popularity

Publisher

verified publisherjesway.com

A Flutter plugin for retrieving the device locale information.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter

More

Packages that depend on flutter_device_locale