flutter_intl_phone_field 0.0.4 flutter_intl_phone_field: ^0.0.4 copied to clipboard
A customized Flutter TextFormField to input international phone number along with country code.
import 'package:flutter/material.dart';
import 'package:flutter_intl_phone_field/flutter_intl_phone_field.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({super.key});
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
final GlobalKey<FormState> _formKey = GlobalKey();
FocusNode focusNode = FocusNode();
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
appBar: AppBar(
title: const Text('Phone Field Example'),
),
body: Padding(
padding: const EdgeInsets.symmetric(horizontal: 16.0),
child: Form(
key: _formKey,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
const SizedBox(height: 30),
const TextField(
decoration: InputDecoration(
labelText: 'Name',
border: OutlineInputBorder(
borderSide: BorderSide(),
),
),
),
const SizedBox(
height: 10,
),
const TextField(
decoration: InputDecoration(
labelText: 'Email',
border: OutlineInputBorder(
borderSide: BorderSide(),
),
),
),
const SizedBox(
height: 10,
),
IntlPhoneField(
focusNode: focusNode,
decoration: const InputDecoration(
labelText: 'Phone Number',
border: OutlineInputBorder(
borderSide: BorderSide(),
),
),
languageCode: "en",
onChanged: (phone) {
print(phone.completeNumber);
},
onCountryChanged: (country) {
print('Country changed to: ${country.name}');
},
),
const SizedBox(
height: 10,
),
MaterialButton(
color: Theme.of(context).primaryColor,
textColor: Colors.white,
onPressed: () {
_formKey.currentState?.validate();
},
child: const Text('Submit'),
),
],
),
),
),
),
);
}
}