【发布时间】:2021-06-09 10:10:54
【问题描述】:
在我的项目中,我想将文本字段中的文本输入添加到列表中以构建 Listview.builder。 问题是我不知道如何将字符串添加到列表中(我想像在待办事项应用程序中一样使用字符串来制作服务日期)。 (例如) time.add(time1) 不起作用,我希望有人可以帮助我。 有没有其他方法可以将 Inputtext 传输到列表中,我对所有内容都开放
首页
class Homescreen extends StatefulWidget {
String time1;
String who1;
String where1;
String when1;
Homescreen({this.time1, this.who1, this.where1, this.when1});
@override
_HomescreenState createState() => _HomescreenState();
}
TextEditingController myControllertime = TextEditingController();
TextEditingController myControllerwho = TextEditingController();
TextEditingController myControllerwhen = TextEditingController();
TextEditingController myControllerwhere = TextEditingController();
class _HomescreenState extends State<Homescreen> {
List<String> time = ["8:00",];
List<String> who = ["Eric", ];
List<String> when = ["Friday 21.4.21",];
List<String> where = ["At McDonalds", ];
ListView.builder(
physics: NeverScrollableScrollPhysics(),
shrinkWrap: true,
itemCount: where.length,
itemBuilder: (BuildContext context, int Index) {
return Column(children: [
SizedBox(
height: 40,
),
Container(
child: GestureDetector(
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => Meet1()));
},
child: Container(
width: size.width * 0.9,
decoration: BoxDecoration(
borderRadius: BorderRadius.all(
Radius.circular(70)),
gradient: LinearGradient(
begin: Alignment.topRight,
end: Alignment.bottomRight,
colors: [
Colors.orange,
Colors.purple,
],
),
),
child: Column(children: <Widget>[
SizedBox(
height: 10,
),
Padding(
padding: EdgeInsets.all(20),
child: Column(
children: <Widget>[
Text(
time[Index],
style: TextStyle(
color: Colors.white,
fontSize: 40,
fontWeight:
FontWeight.bold),
),
SizedBox(
height: 10,
),
Text(
who[Index],
style: TextStyle(
color: Colors.white,
fontSize: 20,
fontWeight:
FontWeight.bold),
),
Text(
when[Index],
style: TextStyle(
color: Colors.white,
fontSize: 20,
fontWeight:
FontWeight.bold),
),
Text(
where[Index],
style: TextStyle(
color: Colors.white,
fontSize: 20,
fontWeight:
FontWeight.bold),
),
第二页
TextButton(
child: Icon(
Icons.check_circle_outline_rounded,
color: Colors.green,
size: 120,
),
onPressed: () {
Navigator.pop(context, MaterialPageRoute(builder: (builder) {
return Homescreen(
time1: myControllertime.text,
who1: myControllerwho.text,
when1: myControllerwhen.text,
where1: myControllerwhere.text
,
);
}));
})
],
));
child: Column(children: <Widget>[
SizedBox(
height: 10,
),
Padding(
padding: EdgeInsets.all(25),
child: Column(
children: <Widget>[
TextField(
controller: myControllertime,
decoration: InputDecoration(hintText: " Time ")),
SizedBox(
height: 10,
),
TextField(
controller: myControllerwho,
decoration: InputDecoration(hintText: " Who "),
),
SizedBox(
height: 10,
),
TextField(
controller: myControllerwhen,
decoration: InputDecoration(hintText: " Date "),
),
SizedBox(
height: 10,
),
TextField(
controller: myControllerwhere,
decoration: InputDecoration(hintText: " Where "),
),
【问题讨论】:
-
//void main() { String m = "map";列表 mx = ["map1","2","3"]; mx.add(m);打印(MX); } // 这是一个将字符串添加到列表的坏例子,但为什么我要评论这个呢?这样可以完成工作,您也可以将其用于您的工作,但这不是正确的方法。