Skip to content

Commit

Permalink
updated android functionality from PR
Browse files Browse the repository at this point in the history
  • Loading branch information
magnatronus committed Jul 5, 2022
1 parent c8468e9 commit 57c54d8
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.5.3 - 5 Jul 2022

* merge PR to add additional Android functionality - see readme

## 0.5.2 - 19 May 2022

* Merge PR to detect token rather than hard code
Expand Down
8 changes: 6 additions & 2 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@ class _MyAppState extends State<MyApp> {
Future<void> _getCurrentLocale() async {
try {
final currentLocale = await Devicelocale.currentLocale;
print((currentLocale != null) ? currentLocale : "Unable to get currentLocale");
print((currentLocale != null)
? currentLocale
: "Unable to get currentLocale");
setState(() => _currentLocale = currentLocale);
} on PlatformException {
print("Error obtaining current locale");
Expand All @@ -104,7 +106,9 @@ class _MyAppState extends State<MyApp> {
Future<void> _getPreferedLanguages() async {
try {
final languages = await Devicelocale.preferredLanguages;
print((languages != null) ? languages : "unable to get preferred languages");
print((languages != null)
? languages
: "unable to get preferred languages");
setState(() => _languages = languages);
} on PlatformException {
print("Error obtaining preferred languages");
Expand Down
10 changes: 7 additions & 3 deletions lib/devicelocale.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import 'package:flutter/services.dart';

/// A Simple plug-in that can be used to query a device( iOS or Android) to obtain a list of current set up locales and languages
class Devicelocale {
static const MethodChannel _channel = const MethodChannel('uk.spiralarm.flutter/devicelocale');
static const MethodChannel _channel =
const MethodChannel('uk.spiralarm.flutter/devicelocale');

/// return a [Locale] based on the passed in String [info] or the [defaultLocale] and the platform
static Locale? _getAsLocale(String? info, String? defaultLocale) {
Expand All @@ -20,7 +21,9 @@ class Devicelocale {
List localeList = info.split(token);
if (localeList.length < 2) {
if (defaultLocale != null) {
List defaultList = defaultLocale.contains('-') ? defaultLocale.split('-') : defaultLocale.split('_');
List defaultList = defaultLocale.contains('-')
? defaultLocale.split('-')
: defaultLocale.split('_');
if (defaultList.length >= 2) {
return Locale(defaultList[0], defaultList[1]);
} else {
Expand Down Expand Up @@ -77,7 +80,8 @@ class Devicelocale {
/// Returns a [bool] so you know if language per app setting is available.
static Future<bool> get isLanguagePerAppSettingSupported async {
if (!Platform.isAndroid) return false;
final bool? isSupported = await _channel.invokeMethod('isLanguagePerAppSettingSupported');
final bool? isSupported =
await _channel.invokeMethod('isLanguagePerAppSettingSupported');
return isSupported ?? false;
}

Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: devicelocale
description: A Flutter package that can be used to extract the locales that are currently defined on a device with the current locale set as the first in the list.
version: 0.5.2
version: 0.5.3
homepage: https://github.com/magnatronus/flutter-devicelocale

environment:
Expand Down

0 comments on commit 57c54d8

Please sign in to comment.