Search packages, repositories and app categories

Package detailsv1.4.0

device_region

This plugin uses platform-specific API to return SIM country code

AndroidiOSWindowsLinux
30-day downloads
18.3K
Likes
26
Pub points
150

Install package

flutter pub add device_region

Package Overview

Package selection guidance compiled from public package information, community data, and project usage.

The device_region package retrieves the SIM country code using platform-specific APIs on Android, iOS, Windows, and Linux. It provides a simple, cross-platform way to determine the country associated with the device's SIM card, which is useful for localization, region-based content delivery, or compliance checks. The plugin abstracts native implementation details, offering a consistent Dart interface across platforms. It does not require internet access and operates directly from device-level data.

Use cases

  • Determining user's country based on SIM card
  • Localizing app content by region
  • Enforcing region-specific restrictions
  • Automatically setting default country in forms
  • Supporting multi-region applications

Key features

  • Cross-platform support (Android, iOS, Windows, Linux)
  • Uses native SIM country code APIs
  • No internet required
  • Simple, lightweight API
  • Returns ISO 3166-1 alpha-2 country codes

Suitable for

  • Apps needing regional detection without GPS
  • Travel or payment apps requiring country context
  • Localization frameworks
  • Offline-first applications
  • Developers targeting multiple platforms

Considerations

  • Relies on SIM card presence; may return null if no SIM
  • Does not work on devices without SIM (e.g., tablets)
  • Country code may not reflect user's current location
  • Limited to SIM-based country identification
  • May require runtime permissions on some platforms

Original README

Original README snapshot from the linked source repository. Visit the repository for the latest content.

device_region

A Flutter plugin which uses platform-specific API to return a SIM country code. Supports iOS and Android.

Installation

In your Flutter project, in pubspec.yaml file add the dependency:

dependencies:
  device_region: ^1.4.0

Usage example

Import device_region.dart package.

import 'package:device_region/device_region.dart';
Get SIM country code

Call getSIMCountryCode method to receive SIM country code.

await DeviceRegion.getSIMCountryCode();
Android:

Using TelephonyManager class:

Returns simCountryIso if available. Otherwise, it should return networkCountryIso.

In case the value cannot be retrieved or an error occurs, null value will be returned

iOS:
iOS 16.0 and higher

Due to deprecated properties in CTTelephonyNetworkInfo class, plugin uses Locale class and returns Locale.current.region.identifier.

iOS up to 16.0

Using CTTelephonyNetworkInfo class:

Returns isoCountryCode if available.

In case the value cannot be retrieved or an error occurs, null value will be returned

Important notes

  • While call getSIMCountryCode on iOS (up to 16.0), it returns proper country code and can throw error log in debugger as below:
[Client] Updating selectors after delegate addition failed with: Error Domain=NSCocoaErrorDomain Code=4099 "The connection to service with pid 91 named com.apple.commcenter.coretelephony.xpc was invalidated from this process." UserInfo={NSDebugDescription=The connection to service with pid 91 named com.apple.commcenter.coretelephony.xpc was invalidated from this process.}

It's well known bug on iOS and it does not affect the operation of the application.

  • Method returns null in case if for some reason it was not possible to retrieve the information from the SIM slot. So it will return null i.e on iOS simulators and devices without SIM card inserted.

  • On iOS, it only works from 12.0 and above. For lower versions it will return null.

Categories

Source repository

Projects using this package