lundi 1 juin 2020

How can i manipulate checkbox selection?

import 'package:flutter/material.dart';
import 'package:linq_pay_app/src/CarBikeInsurance/widgets/LSLayout.dart';
import 'package:linq_pay_app/src/CarBikeInsurance/widgets/fields/LSTextField.dart';
import 'package:grouped_buttons/grouped_buttons.dart';

class HealthInsurance extends StatefulWidget {
  @override
  _HealthInsuranceState createState() => _HealthInsuranceState();
}

class _HealthInsuranceState extends State<HealthInsurance> {

  List<String> selectedMembers;

  Widget Page1(){
    return Container(
      child: Padding(
        padding: const EdgeInsets.all(8.0),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: <Widget>[
            Text("Residence Pincode",style: TextStyle(fontWeight: FontWeight.bold),),
            SizedBox(height: 10.0,),
            LSTextField(label: "Enter Pincode",),
          ],
        ),
      ),
    );
  }

  Widget Page2(){
    return ListView(
        children: <Widget>[

          Container(
            padding: const EdgeInsets.only(left: 14.0, top: 14.0),
            child: Text("Add the members you want to insure:",
              style: TextStyle(
              fontWeight: FontWeight.bold,
              fontSize: 20.0
              ),
            ),
          ),

        CheckboxGroup(
          labels: <String>[
          "Self",
          "Spouse",
          "Son",
          "Daughter",
          "Mother",
          "Father",
          "Mother-in-law",
          "Father-in-law",
          ],

        onChange: (bool isChecked, String label, int index) => print("isChecked: $isChecked   label: $label  index: $index"),
        onSelected: (List<String> checked) => selectedMembers=checked,
        ),
      ]
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        iconTheme: IconThemeData(
          color: Colors.black,
        ),
        title: Text("Back"),
        centerTitle: false,
      ),
      body: Page2()
    );
  }
}

There are 2 issues: 1. If the user selects Son or daughter, he should get an option ahead of son field to add or subtract the number of son or daughter and can keep a track of how many son or daughter he has selected.

  1. If the user selects his parents, he cannot select his mother-in-law and father-in-law and vice versa.



Aucun commentaire:

Enregistrer un commentaire