Skip to content

Commit

Permalink
Revert "Set IconButton.visualDensity default to `VisualDensity.stan…
Browse files Browse the repository at this point in the history
…dard` (#109349)" (#109421)

This reverts commit 3070baf.
  • Loading branch information
QuncCccccc committed Aug 11, 2022
1 parent 095f5da commit 625d96a
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 121 deletions.
2 changes: 1 addition & 1 deletion dev/tools/gen_defaults/lib/icon_button_template.dart
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ class _${blockName}DefaultsM3 extends ButtonStyle {
});
@override
VisualDensity? get visualDensity => VisualDensity.standard;
VisualDensity? get visualDensity => Theme.of(context).visualDensity;
@override
MaterialTapTargetSize? get tapTargetSize => Theme.of(context).materialTapTargetSize;
Expand Down
4 changes: 4 additions & 0 deletions examples/api/lib/material/icon_button/icon_button.3.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ class IconButtonToggleApp extends StatelessWidget {
theme: ThemeData(
colorSchemeSeed: const Color(0xff6750a4),
useMaterial3: true,
// Desktop and web platforms have a compact visual density by default.
// To see buttons with circular background on desktop/web, the "visualDensity"
// needs to be set to "VisualDensity.standard".
visualDensity: VisualDensity.standard,
),
title: 'Icon Button Types',
home: const Scaffold(
Expand Down
20 changes: 10 additions & 10 deletions examples/api/test/widgets/heroes/hero.0_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,32 +13,32 @@ void main() {
);

expect(find.text('Hero Sample'), findsOneWidget);
await tester.tap(find.byType(example.BoxWidget));
await tester.tap(find.byType(Container));
await tester.pump();

Size heroSize = tester.getSize(find.byType(example.BoxWidget));
Size heroSize = tester.getSize(find.byType(Container));

// Jump 25% into the transition (total length = 300ms)
await tester.pump(const Duration(milliseconds: 75)); // 25% of 300ms
heroSize = tester.getSize(find.byType(example.BoxWidget));
heroSize = tester.getSize(find.byType(Container));
expect(heroSize.width.roundToDouble(), 103.0);
expect(heroSize.height.roundToDouble(), 60.0);

// Jump to 50% into the transition.
await tester.pump(const Duration(milliseconds: 75)); // 25% of 300ms
heroSize = tester.getSize(find.byType(example.BoxWidget));
heroSize = tester.getSize(find.byType(Container));
expect(heroSize.width.roundToDouble(), 189.0);
expect(heroSize.height.roundToDouble(), 146.0);

// Jump to 75% into the transition.
await tester.pump(const Duration(milliseconds: 75)); // 25% of 300ms
heroSize = tester.getSize(find.byType(example.BoxWidget));
heroSize = tester.getSize(find.byType(Container));
expect(heroSize.width.roundToDouble(), 199.0);
expect(heroSize.height.roundToDouble(), 190.0);

// Jump to 100% into the transition.
await tester.pump(const Duration(milliseconds: 75)); // 25% of 300ms
heroSize = tester.getSize(find.byType(example.BoxWidget));
heroSize = tester.getSize(find.byType(Container));
expect(heroSize, const Size(200.0, 200.0));

expect(find.byIcon(Icons.arrow_back), findsOneWidget);
Expand All @@ -47,25 +47,25 @@ void main() {

// Jump 25% into the transition (total length = 300ms)
await tester.pump(const Duration(milliseconds: 75)); // 25% of 300ms
heroSize = tester.getSize(find.byType(example.BoxWidget));
heroSize = tester.getSize(find.byType(Container));
expect(heroSize.width.roundToDouble(), 199.0);
expect(heroSize.height.roundToDouble(), 190.0);

// Jump to 50% into the transition.
await tester.pump(const Duration(milliseconds: 75)); // 25% of 300ms
heroSize = tester.getSize(find.byType(example.BoxWidget));
heroSize = tester.getSize(find.byType(Container));
expect(heroSize.width.roundToDouble(), 189.0);
expect(heroSize.height.roundToDouble(), 146.0);

// Jump to 75% into the transition.
await tester.pump(const Duration(milliseconds: 75)); // 25% of 300ms
heroSize = tester.getSize(find.byType(example.BoxWidget));
heroSize = tester.getSize(find.byType(Container));
expect(heroSize.width.roundToDouble(), 103.0);
expect(heroSize.height.roundToDouble(), 60.0);

// Jump to 100% into the transition.
await tester.pump(const Duration(milliseconds: 75)); // 25% of 300ms
heroSize = tester.getSize(find.byType(example.BoxWidget));
heroSize = tester.getSize(find.byType(Container));
expect(heroSize, const Size(50.0, 50.0));
});
}
36 changes: 18 additions & 18 deletions examples/api/test/widgets/heroes/hero.1_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,30 @@ void main() {
await tester.tap(find.byType(ElevatedButton));
await tester.pump();

Size heroSize = tester.getSize(find.byType(example.BoxWidget).first);
Size heroSize = tester.getSize(find.byType(Container).first);
expect(heroSize, const Size(50.0, 50.0));

// Jump 25% into the transition (total length = 300ms)
await tester.pump(const Duration(milliseconds: 75)); // 25% of 300ms
heroSize = tester.getSize(find.byType(example.BoxWidget).first);
heroSize = tester.getSize(find.byType(Container).first);
expect(heroSize.width.roundToDouble(), 171.0);
expect(heroSize.height.roundToDouble(), 73.0);

// Jump to 50% into the transition.
await tester.pump(const Duration(milliseconds: 75)); // 25% of 300ms
heroSize = tester.getSize(find.byType(example.BoxWidget).first);
heroSize = tester.getSize(find.byType(Container).first);
expect(heroSize.width.roundToDouble(), 371.0);
expect(heroSize.height.roundToDouble(), 273.0);

// Jump to 75% into the transition.
await tester.pump(const Duration(milliseconds: 75)); // 25% of 300ms
heroSize = tester.getSize(find.byType(example.BoxWidget).first);
heroSize = tester.getSize(find.byType(Container).first);
expect(heroSize.width.roundToDouble(), 398.0);
expect(heroSize.height.roundToDouble(), 376.0);

// Jump to 100% into the transition.
await tester.pump(const Duration(milliseconds: 75)); // 25% of 300ms
heroSize = tester.getSize(find.byType(example.BoxWidget).first);
heroSize = tester.getSize(find.byType(Container).first);
expect(heroSize, const Size(400.0, 400.0));

expect(find.byIcon(Icons.arrow_back), findsOneWidget);
Expand All @@ -48,25 +48,25 @@ void main() {

// Jump 25% into the transition (total length = 300ms)
await tester.pump(const Duration(milliseconds: 75)); // 25% of 300ms
heroSize = tester.getSize(find.byType(example.BoxWidget).first);
heroSize = tester.getSize(find.byType(Container).first);
expect(heroSize.width.roundToDouble(), 398.0);
expect(heroSize.height.roundToDouble(), 376.0);

// Jump to 50% into the transition.
await tester.pump(const Duration(milliseconds: 75)); // 25% of 300ms
heroSize = tester.getSize(find.byType(example.BoxWidget).first);
heroSize = tester.getSize(find.byType(Container).first);
expect(heroSize.width.roundToDouble(), 371.0);
expect(heroSize.height.roundToDouble(), 273.0);

// Jump to 75% into the transition.
await tester.pump(const Duration(milliseconds: 75)); // 25% of 300ms
heroSize = tester.getSize(find.byType(example.BoxWidget).first);
heroSize = tester.getSize(find.byType(Container).first);
expect(heroSize.width.roundToDouble(), 171.0);
expect(heroSize.height.roundToDouble(), 73.0);

// Jump to 100% into the transition.
await tester.pump(const Duration(milliseconds: 75)); // 25% of 300ms
heroSize = tester.getSize(find.byType(example.BoxWidget).first);
heroSize = tester.getSize(find.byType(Container).first);
expect(heroSize, const Size(50.0, 50.0));
});

Expand All @@ -79,30 +79,30 @@ void main() {
await tester.tap(find.byType(ElevatedButton));
await tester.pump();

Size heroSize = tester.getSize(find.byType(example.BoxWidget).last);
Size heroSize = tester.getSize(find.byType(Container).last);
expect(heroSize, const Size(50.0, 50.0));

// Jump 25% into the transition (total length = 300ms)
await tester.pump(const Duration(milliseconds: 75)); // 25% of 300ms
heroSize = tester.getSize(find.byType(example.BoxWidget).last);
heroSize = tester.getSize(find.byType(Container).last);
expect(heroSize.width.roundToDouble(), 133.0);
expect(heroSize.height.roundToDouble(), 133.0);

// Jump to 50% into the transition.
await tester.pump(const Duration(milliseconds: 75)); // 25% of 300ms
heroSize = tester.getSize(find.byType(example.BoxWidget).last);
heroSize = tester.getSize(find.byType(Container).last);
expect(heroSize.width.roundToDouble(), 321.0);
expect(heroSize.height.roundToDouble(), 321.0);

// Jump to 75% into the transition.
await tester.pump(const Duration(milliseconds: 75)); // 25% of 300ms
heroSize = tester.getSize(find.byType(example.BoxWidget).first);
heroSize = tester.getSize(find.byType(Container).first);
expect(heroSize.width.roundToDouble(), 398.0);
expect(heroSize.height.roundToDouble(), 376.0);

// Jump to 100% into the transition.
await tester.pump(const Duration(milliseconds: 75)); // 25% of 300ms
heroSize = tester.getSize(find.byType(example.BoxWidget).last);
heroSize = tester.getSize(find.byType(Container).last);
expect(heroSize, const Size(400.0, 400.0));

expect(find.byIcon(Icons.arrow_back), findsOneWidget);
Expand All @@ -111,25 +111,25 @@ void main() {

// Jump 25% into the transition (total length = 300ms)
await tester.pump(const Duration(milliseconds: 75)); // 25% of 300ms
heroSize = tester.getSize(find.byType(example.BoxWidget).last);
heroSize = tester.getSize(find.byType(Container).last);
expect(heroSize.width.roundToDouble(), 386.0);
expect(heroSize.height.roundToDouble(), 386.0);

// Jump to 50% into the transition.
await tester.pump(const Duration(milliseconds: 75)); // 25% of 300ms
heroSize = tester.getSize(find.byType(example.BoxWidget).last);
heroSize = tester.getSize(find.byType(Container).last);
expect(heroSize.width.roundToDouble(), 321.0);
expect(heroSize.height.roundToDouble(), 321.0);

// Jump to 75% into the transition.
await tester.pump(const Duration(milliseconds: 75)); // 25% of 300ms
heroSize = tester.getSize(find.byType(example.BoxWidget).last);
heroSize = tester.getSize(find.byType(Container).last);
expect(heroSize.width.roundToDouble(), 133.0);
expect(heroSize.height.roundToDouble(), 133.0);

// Jump to 100% into the transition.
await tester.pump(const Duration(milliseconds: 75)); // 25% of 300ms
heroSize = tester.getSize(find.byType(example.BoxWidget).last);
heroSize = tester.getSize(find.byType(Container).last);
expect(heroSize, const Size(50.0, 50.0));
});
}
4 changes: 2 additions & 2 deletions packages/flutter/lib/src/material/app_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -998,8 +998,7 @@ class _AppBarState extends State<AppBar> {
}
}
if (leading != null) {
leading = Container(
alignment: Alignment.center,
leading = ConstrainedBox(
constraints: BoxConstraints.tightFor(width: widget.leadingWidth ?? _kLeadingWidth),
child: leading,
);
Expand Down Expand Up @@ -1057,6 +1056,7 @@ class _AppBarState extends State<AppBar> {
if (widget.actions != null && widget.actions!.isNotEmpty) {
actions = Row(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: widget.actions!,
);
} else if (hasEndDrawer) {
Expand Down
12 changes: 2 additions & 10 deletions packages/flutter/lib/src/material/icon_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,6 @@ const double _kMinButtonSize = kMinInteractiveDimension;
/// precedence: widget property, [IconButtonTheme] property, [IconTheme] property and
/// internal default property value.
///
/// In Material Design 3, the [IconButton.visualDensity] defaults to [VisualDensity.standard]
/// for all platforms because the button will have a rounded rectangle shape if
/// the [IconButton.visualDensity] is set to [VisualDensity.compact]. Users can
/// customize it by using [IconButtonTheme], [IconButton.style] or [IconButton.visualDensity].
///
/// {@tool dartpad}
/// This sample shows creation of [IconButton] widgets for standard, filled,
/// filled tonal and outlined types, as described in: https://m3.material.io/components/icon-buttons/overview
Expand Down Expand Up @@ -223,9 +218,6 @@ class IconButton extends StatelessWidget {
///
/// {@macro flutter.material.themedata.visualDensity}
///
/// This property can be null. If null, it defaults to [VisualDensity.standard]
/// in Material Design 3 to make sure the button will be circular on all platforms.
///
/// See also:
///
/// * [ThemeData.visualDensity], which specifies the [visualDensity] for all
Expand Down Expand Up @@ -819,7 +811,7 @@ class _IconButtonM3 extends ButtonStyleButton {
/// * `mouseCursor`
/// * disabled - SystemMouseCursors.basic
/// * others - SystemMouseCursors.click
/// * `visualDensity` - VisualDensity.standard
/// * `visualDensity` - theme.visualDensity
/// * `tapTargetSize` - theme.materialTapTargetSize
/// * `animationDuration` - kThemeChangeDuration
/// * `enableFeedback` - true
Expand Down Expand Up @@ -1061,7 +1053,7 @@ class _IconButtonDefaultsM3 extends ButtonStyle {
});

@override
VisualDensity? get visualDensity => VisualDensity.standard;
VisualDensity? get visualDensity => Theme.of(context).visualDensity;

@override
MaterialTapTargetSize? get tapTargetSize => Theme.of(context).materialTapTargetSize;
Expand Down
5 changes: 0 additions & 5 deletions packages/flutter/lib/src/material/theme_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1261,11 +1261,6 @@ class ThemeData with Diagnosticable {
///
/// A larger value translates to a spacing increase (less dense), and a
/// smaller value translates to a spacing decrease (more dense).
///
/// In Material Design 3, the [visualDensity] does not override the value of
/// [IconButton.visualDensity] which defaults to [VisualDensity.standard]
/// for all platforms. To override the default value of [IconButton.visualDensity],
/// use [ThemeData.iconButtonTheme] instead.
/// {@endtemplate}
final VisualDensity visualDensity;

Expand Down
12 changes: 6 additions & 6 deletions packages/flutter/test/material/app_bar_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -707,8 +707,8 @@ void main() {
);

final Finder hamburger = find.byTooltip('Open navigation menu');
expect(tester.getTopLeft(hamburger), const Offset(4.0, 4.0));
expect(tester.getSize(hamburger), const Size(48.0, 48.0));
expect(tester.getTopLeft(hamburger), Offset.zero);
expect(tester.getSize(hamburger), const Size(56.0, 56.0));
});

testWidgets('test action is 4dp from edge and 48dp min', (WidgetTester tester) async {
Expand Down Expand Up @@ -737,14 +737,14 @@ void main() {
),
);

final Finder addButton = find.widgetWithIcon(IconButton, Icons.add);
final Finder addButton = find.byTooltip('Add');
expect(tester.getTopRight(addButton), const Offset(800.0, 0.0));
// It's still the size it was plus the 2 * 8dp padding from IconButton.
expect(tester.getSize(addButton), const Size(60.0 + 2 * 8.0, 56.0));

final Finder shareButton = find.widgetWithIcon(IconButton, Icons.share);
final Finder shareButton = find.byTooltip('Share');
// The 20dp icon is expanded to fill the IconButton's touch target to 48dp.
expect(tester.getSize(shareButton), const Size(48.0, 48.0));
expect(tester.getSize(shareButton), const Size(48.0, 56.0));
});

testWidgets('SliverAppBar default configuration', (WidgetTester tester) async {
Expand Down Expand Up @@ -1672,7 +1672,7 @@ void main() {
),
);
await tester.tap(find.byKey(key));
expect(painter, paints..save()..translate()..save()..translate()..circle(x: 24.0, y: 24.0));
expect(painter, paints..save()..translate()..save()..translate()..circle(x: 24.0, y: 28.0));
});

testWidgets('AppBar handles loose children 0', (WidgetTester tester) async {
Expand Down

0 comments on commit 625d96a

Please sign in to comment.