flutter_localized_country_name 0.0.1

  • Readme
  • Changelog
  • Example
  • Installing
  • 57

flutter_localized_country_name #

A Flutter plugin to get localized country name with the help of Native functions.

Supports both Android and iOS.

Features #

  • Get localized country code
  • Enabled forcing a locale to use if needed

How to use #

To use this library, all you need to do is call this function below to get the localized country names:

await FlutterLocalizedCountryName.getLocalizedCountryName(
          countryCode: countryCode,
          localeToUse: forcedLocale
      );

Please do note that if you don't supply a value for localeToUse, then this library will use the current locale of the device if supported by the application. If supplied, this library will use that locale no matter if it's supported by the application or not.

Contributor #

  • Angga Dwi Arifandi (a.arifandi@mozio.com)

0.0.1 #

  • Initial features:
    • Get localized country code name
    • Enabled forcing a locale if needed

example/lib/main.dart

import 'package:flutter/material.dart';

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

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

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

class _MyAppState extends State<MyApp> {
  TextEditingController _countryCodeController;
  TextEditingController _forcedLocaleController;
  String _countryName;

  @override
  void initState() {
    super.initState();
    _countryCodeController = TextEditingController();
    _forcedLocaleController = TextEditingController();
  }

  @override
  void dispose() {
    _countryCodeController.dispose();
    _forcedLocaleController.dispose();
    super.dispose();
  }

  convertCountryName() async {
    String countryCode = _countryCodeController.text;
    String forcedLocale = _forcedLocaleController.text;
    String countryName;
    try {
      String countryName = await FlutterLocalizedCountryName.getLocalizedCountryName(
          countryCode: countryCode,
          localeToUse: forcedLocale
      );
    } on PlatformException {
      countryName = 'Failed to get country name.';
    }
    setState(() {
      _countryName = countryName;
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Example app'),
        ),
        body: Padding(
          padding: EdgeInsets.symmetric(horizontal: 10.0),
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            crossAxisAlignment: CrossAxisAlignment.center,
            children: <Widget>[
              TextField(
                controller: _countryCodeController,
                decoration: InputDecoration(
                  border: UnderlineInputBorder(),
                  labelText: "Country name (*)"
                ),
              ),
              TextField(
                controller: _forcedLocaleController,
                decoration: InputDecoration(
                    border: UnderlineInputBorder(),
                    labelText: "Forced Locale"
                ),
              ),
              Padding(
                padding: EdgeInsets.only(top: 10.0),
                child: RaisedButton(
                  onPressed: convertCountryName,
                  child: Text(
                    "CONVERT"
                  ),
                ),
              ),
              Padding(
                padding: const EdgeInsets.only(top: 10.0),
                child: Center(
                  child: Text(
                      'Country name is: $_countryName\n',
                  ),
                ),
              )
            ],
          ),
        ),
      ),
    );
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  flutter_localized_country_name: ^0.0.1

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:flutter_localized_country_name/flutter_localized_country_name.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
26
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
72
Overall:
Weighted score of the above. [more]
57
Learn more about scoring.

We analyzed this package on Jul 10, 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:flutter_localized_country_name/flutter_localized_country_name.dart that declares support for platforms: android, ios

Package does not support Flutter platform macos

Because:

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

Package does not support Flutter platform web

Because:

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

Package does not support Flutter platform windows

Because:

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

Package not compatible with SDK dart

Because:

  • flutter_localized_country_name that is a package requiring null.

Health suggestions

Format lib/constants.dart.

Run flutter format to format lib/constants.dart.

Format lib/flutter_localized_country_name.dart.

Run flutter format to format lib/flutter_localized_country_name.dart.

Format lib/generated/i18n.dart.

Run flutter format to format lib/generated/i18n.dart.

Maintenance suggestions

The package description is too short. (-13 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.

Package is pre-v0.1 release. (-10 points)

While nothing is inherently wrong with versions of 0.0.*, it might mean that the author is still experimenting with the general direction of the API.

Homepage URL is insecure. (-5 points)

Update the homepage field and use a secure (https) URL.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.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
Dev dependencies
flutter_test