local_country_picker 1.1.0 copy "local_country_picker: ^1.1.0" to clipboard
local_country_picker: ^1.1.0 copied to clipboard

A self-contained Flutter country picker. 205 countries, bundled flag PNGs (round + rect), EN/NL translations, theme-aware styling. No network calls.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:local_country_picker/local_country_picker.dart';
import 'package:flutter_localizations/flutter_localizations.dart';

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

class _DemoApp extends StatefulWidget {
  const _DemoApp();

  @override
  State<_DemoApp> createState() => _DemoAppState();
}

class _DemoAppState extends State<_DemoApp> {
  Locale _locale = const Locale('en', 'US');

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Country Picker Demo',
      debugShowCheckedModeBanner: false,
      locale: _locale,
      supportedLocales: CountryPickerLocalizations.supportedLocales,
      localizationsDelegates: const [
        CountryPickerLocalizations.delegate,
        GlobalMaterialLocalizations.delegate,
        GlobalWidgetsLocalizations.delegate,
        GlobalCupertinoLocalizations.delegate,
      ],
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: const Color(0xFFFF4500)),
        scaffoldBackgroundColor: const Color(0xFFFAFAFC),
        useMaterial3: true,
      ),
      home: _DemoHome(
        locale: _locale,
        onLocaleChange: (l) => setState(() => _locale = l),
      ),
    );
  }
}

class _DemoHome extends StatefulWidget {
  const _DemoHome({required this.locale, required this.onLocaleChange});

  final Locale locale;
  final ValueChanged<Locale> onLocaleChange;

  @override
  State<_DemoHome> createState() => _DemoHomeState();
}

class _DemoHomeState extends State<_DemoHome> {
  Country? _selected;
  CountryFlagShape _shape = CountryFlagShape.round;

  Future<void> _open() async {
    final result = await showCountryPicker(
      context,
      selected: _selected,
      shape: _shape,
    );
    if (result != null) setState(() => _selected = result);
  }

  @override
  Widget build(BuildContext context) {
    final selected = _selected;
    return Scaffold(
      appBar: AppBar(title: const Text('local_country_picker')),
      body: Center(
        child: Padding(
          padding: const EdgeInsets.all(24),
          child: Column(
            mainAxisSize: MainAxisSize.min,
            children: [
              Text(
                selected == null
                    ? 'No country selected'
                    : '${selected.alpha2} — ${countryNameOf(context, selected.alpha2)}',
                style: Theme.of(context).textTheme.titleMedium,
              ),
              const SizedBox(height: 24),
              SegmentedButton<CountryFlagShape>(
                segments: const [
                  ButtonSegment(
                    value: CountryFlagShape.round,
                    label: Text('Round'),
                  ),
                  ButtonSegment(
                    value: CountryFlagShape.rect,
                    label: Text('Rect'),
                  ),
                ],
                selected: {_shape},
                onSelectionChanged: (s) => setState(() => _shape = s.first),
              ),
              const SizedBox(height: 12),
              SegmentedButton<Locale>(
                segments: const [
                  ButtonSegment(
                    value: Locale('en', 'US'),
                    label: Text('English'),
                  ),
                  ButtonSegment(
                    value: Locale('nl', 'NL'),
                    label: Text('Nederlands'),
                  ),
                ],
                selected: {widget.locale},
                onSelectionChanged: (s) => widget.onLocaleChange(s.first),
              ),
              const SizedBox(height: 24),
              FilledButton(
                onPressed: _open,
                child: const Text('Pick a country'),
              ),
            ],
          ),
        ),
      ),
    );
  }
}
1
likes
160
points
15
downloads
screenshot

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

A self-contained Flutter country picker. 205 countries, bundled flag PNGs (round + rect), EN/NL translations, theme-aware styling. No network calls.

Repository (GitHub)
View/report issues

Topics

#country #picker #flag #localization #offline

License

MIT (license)

Dependencies

flutter, flutter_localizations, flutter_svg

More

Packages that depend on local_country_picker