I am developping a Flutter app which uses a Textfield
.
I am declaring the TextField
like this :
new TextField(
controller : _controller,
decoration : new InputDecoration(
hintText: 'Message...'
)
)
The TextField
is displayed in my widget, however when I tap on it, the keyboard is automatically closed and the following error appears in the console
E/SpannableStringBuilder(17860): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
I am running this using the Flutter plugin in IntelliJ on a Android (Samsung Galaxy Grand Prime, Android 5.1).
How could I solve this problem ?
EDIT: As seen on this answer (Android - SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length), I have tried switching keyboard (Google and Samsung), stille the same
I think the full error might be somewhere else. I would suggest opening a new flutter issue if the issue is specific to one android device.
The fix for me was to add autocorrect: false
, and set keyboardType: TextInputType.visiblePassword
the bug occurred on my s8plus, it didn't happen on my iPhone simulator.
return TextFormField(
controller: emailController,
autofocus: true,
autocorrect: false,
keyboardType: TextInputType.visiblePassword,
validator: validateEmailOrPhoneNumber,
onChanged: (text) {
this._validateEmailORPhoneNumber(text);
this._onTouched('emailOrPhoneNumber');
},
onTap: () => _onTouched('emailOrPhoneNumber'),
decoration: InputDecoration(
prefixIcon: isPhoneNumber
? Container(
width: 70,
child: leftSection,
)
: null,
labelText: 'Email or Phone number',
hintText: 'Enter Email or Phone number'),
);
I had the same error. In my case, the problem wasn't the TextFormField
. It was because of the key inside the Form
widget. If you use a key, the general widget must be StatefulWidget
, not StatelessWidget
.
class MyWidget extends StatelessWidget{
final GlobalKey<FormState> _formKey = GlobalKey<FormState>();
@override
Widget build(BuildContext context) {
// TODO: implement build
return Scaffold(
body: Form(
key: _formKey,
child: TextFormField(),
),
);
}
}
class MyWidget extends StatefulWidget{
@override
State<StatefulWidget> createState() {
// TODO: implement createState
return _MyWidgetState();
}
}
class _MyWidgetState extends State<MyWidget>{
final GlobalKey<FormState> _formKey = GlobalKey<FormState>();
@override
Widget build(BuildContext context) {
// TODO: implement build
return Scaffold(
body: Form(
key: _formKey,
child: TextFormField(),
),
);
}
}
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