[英]i want to create a list of user profile in flutter?
I am new to the flutter and for practice purposes, I am creating a blood donation app, in my app, I have added a registration form for donor registration, now when a recipient comes for blood needs, they fill out the form for specific blood group accordingly recipient could see a list of donors with profile, name, city, and country.我是 flutter 的新手,出于练习目的,我正在创建一个献血应用程序,在我的应用程序中,我添加了一个用于捐赠者登记的注册表,现在当接受者需要血液时,他们会填写特定血液的表格相应地,收件人可以看到带有个人资料、姓名、城市和国家/地区的捐助者列表。 Now I need help in creating this page that shows all the registered donors on the list.
现在我需要帮助来创建这个显示列表中所有注册捐助者的页面。
Firstly you need to make the data model where you can add specific data.首先,您需要创建数据 model,您可以在其中添加特定数据。 Make form where user fills the data and afterwards put that data into model. Add those models into list and then map into listView.
在用户填写数据的地方制作表格,然后将该数据放入 model。将这些模型添加到列表中,然后将 map 放入 listView。
Model: Model:
class BloodDonor {
final String profile;
final String name;
final String city;
final String country;
BloodDonor({
required this.city,
required this.country,
required this.name,
required this.profile,
});
}
Screen:屏幕:
class GetDonorDetailScreen extends StatefulWidget {
@override
State<GetDonorDetailScreen> createState() => _GetDonorDetailScreenState();
}
class _GetDonorDetailScreenState extends State<GetDonorDetailScreen> {
final GlobalKey<FormState> formKey = GlobalKey<FormState>();
BloodDonor bloodDonor = BloodDonor();
List<BloodDonor> donors = [];
@override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: Form(
key: formKey,
child: Padding(
padding: EdgeInsets.symmetric(horizontal: 10, vertical: 5),
child: Column(
children: [
TextFormField(
decoration: InputDecoration(
hintText: 'Enter profile',
),
validator: (valueEntered) {
return valueEntered!.isEmpty ? "Please fill here" : null;
},
onSaved: (value) {
bloodDonor.profile = value!;
},
),
SizedBox(height: 10),
TextFormField(
decoration: InputDecoration(
hintText: 'Enter Name',
),
validator: (valueEntered) {
return valueEntered!.isEmpty ? "Please fill here" : null;
},
onSaved: (value) {
bloodDonor.name = value!;
},
),
SizedBox(height: 10),
TextFormField(
decoration: InputDecoration(
hintText: 'Enter City',
),
validator: (valueEntered) {
return valueEntered!.isEmpty ? "Please fill here" : null;
},
onSaved: (value) {
bloodDonor.city = value!;
},
),
SizedBox(height: 10),
TextFormField(
decoration: InputDecoration(
hintText: 'Enter Country',
),
validator: (valueEntered) {
return valueEntered!.isEmpty ? "Please fill here" : null;
},
onSaved: (value) {
bloodDonor.country = value!;
},
),
SizedBox(height: 10),
Center(
child: ElevatedButton(
child: Text("Add"),
onPressed: () {
if (formKey.currentState!.validate()) {
formKey.currentState!.save();
setState(() {
donors.add(bloodDonor);
bloodDonor = BloodDonor();
formKey.currentState?.reset();
});
}
},
),
),
SizedBox(height: 10),
Expanded(
child: ListView(
children: [
for (final donor in donors)
ListTile(
title: Text(donor.name),
subtitle: Text(
"${donor.city}, ${donor.country} - ${donor.profile}"),
),
],
),
),
],
),
),
),
),
);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.