phone_input_field 0.0.1 copy "phone_input_field: ^0.0.1" to clipboard
phone_input_field: ^0.0.1 copied to clipboard

A Flutter package for international phone number input with country selection. Features a country picker dialog with search and customizable phone input field.

example/lib/main.dart

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

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

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'International Phone Input Example',
      theme: ThemeData(
        primarySwatch: Colors.blue,
        useMaterial3: true,
      ),
      home: const ExamplePage(),
    );
  }
}

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

  @override
  State<ExamplePage> createState() => _ExamplePageState();
}

class _ExamplePageState extends State<ExamplePage> {
  late TextEditingController _phoneController;
  Country? _selectedCountry;

  @override
  void initState() {
    super.initState();
    _phoneController = TextEditingController();
  }

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

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Phone Input Example'),
        elevation: 0,
      ),
      body: Padding(
        padding: const EdgeInsets.all(24),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Text(
              'Enter Your Phone Number',
              style: Theme.of(context).textTheme.headlineSmall,
            ),
            const SizedBox(height: 24),
            PhoneInputField(
              controller: _phoneController,
              onChanged: (value) {
                setState(() {});
              },
              onCountryChanged: (country) {
                setState(() {
                  _selectedCountry = country;
                });
              },
            ),
            const SizedBox(height: 32),
            Container(
              padding: const EdgeInsets.all(16),
              decoration: BoxDecoration(
                color: Colors.grey.shade100,
                borderRadius: BorderRadius.circular(8),
              ),
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Text(
                    'Phone Details:',
                    style: Theme.of(context).textTheme.titleMedium,
                  ),
                  const SizedBox(height: 12),
                  Text(
                    'Country: ${_selectedCountry?.name ?? 'Indonesia'}',
                  ),
                  const SizedBox(height: 8),
                  Text(
                    'Phone: ${_phoneController.text.isEmpty ? "Not entered" : _phoneController.text}',
                  ),
                ],
              ),
            ),
          ],
        ),
      ),
    );
  }
}
0
likes
150
points
4
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

A Flutter package for international phone number input with country selection. Features a country picker dialog with search and customizable phone input field.

Repository (GitHub)
View/report issues

Topics

#phone-input #country-selector #internalization #ui-widgets

License

BSD-3-Clause (license)

Dependencies

flutter

More

Packages that depend on phone_input_field