country_detector 1.0.2 copy "country_detector: ^1.0.2" to clipboard
country_detector: ^1.0.2 copied to clipboard

flutter plugin for android and ios that detects a user's country code

example/lib/main.dart

import 'package:flutter/material.dart';

import 'package:country_detector/country_detector.dart';

void main() {
  WidgetsFlutterBinding.ensureInitialized();
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  final _countryDetector = CountryDetector();

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Country Code Detector Example'),
        ),
        body: Center(
          child: Column(mainAxisSize: MainAxisSize.min, children: [
            FutureBuilder<String?>(
                future: _countryDetector.isoCountryCode(),
                builder: (_, future) {
                  if (future.connectionState == ConnectionState.done) {
                    return Text('isoCode : ${future.data ?? ''}\n');
                  }
                  if (future.hasError) {
                    return const Text('fetching iso country code failed\n');
                  }
                  return const Text('Fetching iso country code...\n');
                }),
            FutureBuilder<AllCountries>(
                future: _countryDetector.detectAll(),
                builder: (_, future) {
                  if (future.connectionState == ConnectionState.done) {
                    final allCodes = future.data ?? AllCountries();
                    String resultStr = '';
                    for (final code in allCodes.toMap().entries) {
                      resultStr += '${code.key} : ${code.value}\n';
                    }
                    return Text('$resultStr\n');
                  }
                  if (future.hasError) {
                    return const Text('fetching all country code failed\n');
                  }
                  return const Text('Fetching all country code...\n');
                }),
          ]),
        ),
      ),
    );
  }
}
5
likes
160
points
140
downloads

Publisher

verified publisherhyunwookim.net

Weekly Downloads

flutter plugin for android and ios that detects a user's country code

Homepage
Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on country_detector