platform_interface 1.0.2

  • Readme
  • Changelog
  • Example
  • Installing
  • 58

platform_interface #

Gets the device locale data, independent of the app locale settings.

Usage #

import 'package:platform_interface/platform_interface.dart';

then

List languages = await PlatformInterface.preferredLanguages;
String locale = await PlatformInterface.currentLocale;

this should return a list of the preferred/current language locales setup on the device, with the current one being the first in the list or just the currently set device locale.

iOS #

Updates #

Getting Started #

For help getting started with Flutter, view our online documentation, which offers tutorials, samples, guidance on mobile development, and a full API reference.

1.0.2 #

  • Fixed Warning on iOS for iOS version < 10

1.0.1 #

  • Homepage Address fixed

1.0.0 #

  • Initial release.

example/lib/main.dart

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

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

/// Demo getting a device locale
class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  List _languages = List();
  Locale _locale;

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

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initPlatformState() async {
    List languages;
    Locale currentLocale;
    // Platform messages may fail, so we use a try/catch PlatformException.
    try {
      languages = await PlatformInterface.locale.preferredLanguages;
      print(languages);
    } on PlatformException {
      print("Error obtaining preferred languages");
    }
    try {
      currentLocale = await PlatformInterface.locale.currentLocale;
      print(currentLocale);
    } on PlatformException {
      print("Error obtaining current 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(() {
      _languages = languages;
      _locale = currentLocale;
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Center(
            child: Column(
          children: <Widget>[
            Text("Current locale: "),
            Text('$_locale'),
            Text("Preferred Languages: "),
            Text(_languages.toString()),
            Padding(
              padding: EdgeInsets.all(10),
              child: RaisedButton(
                  onPressed: () {
                    listLanguages();
                  },
                  child: Text("Run Test")),
            ),
          ],
        )),
      ),
    );
  }

  /// testing for issue-12
  void listLanguages() async {
    List languages = await PlatformInterface.locale.preferredLanguages;
    Locale locale = await PlatformInterface.locale.currentLocale;
    print('current locale: $locale, preferred device languages:');
    languages.forEach((l) => print(l));
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  platform_interface: ^1.0.2

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:platform_interface/platform_interface.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
16
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
58
Learn more about scoring.

We analyzed this package on Jul 9, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.14
  • Flutter: 1.17.5

Analysis suggestions

Package does not support Flutter platform linux

Because:

  • package:platform_interface/platform_interface.dart that declares support for platforms: android, ios

Package does not support Flutter platform macos

Because:

  • package:platform_interface/platform_interface.dart that declares support for platforms: android, ios

Package does not support Flutter platform web

Because:

  • package:platform_interface/platform_interface.dart that declares support for platforms: android, ios

Package does not support Flutter platform windows

Because:

  • package:platform_interface/platform_interface.dart that declares support for platforms: android, ios

Package not compatible with SDK dart

Because:

  • platform_interface that is a package requiring null.

Health suggestions

Format lib/main.dart.

Run flutter format to format lib/main.dart.

Format lib/platform_interface.dart.

Run flutter format to format lib/platform_interface.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.12 1.14.13
meta 1.1.8 1.2.2
sky_engine 0.0.99
typed_data 1.1.6 1.2.0
vector_math 2.0.8 2.1.0-nullsafety