Skip to content

[Material Cross Imports] Clean up Material Divider usages#187300

Open
navaronbracke wants to merge 2 commits into
flutter:masterfrom
navaronbracke:cleanup_divider_usages
Open

[Material Cross Imports] Clean up Material Divider usages#187300
navaronbracke wants to merge 2 commits into
flutter:masterfrom
navaronbracke:cleanup_divider_usages

Conversation

@navaronbracke
Copy link
Copy Markdown
Contributor

This PR cleans up usages of the Material Divider in areas where it was used for convenience. (i.e. examples/api which didn't have anything to do with examples/api/material)

This was left over from when we discussed it specifically for tests that used it.

See #177415
Fixes #180501

For the desktop reviewers: There is a replacement of Divider in the multiple windows example, although the test for it does not assert on finding the divider.

If you had to change anything in the flutter/tests repo, include a link to the migration guide as per the breaking change policy.

Pre-launch Checklist

If you need help, consider asking for advice on the #hackers-new channel on Discord.

If this change needs to override an active code freeze, provide a comment explaining why. The code freeze workflow can be overridden by code reviewers. See pinned issues for any active code freezes with guidance.

Note: The Flutter team is currently trialing the use of Gemini Code Assist for GitHub. Comments from the gemini-code-assist bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.

@flutter-dashboard flutter-dashboard Bot added the CICD Run CI/CD label May 29, 2026
@github-actions github-actions Bot added a: tests "flutter test", flutter_test, or one of our tests a: text input Entering text in a text field or keyboard related problems framework flutter/packages/flutter repository. See also f: labels. f: scrolling Viewports, list views, slivers, etc. d: api docs Issues with https://api.flutter.dev/ d: examples Sample code and demos c: tech-debt Technical debt, code quality, testing, etc. labels May 29, 2026
Copy link
Copy Markdown
Contributor

@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 replaces the Divider widget with custom divider implementations using Container across various examples, tests, and documentation, and updates some imports from material.dart to widgets.dart. The review feedback recommends optimizing these custom dividers by replacing Container with a combination of SizedBox and ColoredBox inside a const Padding to enable compile-time evaluation and improve performance. Additionally, it is suggested to instantiate ExampleWidget with const where applicable.

return const MaterialApp(home: ExampleWidget());
return WidgetsApp(
color: const Color(0xFFFFFFFF),
home: ExampleWidget(),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Since ExampleWidget has a const constructor, it should be instantiated with const here to avoid unnecessary rebuilds and improve performance.

Suggested change
home: ExampleWidget(),
home: const ExampleWidget(),

Comment on lines +55 to +64
Widget buildDivider() {
return Padding(
padding: const EdgeInsets.all(4),
child: Container(
color: const Color(0xFF000000),
height: 4,
width: double.infinity,
),
);
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Using Container with only color, height, and width is less efficient than using a combination of SizedBox and ColoredBox. Additionally, Container does not have a const constructor, which prevents the entire helper method's returned widget tree from being evaluated at compile time. Refactoring this to use const Padding with SizedBox and ColoredBox improves performance and allows the widget tree to be const.

Suggested change
Widget buildDivider() {
return Padding(
padding: const EdgeInsets.all(4),
child: Container(
color: const Color(0xFF000000),
height: 4,
width: double.infinity,
),
);
}
Widget buildDivider() {
return const Padding(
padding: EdgeInsets.all(4),
child: SizedBox(
height: 4,
width: double.infinity,
child: ColoredBox(
color: Color(0xFF000000),
),
),
);
}
References
  1. The style guide suggests assessing whether the code can be made simpler or refactored to enhance readability and maintainability. (link)

Comment on lines +76 to +83
separatorBuilder: (_, _) => Padding(
padding: const EdgeInsets.all(4),
child: Container(
color: const Color(0xFF000000),
height: 4,
width: double.infinity,
),
),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Using Container with only color, height, and width is less efficient than using a combination of SizedBox and ColoredBox. Additionally, Container does not have a const constructor, which prevents the returned widget tree from being evaluated at compile time. Refactoring this to use const Padding with SizedBox and ColoredBox improves performance and allows the widget tree to be const.

Suggested change
separatorBuilder: (_, _) => Padding(
padding: const EdgeInsets.all(4),
child: Container(
color: const Color(0xFF000000),
height: 4,
width: double.infinity,
),
),
separatorBuilder: (_, _) => const Padding(
padding: EdgeInsets.all(4),
child: SizedBox(
height: 4,
width: double.infinity,
child: ColoredBox(
color: Color(0xFF000000),
),
),
),
References
  1. The style guide suggests assessing whether the code can be made simpler or refactored to enhance readability and maintainability. (link)

Comment on lines +18 to +27
Widget buildDivider() {
return Padding(
padding: const EdgeInsets.all(4),
child: Container(
color: const Color(0xFF000000),
height: 4,
width: double.infinity,
),
);
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Using Container with only color, height, and width is less efficient than using a combination of SizedBox and ColoredBox. Additionally, Container does not have a const constructor, which prevents the entire helper method's returned widget tree from being evaluated at compile time. Refactoring this to use const Padding with SizedBox and ColoredBox improves performance and allows the widget tree to be const.

Suggested change
Widget buildDivider() {
return Padding(
padding: const EdgeInsets.all(4),
child: Container(
color: const Color(0xFF000000),
height: 4,
width: double.infinity,
),
);
}
Widget buildDivider() {
return const Padding(
padding: EdgeInsets.all(4),
child: SizedBox(
height: 4,
width: double.infinity,
child: ColoredBox(
color: Color(0xFF000000),
),
),
);
}
References
  1. The style guide suggests assessing whether the code can be made simpler or refactored to enhance readability and maintainability. (link)

void main() {
testWidgets('shows font features', (WidgetTester tester) async {
await tester.pumpWidget(const MaterialApp(home: example.ExampleWidget()));
await tester.pumpWidget(example.ExampleWidget());
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Since ExampleWidget has a const constructor, it should be instantiated with const here to avoid unnecessary rebuilds and improve performance.

Suggested change
await tester.pumpWidget(example.ExampleWidget());
await tester.pumpWidget(const example.ExampleWidget());

Comment on lines +362 to +367
Widget _buildDivider() {
return Padding(
padding: const EdgeInsets.all(4),
child: Container(color: const Color(0xFF000000), height: 4, width: double.infinity),
);
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Using Container with only color, height, and width is less efficient than using a combination of SizedBox and ColoredBox. Additionally, Container does not have a const constructor, which prevents the entire helper method's returned widget tree from being evaluated at compile time. Refactoring this to use const Padding with SizedBox and ColoredBox improves performance and allows the widget tree to be const.

  Widget _buildDivider() {
    return const Padding(
      padding: EdgeInsets.all(4),
      child: SizedBox(
        height: 4,
        width: double.infinity,
        child: ColoredBox(color: Color(0xFF000000)),
      ),
    );
  }
References
  1. The style guide suggests assessing whether the code can be made simpler or refactored to enhance readability and maintainability. (link)

Comment on lines +582 to +589
Padding(
padding: const EdgeInsets.all(4),
child: Container(
color: const Color(0xFF000000),
height: 5,
width: double.infinity,
),
),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Using Container with only color, height, and width is less efficient than using a combination of SizedBox and ColoredBox. Additionally, Container does not have a const constructor, which prevents the returned widget tree from being evaluated at compile time. Refactoring this to use const Padding with SizedBox and ColoredBox improves performance and allows the widget tree to be const.

Suggested change
Padding(
padding: const EdgeInsets.all(4),
child: Container(
color: const Color(0xFF000000),
height: 5,
width: double.infinity,
),
),
const Padding(
padding: EdgeInsets.all(4),
child: SizedBox(
height: 5,
width: double.infinity,
child: ColoredBox(color: Color(0xFF000000)),
),
),
References
  1. The style guide suggests assessing whether the code can be made simpler or refactored to enhance readability and maintainability. (link)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

a: tests "flutter test", flutter_test, or one of our tests a: text input Entering text in a text field or keyboard related problems c: tech-debt Technical debt, code quality, testing, etc. CICD Run CI/CD d: api docs Issues with https://api.flutter.dev/ d: examples Sample code and demos f: scrolling Viewports, list views, slivers, etc. framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

(Test cross-imports) About Divider material widget import for tests in test/widgets

1 participant