简体   繁体   English

我想在 flutter 中创建用户配置文件列表?

[英]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.

相关问题 我想用 flutter 创建一个可以排序的列表 - I want to use flutter to create a list that can be sorted 我想在 flutter/dart 中创建带有下拉列表的多个过滤器列表 - I want to create multiple filter list with dropdown in flutter/dart 我想在 flutter 中创建一个聊天应用程序 - I want to create a chatapp in flutter 我想在 flutter 中创建一个自定义 DropdownButton,它可以与不同的列表一起重复使用 [Flutter] - I want to create a custom DropdownButton in flutter which can be reusable with different List [Flutter] 使用Bloc,RxDart和Flutter创建用户个人资料页面 - Create user profile page using Bloc, RxDart and Flutter 如何从 Flutter 中的列表移动到特定用户配置文件屏幕 - How to move to Specific user profile screen from a list in Flutter 我想在 flutter 中创建一个带有 firebase 的列表视图,它将显示标题副标题和图像,并且当用户单击将打开 web 视图的列表视图时 - i want to create a listview with firebase in flutter that will show title subtitle and image and when user click on listview that will open a webview 我想验证 flutter 中的用户输入 - I want to validate the user input in flutter 我想用listview创建一个颤动的应用程序 - I want to create a flutter app with a listview 我想在 Flutter 上创建这样的应用栏 - i want to create like this app bar on Flutter
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM