I do not see a blinking cursor if I enable and focus a previous disabled TextFormField. In this example, the TextFormField is originally disabled, as indicated by the _enabled
state variable, and when you click on the enable button, the field is enabled and focused but the blinking cursor is not visible. I have to click on the TextFormField in order to see the blinking cursor.
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key}) : super(key: key);
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
bool _enabled = false;
FocusNode focusNodeA = FocusNode();
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Test'),
),
body: TextFormField(
enabled: _enabled,
focusNode: focusNodeA,
),
floatingActionButton: FloatingActionButton(
onPressed: () {
setState(() => _enabled = true);
FocusScope.of(context).requestFocus(focusNodeA);
},
child: Text('Enable'),
),
);
}
}
If I press 'Enable' twice, the cursor is shown.
If the TextFormField was already enabled and then focused, the blinking cursor is visible.