lundi 26 août 2019

What is the best way to design and manage/save state for a widget with many checkboxes?

I'm creating a Flutter app to store progress for board game characters, I want to allow a user to check up to 18 checkboxes, where the checkboxes are grouped in threes:

https://imgur.com/a/jOiQfrX for a picture, as I can't embed it.

My first approach was to code this widget such that I have as little code reused as possible.

CheckboxGroup is a Row widget with a checkmark icon, ":", and three checkboxes as children. CheckboxGridRow is a Row widget with two CheckboxGroups as children. CheckboxGrid is a Column widget with three CheckboxGridRows as children.

-> CheckboxGrid
  -> CheckboxGridRow
    -> CheckboxGroup
    -> CheckboxGroup
  -> CheckboxGridRow
    -> CheckboxGroup
    -> CheckboxGroup
  -> CheckboxGridRow
    -> CheckboxGroup
    -> CheckboxGroup

This works fine for UI purposes, but I'm struggling to wrap my head around how to manage/store state for it. I expect that I will use a List<bool> to store true/false for state, but where should the state change and database logic be for this setup?




Aucun commentaire:

Enregistrer un commentaire