当我单击TextField时,整个小部件会重新加载,这是一个问题。 我不希望这种情况发生。 尝试了许多方法,但无法解决。我正在Android设备上运行该应用。
class Testextends StatefulWidget {
@override
_TestState createState() => _TestState();
}
class _TestState extends State<Test> {
final _search = TextEditingController();
static final GlobalKey<ScaffoldState> _scaffoldKey = new GlobalKey<ScaffoldState>();
@override
Widget build(BuildContext context) {
return Scaffold(
key: _scaffoldKey,
appBar: AppBar(
title: Container(
height: 45,
width: MediaQuery.of(context).size.width * 0.9,
child: Row(
children: <Widget>[
Expanded(
child: TextField(
decoration: InputDecoration(
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.all(
Radius.circular(30.0),
),
borderSide: BorderSide(color: Colors.grey[400]),
),
border: OutlineInputBorder(
borderRadius: BorderRadius.all(
Radius.circular(30.0),
),
),
labelStyle: TextStyle(color: Colors.grey[400], fontSize: 15),
labelText: 'Search...',
),
controller: _search,
onSubmitted: (_) => search(),
),
),
],
),
),
),
body: Text('Test Body'),
);
}
}
谁能告诉我为什么会这样?