user_country_detector_android 0.0.1
user_country_detector_android: ^0.0.1 copied to clipboard
User country detector. Android only.
example/lib/main.dart
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:user_country_detector_android/user_country_detector_android.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({super.key});
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
Future<(String, bool)> get future => Future(() async {
final nci = await UserCountryDetectorAndroid.getCountryIso3166Alpha2();
final sup = await UserCountryDetectorAndroid.isSupported;
return (nci, sup);
});
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Plugin example app'),
),
floatingActionButton: FloatingActionButton(onPressed: () {
setState(() {
});
}),
body: Center(
child: FutureBuilder(
future: future,
builder: (context, snapshot) {
if (snapshot.connectionState != ConnectionState.done) {
return CircularProgressIndicator();
}
if (snapshot.hasError) {
return Text('${snapshot.error}');
}
return Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text('Country code: ${snapshot.data!.$1}'),
Text('Supports detector: ${snapshot.data!.$2}'),
],
);
},
),
),
),
);
}
}