dimanche 28 février 2021

Store multiple Checkbox values in Firestore in Flutter

I develop an applicaion for elderly, when they sing up, the app requires from them to select which chronic disease they have from multiple Checkbox that in DropDown. then I want to store these multiple choices in Cloud Firestore, I need to know how to stroe it? my code is:

import 'package:flutter/material.dart';
import 'Constants.dart';
import 'checkBox.dart';
class ChronicDiseaseDropDown extends StatelessWidget {
  Color borderColor;
  Color hintColor;
  Color iconColor;
  ChronicDiseaseDropDown({
    this.borderColor = white,
    this.hintColor = white,
    this.iconColor = white,
  });
  @override

  //List<Map<String, String>> chronicDisease= [{'id':'1', 'disease':'أمراض القلب'},];

  final chronicDiseaseList = const [
    {'id': 1, 'disease': 'أمراض القلب'},
    {'id': 2, 'disease': 'أمراض السكري'},
    {'id': 3, 'disease': 'أمراض الجهاز التنفسي'},
    {'id': 4, 'disease': 'أمراض السرطان'},
    {'id': 5, 'disease': 'أمراض ارتفاع ضغط الدم'},
  ];

  bool isHeartDisease = false;
  bool isDiabetes = false;
  bool isRespiratorySystemDisease = false;
  bool isCancer = false;
  bool isHighBloodDisease = false;



  String dropdownValue = 'First';
  @override
  Widget build(BuildContext context) {
    return SizedBox(
      height: 50,
      width: 350,
      child: DropdownButtonFormField(
        iconSize: 50,
        iconEnabledColor: iconColor,
        decoration: InputDecoration(
          hintText: 'الأمراض المزمنة',
          hintStyle: TextStyle(
              fontSize: 23, fontWeight: FontWeight.bold, color: hintColor),
          enabledBorder: OutlineInputBorder(
            borderSide: BorderSide(
              color: borderColor,
            ),
            borderRadius: BorderRadius.circular(30.0),
          ),
        ),
        items: [
          DropdownMenuItem(
            child: Row(
              children: <Widget>[
                CheckboxSelectorPage(isHeartDisease),
                Text(
                  chronicDiseaseList[0]['disease'],
                  style: textStyle1,
                ),
              ],
            ),
          ),
          DropdownMenuItem(
            child: Row(
              children: <Widget>[
                CheckboxSelectorPage(isDiabetes),
                Text(
                  chronicDiseaseList[1]['disease'],
                  style: textStyle1,
                ),
              ],
            ),
          ),
          DropdownMenuItem(
            child: Row(
              children: <Widget>[
                CheckboxSelectorPage(isRespiratorySystemDisease),
                Text(
                  chronicDiseaseList[2]['disease'],
                  style: textStyle1,
                ),
              ],
            ),
          ),
          DropdownMenuItem(
            child: Row(
              children: <Widget>[
                CheckboxSelectorPage(isCancer),
                Text(
                  chronicDiseaseList[3]['disease'],
                  style: textStyle1,
                ),
              ],
            ),
          ),
          DropdownMenuItem(
            child: Row(
              children: <Widget>[
                CheckboxSelectorPage(isHighBloodDisease),
                Text(
                  chronicDiseaseList[4]['disease'],
                  style: textStyle1,
                ),
              ],
            ),
          )
        ].toList(),
        onChanged: (value) {},
      ),
    );
  }
}

I want to store checkbox values in field ChronicDisease: enter image description here




Aucun commentaire:

Enregistrer un commentaire