lundi 12 décembre 2022

i want to select multiple items

this is my code 


class HighestEducation extends StatefulWidget {
  const HighestEducation({Key? key}) : super(key: key);

  @override
  State<HighestEducation> createState() => _HighestEducationState();
}

class _HighestEducationState extends State<HighestEducation> {
  int selectedPosition = -1;
  late Future<List<Region>> qualification;

  Region? selEdu;
  TextEditingController highestEducation = TextEditingController();

  NetWorkOperations ntop = NetWorkOperations();
  var education = [];
  final List<Region> _selEdu = [];
//List<bool> _checkBoxValues = [];
//bool x = false;

  @override
  void initState() {
    super.initState();

    qualification = ntop.getDropDownList(0, 5);
  }

  @override
  Widget build(BuildContext context) {
    return ListView(
        shrinkWrap: true,
        scrollDirection: Axis.vertical,
        physics: const BouncingScrollPhysics(),
        children: [
          const AppText(
              text: 'HighestEducation', fontSize: 18, color: profileConnect1),
          12.hBox,
          Padding(
              padding: const EdgeInsets.symmetric(horizontal: 20),
              child: FutureBuilder<List<Region>>(
                  future: qualification,
                  builder: (context, snapshot) {
                    if (snapshot.hasData) {
                      int length = snapshot.data!.length;

                      for (int i = 0; i < length; i++) {
                        Region edu = snapshot.data![i];
                        education.add(edu.value);
                      }
                   
                    return AppTextField(
                          suffixIcon: inputArrowDownIcon,
                          hint: 'M.Com',
                          controller: highestEducation,
                          enabledBorder: true,
                          suffixColor: captionInterest,
                          onTap: () => showOptionPicker(context,
                                  itemBuilder: (_, int index) {
                                if (education.length > 0) {
                                  return Padding(
                                    padding: const EdgeInsets.symmetric(
                                        horizontal: 20.0),
                                    child: Center(
                                        child: AppText(
                                            fontSize: 15,
                                            text: education[index])),

                                      );
                                } else {
                                  return const Center(
                                    child: CircularProgressIndicator(),
                                  );
                                }
                              }, onDonePressed: (int selectedIndex) {
                                setState(() {
                                  highestEducation.text =
                                      education[selectedIndex];
                                });
                              }, itemCount: education.length));
                    } else if (snapshot.hasError) {
                      return Text('${snapshot.error}');
                    }
                    return const Center(
                      child: CircularProgressIndicator(),
                    );
                  }))
        ]);
  }
}

i am new to flutter and i dont know how to implement multiselection in my code using checkbox,here i am using an api to get data and i name it as "education" and i access the educationlevels from this api, i have to keep future builder and the logic what i used in my code, here i am using apptextfield as a customizes textfield , please help me to solve my issue,




Aucun commentaire:

Enregistrer un commentaire