在flutter中提交后如何获取复选框的自动增减值

时间:2019-11-30 07:11:03

标签: flutter checkbox

您好,我想在提交复选框后在页面顶部显示复选框值。enter image description here

如果我们选中2个复选框并提交,则其中1个复选框的黄金值为2。

new CheckboxListTile(                   标题:文本(键),                   值:值[键],                   activeColor:Colors.teal,                   checkColor:Colors.white,                   onChanged :(布尔值){                     setState((){                       values [key] = value;

                  if(value) {
                    _incrementCounter(2);
                  } else {
                    _incrementCounter(-2);
                  }


                });
              },
            );
          }).toList(),

  _incrementCounter(int gold_value) async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    int counter = (prefs.getInt('score') ?? 0) + gold_value;
    print('currenct score $counter ');
    await prefs.setInt('score', counter);
  }

0 个答案:

没有答案