input_phone_field 0.0.6
input_phone_field: ^0.0.6 copied to clipboard
Input phone field is a plugin to control your field.
example/lib/main.dart
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:input_phone_field/input_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<FormFieldState> _phoneFormFieldState = GlobalKey();
final _phoneController = TextEditingController();
final _phoneFocusNode = FocusNode();
String _phoneError = '';
@override
void initState() {
super.initState();
_find();
}
Future<void> _find() async {
final r = await findCountryByPhone('', 'vn');
debugPrint('${r.toString()}');
}
@override
void dispose() {
super.dispose();
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: GestureDetector(
onTap: () => setState(() {
_phoneError = _phoneController.text.isEmpty ? 'Error':'';
_phoneFocusNode.unfocus();
}),
child: Scaffold(
appBar: AppBar(
title: const Text('Plugin example app'),
),
body: Center(
child: InputPhoneField(
formFieldKey: _phoneFormFieldState,
controller: _phoneController,
focusNode: _phoneFocusNode,
style: TextStyle(fontSize: 13),
isHideCountring: true,
dropdownIcon: const Icon(Icons.expand_more),
dropdownIconPosition: IconPosition.trailing,
invalidNumberMessage: _phoneError,
// autovalidateMode: AutovalidateMode.disabled,
errorStyle: TextStyle(color: Colors.red),
errorMinLength: 'Phone number is too short.',
labelStyle: TextStyle(),
pickerDialogStyle: PickerDialogStyle(
isHideBackIcon: true,
isHideSearch: true,
isTrailingCountryCode: false,
isHideCountryCodeOption: false,
countryNameStyle: TextStyle(fontSize: 16),
countryCodeStyle: TextStyle(fontSize: 16),
backgroundColor: Colors.grey.shade50,
isHideCheckIcon: false,
checkColor: Colors.blueAccent,
title: 'Select country',
titleStyle: TextStyle(fontSize: 15),
pickerType: PickerDialogType.bottomsheet,
padding: const EdgeInsets.symmetric(horizontal: 16),
),
decoration: InputDecoration(
labelText: 'Phone number',
hintText: 'Enter phone number',
),
languageCode: "vn",
initialCountryCode: "vn",
isRequireString: _phoneError,
onChanged: (phone) {
debugPrint(phone.completeNumber);
},
onError: (p0) {
_phoneError = p0 ?? '';
},
onCountryChanged: (country) {
_phoneController.text = '';
},
),
),
),
),
);
}
}