I'm trying to use WhitelistingTextInputFormatter in a TextFormField in a Flutter app but I get
undefined name WhitelistingTextInputFormatter
Here is my code:
child: TextFormField(
keyboardType: TextInputType.number,
inputFormatters: [WhitelistingTextInputFormatter.digitsOnly],
decoration: InputDecoration(labelText: 'Staff Number', hintText: 'enter staff number'),
),
Even though you have package:flutter/services.dart imported, in Flutter 2.8.0 was fully deprecated.
Please check the documentation:
@Deprecated(
'Use FilteringTextInputFormatter.digitsOnly instead. '
'This feature was deprecated after v1.20.0-1.0.pre.',
)
Just change WhitelistingTextInputFormatter to FilteringTextInputFormatter
can you confirm you are importing:
import 'package:flutter/services.dart';
at the start of your file?
Also, i think here is the answer to your question:
How to use InputFormatter on Flutter TextField?
"In the services library you will find the TextInputFormatter abstract class (this means that you have to import package:flutter/services.dart)."
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With