sh_country_detector 0.0.1 copy "sh_country_detector: ^0.0.1" to clipboard
sh_country_detector: ^0.0.1 copied to clipboard

A lightweight Flutter utility that detects the user's country automatically using device signals (SIM, timezone, locale) without location permissions or external APIs.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:sh_country_detector/sh_country_detector.dart';

void main() {
  runApp(const MyApp());
}

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Country Detector Example',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      home: const MyHomePage(),
    );
  }
}

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

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  Country? _detectedCountry;
  bool _loading = true;

  @override
  void initState() {
    super.initState();
    _detectCountry();
  }

  Future<void> _detectCountry() async {
    setState(() => _loading = true);
    final country = await CountryDetector.detect();
    setState(() {
      _detectedCountry = country;
      _loading = false;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Country Detector'),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            if (_loading)
              const CircularProgressIndicator()
            else if (_detectedCountry != null) ...[
              const Text('Detected Country:', style: TextStyle(fontSize: 18)),
              const SizedBox(height: 8),
              Text(
                _detectedCountry!.name,
                style:
                    const TextStyle(fontSize: 24, fontWeight: FontWeight.bold),
              ),
              Text(
                'Code: ${_detectedCountry!.isoCode}',
                style: const TextStyle(fontSize: 16, color: Colors.grey),
              ),
            ] else
              const Text('Could not detect country'),
            const SizedBox(height: 24),
            ElevatedButton(
              onPressed: _detectCountry,
              child: const Text('Detect Again'),
            ),
          ],
        ),
      ),
    );
  }
}
0
likes
140
points
0
downloads

Publisher

unverified uploader

Weekly Downloads

A lightweight Flutter utility that detects the user's country automatically using device signals (SIM, timezone, locale) without location permissions or external APIs.

Repository (GitHub)

Documentation

API reference

License

MIT (license)

Dependencies

flutter

More

Packages that depend on sh_country_detector

Packages that implement sh_country_detector