Skip to content

Conversation

@QuncCccccc
Copy link
Contributor

This PR fixes #64702, so the IconButtons on AppBar have a proper circular splash.
Screen Shot 2022-08-10 at 1 39 38 PM
Screen Shot 2022-08-10 at 1 40 59 PM

This PR also sets the default visualDensity of IconButton to VisualDensity.standard, to ensure the default IconButton will have a circular shape even if the app is running on desktop/web platforms (whose default compact visual density changes the shape to be rounded rectangle).

Just for more information, the default IconButton has a size of 48x48, 4 pixels of padding, and a circular shape. However, if a button changes to a different size or shape, the padding between buttons might be different from the default. The below code can achieve a combination of circular IconButton and rounded rectangle IconButton with the same paddings between each other, like the screenshot below.
Screen Shot 2022-08-10 at 1 56 50 PM

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

void main() {
  runApp(const IconButtonApp());
}

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      theme: ThemeData(
        brightness: Brightness.dark,
        colorSchemeSeed: const Color(0xff3c602b),
        useMaterial3: true,
        materialTapTargetSize: MaterialTapTargetSize.padded
    ),
      home: const Scaffold(
        body: ButtonExample(),
      ),
    );
  }
}

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

  Widget filledIconButton(ColorScheme colors) =>
    IconButton(
      icon: const Icon(Icons.back_hand),
      onPressed: () {},
      style: IconButton.styleFrom(
        foregroundColor: colors.onPrimary,
        backgroundColor: colors.primary,
      ),
    );

  Widget outlinedIconButton(ColorScheme colors) =>
    IconButton(
      icon: const Icon(Icons.more_vert),
      onPressed: () {},
      style: IconButton.styleFrom(
        focusColor: colors.onSurfaceVariant.withOpacity(0.12),
        highlightColor: colors.onSurface.withOpacity(0.12),
        side: BorderSide(color: colors.outline),
      ).copyWith(
        foregroundColor: MaterialStateProperty.resolveWith((Set<MaterialState> states) {
          if (states.contains(MaterialState.pressed)) {
            return colors.onSurface;
          }
          return null;
        }),
      ),
    );

  Widget roundedRectangleButton(ColorScheme colors) =>
    IconButton(
      icon: const Icon(Icons.call_end),
      onPressed: () {},
      style: IconButton.styleFrom(
        foregroundColor: colors.error,
        backgroundColor: colors.errorContainer,
        visualDensity: const VisualDensity(horizontal: 2),
      ),
    );

  @override
  Widget build(BuildContext context) {
    final ColorScheme colors = Theme.of(context).colorScheme;

    return Center(
      child: IntrinsicHeight(
        child: Row(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            filledIconButton(colors),
            outlinedIconButton(colors),
            Padding(
              padding: const EdgeInsets.symmetric(horizontal: 4),
              child: roundedRectangleButton(colors),
            ),
          ],
        ),
      ),
    );
  }
}

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the Flutter Style Guide, including Features we expect every widget to implement.
  • I signed the CLA.
  • I listed at least one issue that this PR fixes in the description above.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or this PR is test-exempt.
  • All existing and new tests are passing.

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

@flutter-dashboard flutter-dashboard bot added d: api docs Issues with https://api.flutter.dev/ d: examples Sample code and demos documentation f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels. c: contributor-productivity Team-specific productivity, code health, technical debt. labels Aug 10, 2022
@QuncCccccc QuncCccccc requested review from HansMuller and darrenaustin and removed request for HansMuller and darrenaustin August 10, 2022 21:55
Copy link
Contributor

@HansMuller HansMuller left a comment

Choose a reason for hiding this comment

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

LGTM

/// a component theme parameter like [sliderTheme], [toggleButtonsTheme],
/// or [bottomNavigationBarTheme].
///
/// In Material Design 3, the [IconButton.visualDensity] isn't affected by
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this comment probably belongs with the visualDensity API doc.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved. Thanks!

@QuncCccccc QuncCccccc marked this pull request as ready for review August 11, 2022 01:29
@QuncCccccc QuncCccccc merged commit 3070baf into flutter:master Aug 11, 2022
QuncCccccc added a commit that referenced this pull request Aug 11, 2022
QuncCccccc added a commit that referenced this pull request Aug 11, 2022
QuncCccccc added a commit that referenced this pull request Aug 11, 2022
QuncCccccc added a commit to QuncCccccc/flutter that referenced this pull request Aug 12, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 12, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/plugins that referenced this pull request Aug 12, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 13, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/plugins that referenced this pull request Aug 13, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/plugins that referenced this pull request Aug 13, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 13, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 14, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/plugins that referenced this pull request Aug 14, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 14, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/plugins that referenced this pull request Aug 14, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/plugins that referenced this pull request Aug 14, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 14, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 15, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/plugins that referenced this pull request Aug 15, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 15, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/plugins that referenced this pull request Aug 15, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 15, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/plugins that referenced this pull request Aug 15, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 15, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/plugins that referenced this pull request Aug 15, 2022
QuncCccccc added a commit that referenced this pull request Aug 18, 2022
#109432)

* Revert "Revert "Set `IconButton.visualDensity` default to `VisualDensity.standard` (#109349)" (#109421)"

Co-authored-by: Qun Cheng <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c: contributor-productivity Team-specific productivity, code health, technical debt. d: api docs Issues with https://api.flutter.dev/ d: examples Sample code and demos f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

IconButton's splash radius is too large on an AppBar

2 participants