我是Flutter的新手,我编写了两个页面,分别是页面A和页面B。我使用ReorderableListView在小部件B中显示文本字段的列表。当我从页面A导航到页面B时,文本字段立即失去焦点我点击文本框。有人可以帮忙吗?
void main() => runApp(MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: TapClass(),
));
class TapClass extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: FlatButton(
child: Text('click me'),
onPressed: () {
Navigator.of(context)
.push(MaterialPageRoute(builder: (context) => MyHomePage()));
},
),
));
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key}) : super(key: key);
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
body: ReorderableListView(
children: <Widget>[
Row(
key: ValueKey('key'),
children: <Widget>[
Expanded(
child: TextField(
decoration: InputDecoration(hintText: 'type in'),
),
)
],
)
],
onReorder: (int oldIndex, int newIndex) {},
));
}
}
答案 0 :(得分:0)
因为ReorderaleListView中只有一个孩子。您应该有一个以上的孩子,并为他们分配不同的密钥。希望对您有帮助。