0

For example is the user clicks a checkbox, how can I tell if the user was holding SHIFT, CTRL or any other key pressed ?

Checkbox(
    value: checked,
    onChanged: (value) {
        setState(() {
            // do something
        });
    },
),
D. Joe
  • 573
  • 1
  • 9
  • 17

1 Answers1

0

In your StateFull widget do something like bellow snippet

bool _isChecked = false;

  @override
  Widget build(BuildContext context) {
    return Column(
      children: [
        Checkbox(
          value: _isChecked,
          onChanged: (value) {
            setState(() {
              _isChecked = value;
            });
          },
        ),
        ElevatedButton(
          child: Text('Button'),
          onPressed: (){
            if(_isChecked){
              print('CHeckbox is checked');
            }else{
              print('CHeckbox is not checked');
            }
          },
        ),
      ],
    );
  }
Saiful Islam
  • 1,151
  • 13
  • 22
  • This can be done is stateless widget also, as we are not reflecting the changes in other widgets. it just assigning the values to global variable. – Jitesh Mohite Mar 07 '21 at 06:11
  • give an example then? I think as a beginner thats the right way. – Saiful Islam Mar 07 '21 at 10:05
  • 1
    You misunderstood the question. When the user clicks the checkbox, I want to know if the SHIFT key is pressed or not. Not if the checkbox is checked when the user presses another button. – D. Joe Mar 07 '21 at 13:57