phone_input_field 0.0.1
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.
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}',
),
],
),
),
],
),
),
);
}
}