Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AutoSizeText with checkboxes #101

Closed
flipflop133 opened this issue Nov 6, 2021 · 1 comment
Closed

AutoSizeText with checkboxes #101

flipflop133 opened this issue Nov 6, 2021 · 1 comment
Assignees
Labels
question Further information is requested

Comments

@flipflop133
Copy link

Question
How to avoid AutoSizeText trying to resize itself when tapping on a checkbox that is placed in the same row.

Code sample

// Create days boxes widgets
List<Widget> createDaysBoxes() {
   AutoSizeGroup textGroup =
        AutoSizeGroup(); // Keep consistent font size for all days
    List<Widget> daysBoxes = [];
    data.checkedDays.forEach(
      (day, isChecked) {
        daysBoxes.add(
          Expanded(
            child: Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                Expanded(
                  flex: 3,
                  child: Padding(
                    padding: const EdgeInsets.fromLTRB(10, 5, 0, 5),
                    child: AutoSizeText(
                      getDayString(day),
                      group: textGroup,
                      style: const TextStyle(fontSize: 40),
                    ),
                  ),
                ),
                Expanded(
                  child:Checkbox(
                      checkColor: Colors.white,
                      value: data.checkedDays[day]![1],
                      onChanged: (bool? value) {
                        setState(() {
                          data.checkedDays[day]![1] = value!;
                        });
                      },
                    ),
                ),
              ],
            ),
          ),
        );
      },
    );
    return daysBoxes;
  }

Screenshot
image
-> in this screenshot, "Monday" and "Tuesday" are trying to automatically resize their fontsize each time I tap on a checkbox.

Version

  • Flutter version: 2.5.3
  • auto_size_text version: 3.0.0
@flipflop133 flipflop133 added the question Further information is requested label Nov 6, 2021
@flipflop133
Copy link
Author

So the fix is simply to put the AutoSizeText days in a stateless widget so the text is only calculated on the page launch and not during interaction.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants