Reputation: 1538
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'),
),
Upvotes: 13
Views: 13438
Reputation: 31
First import 'package:flutter/services.dart'; Then Just change WhitelistingTextInputFormatter to FilteringTextInputFormatter.
Upvotes: 2
Reputation: 525
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)."
Upvotes: 10
Reputation: 2310
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
Upvotes: 36