Skip to content

dart format#50

Merged
bdlukaa merged 1 commit into
bdlukaa:masterfrom
kjeremy:formatting
May 26, 2026
Merged

dart format#50
bdlukaa merged 1 commit into
bdlukaa:masterfrom
kjeremy:formatting

Conversation

@kjeremy
Copy link
Copy Markdown
Contributor

@kjeremy kjeremy commented May 21, 2026

No description provided.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request primarily focuses on code reformatting and indentation adjustments across the example application, core library, and test files. A review comment identifies a logic issue in the example app's UI where using indexOf to retrieve color labels can lead to incorrect results if multiple color shades have identical values. The reviewer also noted variable shadowing and provided a code suggestion to use asMap().entries to ensure reliable indexing and cleaner scope management.

Comment on lines +43 to +68
...colors.map((color) {
return Expanded(
child: Container(
color: color,
alignment: Alignment.center,
child: Text(
[
'Lightest',
'Lighter',
'Light',
'Default',
'Dark',
'Darker',
'Darkest',
][colors.indexOf(color)] +
'\n${color.toHex()}',
style: Theme.of(context).textTheme.titleLarge?.copyWith(
color: color.computeLuminance() >= 0.5
? Colors.black
: Colors.white,
),
textAlign: TextAlign.center,
),
),
);
}).toList(),
]),
),
);
});
textAlign: TextAlign.center,
),
),
);
}).toList(),
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The current implementation uses indexOf to determine the label for each color. This logic is flawed because if multiple shades have the same color value (which occurs when the platform doesn't provide specific variants and autoAdjustLightness is disabled or results in the same color), indexOf will always return the index of the first occurrence, leading to incorrect labels in the UI. Additionally, the variable name color in the map function shadows the color variable from the SystemThemeBuilder scope. Using asMap().entries allows for a reliable index and avoids shadowing.

                ...colors.asMap().entries.map((entry) {
                  final index = entry.key;
                  final itemColor = entry.value;
                  return Expanded(
                    child: Container(
                      color: itemColor,
                      alignment: Alignment.center,
                      child: Text(
                        [
                              'Lightest',
                              'Lighter',
                              'Light',
                              'Default',
                              'Dark',
                              'Darker',
                              'Darkest',
                            ][index] +
                            '\n${itemColor.toHex()}',
                        style: Theme.of(context).textTheme.titleLarge?.copyWith(
                          color: itemColor.computeLuminance() >= 0.5
                              ? Colors.black
                              : Colors.white,
                        ),
                        textAlign: TextAlign.center,
                      ),
                    ),
                  );
                }).toList(),

@bdlukaa bdlukaa merged commit d73982f into bdlukaa:master May 26, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants