country_state_city_picker 2.0.0 copy "country_state_city_picker: ^2.0.0" to clipboard
country_state_city_picker: ^2.0.0 copied to clipboard

A flutter package for showing a country, states, and cities. In addition it gives the possibility to select a list of favorites countries.

example/lib/main.dart

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

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

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      title: 'Country State and City Picker',
      theme: ThemeData(
        primarySwatch: Colors.blue,
        useMaterial3: true,
      ),
      home: const MyHomePage(),
    );
  }
}

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

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

class _MyHomePageState extends State<MyHomePage> {
  String? countryValue;
  String? stateValue;
  String? cityValue;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Country State and City Picker'),
        elevation: 2,
      ),
      body: SingleChildScrollView(
        padding: const EdgeInsets.all(20),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            const Text(
              "Adaptive Picker",
              style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
            ),
            const SizedBox(height: 10),
            SelectState(
              pickerType: PickerType.adaptive,
              onCountryChanged: (value) {
                setState(() {
                  countryValue = value;
                });
              },
              onStateChanged: (value) {
                setState(() {
                  stateValue = value;
                });
              },
              onCityChanged: (value) {
                setState(() {
                  cityValue = value;
                });
              },
            ),
            const SizedBox(height: 30),
            const Text(
              "Custom Decoration & Initial Value",
              style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
            ),
            const SizedBox(height: 10),
            SelectState(
              defaultValue: "United States",
              defaultState: "California",
              decoration: InputDecoration(
                filled: true,
                fillColor: Colors.blue.withOpacity(0.1),
                border: OutlineInputBorder(
                  borderRadius: BorderRadius.circular(12),
                  borderSide: BorderSide.none,
                ),
              ),
              onCountryChanged: (value) {},
              onStateChanged: (value) {},
              onCityChanged: (value) {},
            ),
            const SizedBox(height: 30),
            if (countryValue != null)
              Card(
                child: Padding(
                  padding: const EdgeInsets.all(16.0),
                  child: Column(
                    children: [
                      Text("Country: $countryValue"),
                      Text("State: $stateValue"),
                      Text("City: $cityValue"),
                    ],
                  ),
                ),
              ),
          ],
        ),
      ),
    );
  }
}
94
likes
150
points
1.78k
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

A flutter package for showing a country, states, and cities. In addition it gives the possibility to select a list of favorites countries.

Homepage
Repository (GitHub)
View/report issues

License

BSD-3-Clause (license)

Dependencies

cupertino_icons, dropdown_search, flutter

More

Packages that depend on country_state_city_picker