Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 47 additions & 9 deletions examples/api/lib/ui/text/font_feature.0.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';

/// Flutter code sample for [FontFeature].

Expand All @@ -11,27 +11,65 @@ void main() => runApp(const ExampleApp());
class ExampleApp extends StatelessWidget {
const ExampleApp({super.key});

static PageRoute<T> _pageRouteBuilder<T>(
RouteSettings settings,
WidgetBuilder builder,
) {
return PageRouteBuilder<T>(
settings: settings,
pageBuilder:
(
BuildContext context,
Animation<double> animation,
Animation<double> secondaryAnimation,
) => builder(context),
transitionsBuilder:
(
BuildContext context,
Animation<double> animation,
Animation<double> secondaryAnimation,
Widget child,
) => child,
);
}

@override
Widget build(BuildContext context) {
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(),

pageRouteBuilder: _pageRouteBuilder,
);
}
}

final TextStyle titleStyle = TextStyle(
const TextStyle titleStyle = TextStyle(
fontSize: 18,
fontFeatures: const <FontFeature>[FontFeature.enable('smcp')],
color: Colors.blueGrey[600],
fontFeatures: <FontFeature>[FontFeature.enable('smcp')],
color: Color(0xFF0000FF),
);

class ExampleWidget extends StatelessWidget {
const ExampleWidget({super.key});

Widget buildDivider() {
return Padding(
padding: const EdgeInsets.all(4),
child: Container(
color: const Color(0xFF000000),
height: 4,
width: double.infinity,
),
);
}
Comment on lines +55 to +64
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)


@override
Widget build(BuildContext context) {
// The Cardo, Milonga and Raleway Dots fonts can be downloaded from Google
// Fonts (https://www.google.com/fonts).
return Scaffold(
body: Center(
return Directionality(
textDirection: TextDirection.ltr,
child: Center(
child: Column(
mainAxisAlignment: .center,
children: <Widget>[
Expand All @@ -55,7 +93,7 @@ class ExampleWidget extends StatelessWidget {
),
),
const Spacer(),
const Divider(),
buildDivider(),
const Spacer(),
Text(
'fractions look better with a custom ligature:',
Expand All @@ -70,7 +108,7 @@ class ExampleWidget extends StatelessWidget {
),
),
const Spacer(),
const Divider(),
buildDivider(),
const Spacer(),
Text('multiple stylistic sets in one font:', style: titleStyle),
const Text(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,14 @@ class _ScrollNotificationDemoState extends State<ScrollNotificationDemo> {
child: Text('Item $index'),
);
},
separatorBuilder: (_, _) =>
const Divider(indent: 20, endIndent: 20, thickness: 2),
separatorBuilder: (_, _) => Padding(
padding: const EdgeInsets.all(4),
child: Container(
color: const Color(0xFF000000),
height: 4,
width: double.infinity,
),
),
Comment on lines +76 to +83
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)

),
],
);
Expand Down
17 changes: 14 additions & 3 deletions examples/api/lib/widgets/text/ui_testing_with_text.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@ class MyApp extends StatefulWidget {
}

class _MyAppState extends State<MyApp> {
Widget buildDivider() {
return Padding(
padding: const EdgeInsets.all(4),
child: Container(
color: const Color(0xFF000000),
height: 4,
width: double.infinity,
),
);
}
Comment on lines +18 to +27
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)


@override
Widget build(BuildContext context) {
final TextStyle? bodyStyle = Theme.of(context).textTheme.bodyLarge;
Expand Down Expand Up @@ -46,15 +57,15 @@ class _MyAppState extends State<MyApp> {
const Text(
'The identifier property in Semantics widget is used for UI testing with tools that work by querying the native accessibility, like UIAutomator, XCUITest, or Appium. It can be matched with CommonFinders.bySemanticsIdentifier.',
),
const Divider(),
buildDivider(),
Text('Text Example:', style: bodyStyle),
const Text(
'This text has a custom label and an identifier. In Android, the label is used as the content-desc, and the identifier is used as the resource-id.',
semanticsLabel: 'This is a custom label',
semanticsIdentifier:
'This is a custom identifier that only the automation tools are able to see',
),
const Divider(),
buildDivider(),
Text('Text.rich Example:', style: bodyStyle),
Text.rich(
TextSpan(
Expand All @@ -80,7 +91,7 @@ class _MyAppState extends State<MyApp> {
],
),
),
const Divider(),
buildDivider(),
Text('Multi-tenant Example:', style: bodyStyle),
const SizedBox(height: 16),
Column(
Expand Down
4 changes: 2 additions & 2 deletions examples/api/test/ui/text/font_feature.0_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_api_samples/ui/text/font_feature.0.dart' as example;
import 'package:flutter_test/flutter_test.dart';

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());


expect(find.byType(Text), findsNWidgets(9));
expect(
Expand Down
11 changes: 9 additions & 2 deletions examples/multiple_windows/lib/app/window_settings_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ class _WindowSettingsEditorState extends State<_WindowSettingsEditor> {
child: ListView(
children: [
_buildRegularEditor(),
const Divider(),
_buildDivider(),
_buildDialogEditor(),
const Divider(),
_buildDivider(),
_buildTooltipEditor(),
],
),
Expand Down Expand Up @@ -359,6 +359,13 @@ class _WindowSettingsEditorState extends State<_WindowSettingsEditor> {
);
}

Widget _buildDivider() {
return Padding(
padding: const EdgeInsets.all(4),
child: Container(color: const Color(0xFF000000), height: 4, width: double.infinity),
);
}
Comment on lines +362 to +367
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)


void _updateRegularSize() {
widget.settings.regularSize = Size(
double.tryParse(_regularWidthController.text) ?? widget.settings.regularSize.width,
Expand Down
4 changes: 2 additions & 2 deletions packages/flutter/lib/src/widgets/animated_scroll_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,10 @@ class AnimatedList extends _AnimatedScrollView {
/// );
/// },
/// separatorBuilder: (BuildContext context, int index, Animation<double> animation) {
/// return const Divider();
/// return Container(height: 1.0, color: const Color(0xFFF5F5F5));
/// },
/// removedSeparatorBuilder: (BuildContext context, int index, Animation<double> animation) {
/// return const Divider();
/// return Container(height: 1.0, color: const Color(0xFFF5F5F5));
/// }
/// ),
/// );
Expand Down
4 changes: 2 additions & 2 deletions packages/flutter/lib/src/widgets/scroll_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1076,7 +1076,7 @@ abstract class BoxScrollView extends ScrollView {
/// child: Center(child: Text('Entry ${entries[index]}')),
/// );
/// },
/// separatorBuilder: (BuildContext context, int index) => const Divider(),
/// separatorBuilder: (BuildContext context, int index) => Container(height: 1.0, color: const Color(0xFFF5F5F5)),
/// );
/// }
/// ```
Expand Down Expand Up @@ -1483,7 +1483,7 @@ class ListView extends BoxScrollView {
/// ```dart
/// ListView.separated(
/// itemCount: 25,
/// separatorBuilder: (BuildContext context, int index) => const Divider(),
/// separatorBuilder: (BuildContext context, int index) => Container(height: 1.0, color: const Color(0xFFF5F5F5)),
/// itemBuilder: (BuildContext context, int index) {
/// return ListTile(
/// title: Text('item $index'),
Expand Down
2 changes: 1 addition & 1 deletion packages/flutter/lib/src/widgets/sliver.dart
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ class SliverList extends SliverMultiBoxAdaptorWidget {
/// child: Text('list item $index'),
/// );
/// },
/// separatorBuilder: (BuildContext context, int index) => const Divider(),
/// separatorBuilder: (BuildContext context, int index) => Container(height: 1.0, color: const Color(0xFFF5F5F5)),
/// )
/// ```
/// {@end-tool}
Expand Down
4 changes: 2 additions & 2 deletions packages/flutter/test_fixes/widgets/scroll_views_fixes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/widgets.dart';

void main() {
// Runtime variable (should NOT be migrated)
Expand Down Expand Up @@ -163,7 +163,7 @@ void main() {
listView = ListView.separated(
cacheExtent: 200.0,
itemBuilder: (BuildContext context, int index) => const Text(''),
separatorBuilder: (BuildContext context, int index) => const Divider(),
separatorBuilder: (BuildContext context, int index) => const SizedBox(),
itemCount: 10,
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/widgets.dart';

void main() {
// Runtime variable (should NOT be migrated)
Expand Down Expand Up @@ -141,7 +141,7 @@ void main() {

listView = ListView.separated(
scrollCacheExtent: ScrollCacheExtent.pixels(200.0), itemBuilder: (BuildContext context, int index) => const Text(''),
separatorBuilder: (BuildContext context, int index) => const Divider(),
separatorBuilder: (BuildContext context, int index) => const SizedBox(),
itemCount: 10,
);

Expand Down
9 changes: 8 additions & 1 deletion packages/flutter_test/test/controller_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,14 @@ void main() {
ListTile(title: Text('Item a-$i')),
),
),
const Divider(thickness: 5),
Padding(
padding: const EdgeInsets.all(4),
child: Container(
color: const Color(0xFF000000),
height: 5,
width: double.infinity,
),
),
Comment on lines +582 to +589
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)

Expanded(
child: ListView.builder(
key: const Key('listView-b'),
Expand Down
Loading