flutter_phone_number_field 1.0.0 copy "flutter_phone_number_field: ^1.0.0" to clipboard
flutter_phone_number_field: ^1.0.0 copied to clipboard

A customised Flutter TextFormField to input international phone number along with country code.

##International Phone Field Package pub v1.0.0

A customised Flutter TextFormField to input international phone number along with country code.

This widget can be used to make customised text field to take phone number input for any country along with an option to choose country code from a dropdown.You will be able to modify country flags size when building Flutter Web app.

Features #

Getting started #

To use this package:

Run this command:

flutter pub add flutter_phone_number_field

Or, add the following to your pubspec.yaml file:

dependences: flutter_phone_number_field: ^1.0.0

Usage #

Simply create a FlutterPhoneNumberField widget, and pass the required params:

import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_phone_number_field/src/country_picker_dialog.dart';
import 'package:flutter_phone_number_field/flutter_phone_number_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> {
  GlobalKey<FormState> formKey = GlobalKey();

  FocusNode focusNode = FocusNode();
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Phone Number Field Example'),
        ),
        body: Padding(
          padding: const EdgeInsets.symmetric(horizontal: 16.0),
          child: Form(
            key: formKey,
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: <Widget>[
                FlutterPhoneNumberField(
                  focusNode: focusNode,
                  initialCountryCode: "TG",
                  pickerDialogStyle: PickerDialogStyle(
                    countryFlagStyle: const TextStyle(fontSize: 17),
                  ),
                  decoration: const InputDecoration(
                    hintText: 'Phone Number',
                    border: OutlineInputBorder(
                      borderSide: BorderSide(),
                    ),
                  ),
                  languageCode: "en",
                  onChanged: (phone) {
                    if (kDebugMode) {
                      print(phone.completeNumber);
                    }
                  },
                  onCountryChanged: (country) {
                    if (kDebugMode) {
                      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'),
                ),
              ],
            ),
          ),
        ),
      ),
    );
  }
}

Use initialCountryCode to set an initial Country Code. Use webCountryIconWidth to set country flag width if you are building Flutter Web app

3
likes
155
points
113
downloads

Publisher

unverified uploader

Weekly Downloads

A customised Flutter TextFormField to input international phone number along with country code.

Homepage

Documentation

API reference

License

MIT (license)

Dependencies

flutter, test

More

Packages that depend on flutter_phone_number_field