ptwcode_country_codes 1.0.9 copy "ptwcode_country_codes: ^1.0.9" to clipboard
ptwcode_country_codes: ^1.0.9 copied to clipboard

A package to find the calling code and iso code to a country.

example/lib/main.dart

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

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

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

  @override
  Widget build(BuildContext context) {
    return const MaterialApp(
      home: MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});

  final String title;

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

class _MyHomePageState extends State<MyHomePage> {
  Country? _dialogCountry;
  Country? _defaultCountry;

  void _onTapDialog() async {
    _dialogCountry = await showCountryDialog(context);
    setState(() {});
  }

  void _onTapDefault() async {
    _defaultCountry = await getDefaultCountry();
    setState(() {});
  }

  @override
  Widget build(BuildContext context) {
    const style = TextStyle(fontWeight: FontWeight.bold, fontSize: 20);

    return Scaffold(
      appBar: AppBar(title: Text(widget.title)),
      body: Column(
        mainAxisAlignment: MainAxisAlignment.spaceEvenly,
        children: [
          const Center(child: Text('Countries Dialog', style: style)),
          Center(
            child: ElevatedButton(
              onPressed: _onTapDialog,
              child: Text(
                _dialogCountry == null
                    ? 'no country choosen'
                    : 'Country: ${_dialogCountry?.name} | Code: +${_dialogCountry?.call}',
              ),
            ),
          ),
          const Center(child: Text('Default Country', style: style)),
          Center(
            child: ElevatedButton(
              onPressed: _onTapDefault,
              child: Text(
                _defaultCountry == null
                    ? 'no country choosen'
                    : 'Country: ${_defaultCountry?.name} | Code: +${_defaultCountry?.call}',
              ),
            ),
          ),
          const SizedBox(),
        ],
      ),
    );
  }
}
2
likes
150
points
63
downloads

Publisher

unverified uploader

Weekly Downloads

A package to find the calling code and iso code to a country.

Repository (GitHub)

Documentation

API reference

License

MIT (license)

Dependencies

dio, flutter

More

Packages that depend on ptwcode_country_codes