在textFormField中显示其他页面中的选定文本


final TextEditingController _musteri = TextEditingController();
TextFormField(
controller: _musteri,
onTap: () => Navigator.push(
context,
MaterialPageRoute<void>(
builder: (BuildContext context) => const MusteriList(),
),
),
textAlign: TextAlign.center,
decoration: InputDecoration(
labelText: 'Müşteri',
labelStyle: TextStyle(
fontFamily: 'Montserrat',
color: Color.fromARGB(255, 139, 158, 131)),
prefixIcon: Icon(
Icons.person_outline,
color: Color.fromARGB(255, 180, 147, 133),
),
),
),

这是我创建的TextFormField。

List<Map<String, dynamic>> _foundUsers = [];
@override
initState() {
_foundUsers = _allUsers;
super.initState();
}
ListView.builder(
itemCount: _foundUsers.length,
itemBuilder: (context, index) => GestureDetector(
onTap: () => Navigator.push(
context,
MaterialPageRoute<void>(
builder: (BuildContext context) => const SatisIcmali(),
),
),
child: Card(
key: ValueKey(_foundUsers[index]["id"]),
color: Colors.blueAccent,
elevation: 4,
margin: EdgeInsets.symmetric(vertical: 10, horizontal: 15),
child: ListTile(
leading: Text(
_foundUsers[index]["id"].toString(),
style: TextStyle(fontSize: 24, color: Colors.white),
),
title: Text(
_foundUsers[index]["name"],
style: TextStyle(fontSize: 14, color: Colors.white),
),
),
),
),
),

这是一个在单击TextFormField时显示给用户的列表。

我想在我创建的列表中,在第一个代码的textFormField中显示我为["name"]定义的文本。点击卡片将转到上一页,点击卡片中的["名称"]数据将显示在那里。

将foundUsers[index]["name"]传递到导航中,您可以在TextFormField页面上获取并在该页面上进行设置。

Navigator.push(
context,
MaterialPageRoute<void>(
builder: (BuildContext context) => const SatisIcmali(foundUsers[index]["name"]),
),
)

请检查以供参考https://docs.flutter.dev/cookbook/navigation/passing-data

您可以使用上下文提供程序作为RiverPod或GetX,可以从不同的页面访问。

否则,您必须使用TextFormField onChanged(newValue(=>的newValue填充_foundUsers;setState(((=&gt_yourProp=newValue(。

希望一切顺利!

最新更新