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

This package is used to get country code and country name from country code.

example/lib/main.dart

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

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

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

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Country Code Manager Example',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      home: const MyHomePage(title: 'Country Code Manager Example'),
    );
  }
}

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

  // This widget is the home page of your application. It is stateful, meaning
  // that it has a State object (defined below) that contains fields that affect
  // how it looks.

  // This class is the configuration for the state. It holds the values (in this
  // case the title) provided by the parent (in this case the App widget) and
  // used by the build method of the State. Fields in a Widget subclass are
  // always marked "final".

  final String title;

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

class _MyHomePageState extends State<MyHomePage> {
  Country? selectedCountry;

  @override
  void initState() {
    CountryCodeManager.instance.init();
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            ElevatedButton(
              onPressed: () async {
                final result = await ShowCountries.show(context);
                if (result != null) {
                  setState(() {
                    selectedCountry = result;
                  });
                }
              },
              child: const Text('Show Countries'),
            ),
            const SizedBox(height: 20),
            Text(selectedCountry?.name ?? ''),
            const SizedBox(height: 20),
            ShowFlag(countryCode: selectedCountry?.code ?? 'US'),
            const SizedBox(height: 20),
            ShowDialCode(
              initialValue: selectedCountry?.dialCode,
              onSelected: (value) {
                debugPrint(value);
              },
            ),
          ],
        ),
      ),
    );
  }
}
4
likes
160
pub points
35%
popularity

Publisher

verified publisherefestech.com.tr

This package is used to get country code and country name from country code.

Homepage
Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

flutter, very_good_analysis

More

Packages that depend on country_code_manager