number_field 0.1.0 copy "number_field: ^0.1.0" to clipboard
number_field: ^0.1.0 copied to clipboard

A Flutter package for phone number input with country code selection.

example/lib/main.dart

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

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

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flag Phone Field Demo',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.blue),
        useMaterial3: true,
      ),
      home: const MyHomePage(),
      debugShowCheckedModeBanner: false,
    );
  }
}

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

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

class _MyHomePageState extends State<MyHomePage> {
  final TextEditingController _phoneController = TextEditingController();
  Country? _selectedCountry ;

  @override
  void dispose() {
    _phoneController.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Flag Phone TextField'),
        elevation: 2,
      ),
      body: Padding(
        padding: const EdgeInsets.all(16.0),
        child: Column(
          children: [
            const Text(
              'Enter phone number to detect country:',
              style: TextStyle(fontSize: 16, fontWeight: FontWeight.w500),
            ),
            const SizedBox(height: 12),
            FlagPhoneTextField(
              controller: _phoneController,
              decoration: const InputDecoration(
                hintText: 'e.g., +9123456789 or +15343344555',
                border: OutlineInputBorder(),
              ),
              onCountryChanged: (country) {
                setState(() {
                  _selectedCountry = country;
                });
              },
            ),
            const SizedBox(height: 24),
            if (_selectedCountry != null) ...[
              const Text(
                'Detected Country:',
                style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold),
              ),
              const SizedBox(height: 8),
              _buildInfoRow('Flag:', _selectedCountry!.flagEmoji),
              _buildInfoRow('Country:', _selectedCountry!.name),
              _buildInfoRow('ISO Code:', _selectedCountry!.code),
              _buildInfoRow('Dial Code:', _selectedCountry!.dialCode),
            ],
          ],
        ),
      ),
    );
  }

  Widget _buildInfoRow(String label, String value) {
    return Padding(
      padding: const EdgeInsets.symmetric(vertical: 4),
      child: Row(
        children: [
          SizedBox(width: 90, child: Text(label)),
          Text(value),
        ],
      ),
    );
  }
}
3
likes
0
points
25
downloads

Publisher

unverified uploader

Weekly Downloads

A Flutter package for phone number input with country code selection.

Homepage

License

unknown (license)

Dependencies

flutter

More

Packages that depend on number_field