Sitelet https://web.archive.org/web/20220401233355/https://github.com/flutter/flutter/pull/99493
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor ToggleButtons (remove RawMaterialButton) #99493

Merged
merged 4 commits into from Mar 31, 2022

Conversation

TahaTesser
Copy link
Member

@TahaTesser TahaTesser commented Mar 3, 2022 •

fixes #99085
fixes #97302

minimal code sample
import 'package:flutter/material.dart';

const List<Widget> icons = <Widget>[
  Icon(Icons.ac_unit),
  Icon(Icons.call),
  Icon(Icons.cake),
];

void main() => runApp(const MyApp());

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      title: 'Material App',
      home: ToggleButtonsSample(),
    );
  }
}

class ToggleButtonsSample extends StatelessWidget {
  ToggleButtonsSample({Key? key}) : super(key: key);
  final ValueNotifier<int> _toggleValue = ValueNotifier<int>(0);

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

    return Scaffold(
      appBar: AppBar(
        title: const Text('ToggleButtons Sample'),
      ),
      body: Center(
        child: ValueListenableBuilder(
          valueListenable: _toggleValue,
          builder: (BuildContext context, int value, Widget? child) {
            return ToggleButtons(
              onPressed: (int newIndex) => _toggleValue.value = newIndex,
              borderRadius: const BorderRadius.all(Radius.circular(8)),
              selectedBorderColor: colorScheme.primary,
              selectedColor: colorScheme.primary,
              isSelected: <bool>[
                _toggleValue.value == 0,
                _toggleValue.value == 1,
                _toggleValue.value == 2,
              ],
              children: icons,
            );
          },
        ),
      ),
    );
  }
}

Description

Here this PR refactors ToggleButtons and use ButtonStyleButton to style ToggleButtons

highlight color not being translated to ElevatedButton (ButtonStyleButton sets highlight color to be transparent).

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 f: material design framework labels Mar 3, 2022
@TahaTesser TahaTesser requested review from HansMuller and Piinks Mar 3, 2022
@TahaTesser TahaTesser force-pushed the refactor_toggle_buttons branch from 8058dd0 to 2f79f04 Compare Mar 4, 2022
Copy link
Contributor

@Piinks Piinks left a comment

NICE - all of the existing golden file tests pass! 🎉 (There are only two, but still, that's great)

Comparing this to the same refactor you are doing for FAB (#99753)

  • FAB is not becoming a ButtonStyleButton, but here it looks like ToggleButtons are.
  • FAB is not going to have a ButtonStyle style parameter like here, instead deferring to its numerated properties and inherited theme to create a ButtonStyle internally. ToggleButtons here allow for style to be set OR individual properties + theming.

I wonder if the FAB approach is cleaner, the style property here on ToggleButtons might not be necessary, but again I will defer to @HansMuller on general design since he wrote the model.

All of this work in FAB & Toggle is really great progress though. Thanks!

@HansMuller
Copy link
Contributor

@HansMuller HansMuller commented Mar 11, 2022

We should make sure that this PR also fixes #97302

@HansMuller
Copy link
Contributor

@HansMuller HansMuller commented Mar 11, 2022

I agree with Kate, this PR shouldn't include the extra step of adding a ButtonStyle style parameter to ToggleButtons; we should leave that for a separate proposal/PR.

@TahaTesser TahaTesser force-pushed the refactor_toggle_buttons branch from 74a9652 to 4b1618d Compare Mar 11, 2022
@TahaTesser
Copy link
Member Author

@TahaTesser TahaTesser commented Mar 14, 2022

We should make sure that this PR also fixes #97302

This is now handled by TextButton widget in this refactor, can you please take a look

Mobile

Screenshot_1647249245

Desktop (Web)

Screenshot 2022-03-14 111522

@HansMuller
Copy link
Contributor

@HansMuller HansMuller commented Mar 14, 2022

@TahaTesser - if this PR fixes #97302 it should say so in the PR's description and it should include a regression test (marked as a regression test for #97302 with a comment).

@HansMuller
Copy link
Contributor

@HansMuller HansMuller commented Mar 14, 2022

@TahaTesser - the screenshots in #99493 (comment) imply that the background color for the ToggleButtons isn't clipped to the ToggleButtons' shape?

@TahaTesser
Copy link
Member Author

@TahaTesser TahaTesser commented Mar 14, 2022 •

@HansMuller
Thanks so much for your time,

@TahaTesser - the screenshots in #99493 (comment) imply that the background color for the ToggleButtons isn't clipped to the ToggleButtons' shape?

This is just a parent container with color from #97302

ClipRRect still clipping the toggle buttons in this refactor
https://github.com/flutter/flutter/pull/99493/files#diff-153bdbb7a6739dd071bbb7b8230e3884dcb6cedbc21a78ef82c0e6a8166bb220R731

@HansMuller
Copy link
Contributor

@HansMuller HansMuller commented Mar 14, 2022

@TahaTesser - Good!

@TahaTesser
Copy link
Member Author

@TahaTesser TahaTesser commented Mar 14, 2022 •

@HansMuller
Added a regression test with a link to the issue

@TahaTesser
Copy link
Member Author

@TahaTesser TahaTesser commented Mar 15, 2022

@HansMuller
During refactoring noticed, there is no interactive example that showcases different configurations for ToggleButtons

Filed #100124, this will land after this PR (tester finders look for TextButton instead of RawMaterialButton).

Copy link
Contributor

@HansMuller HansMuller left a comment

This is looking good however I don't think the style parameter belongs in this PR; see #99493 (comment)

@TahaTesser TahaTesser force-pushed the refactor_toggle_buttons branch from 4284e86 to 21d345d Compare Mar 17, 2022
@TahaTesser
Copy link
Member Author

@TahaTesser TahaTesser commented Mar 17, 2022

This is looking good however I don't think the style parameter belongs in this PR; see #99493 (comment)

My apologies I missed removing that parameter, done.

Copy link
Contributor

@Piinks Piinks left a comment

@TahaTesser is this ready for another review? Or is it waiting on additional changes like the FAB one?

@TahaTesser
Copy link
Member Author

@TahaTesser TahaTesser commented Mar 23, 2022 •

@TahaTesser is this ready for another review? Or is it waiting on additional changes like the FAB one?

Hey @Piinks!
This needs another review. (my bad I thought I click request button before)

This Diagnosticable issue from FAB one doesn't affect this PR, all tests are passing

@TahaTesser TahaTesser requested a review from HansMuller Mar 23, 2022
@HansMuller
Copy link
Contributor

@HansMuller HansMuller commented Mar 23, 2022

@TahaTesser - I haven't tested or even compiled the code I've suggested for the _ForegroundColor and _BackgroundColor. If they're difficult let me know and I'll fix them.

@TahaTesser TahaTesser force-pushed the refactor_toggle_buttons branch from 213dfc0 to 9db5792 Compare Mar 23, 2022
@TahaTesser
Copy link
Member Author

@TahaTesser TahaTesser commented Mar 23, 2022 •

@TahaTesser - I haven't tested or even compiled the code I've suggested for the _ForegroundColor and _BackgroundColor. If they're difficult let me know and I'll fix them.

This is cleaner, thanks!
I made slight refinements and added these classes including the local ColorScheme variable as suggested and removed the redundant code due to these classes.

engine-flutter-autoroll added a commit to engine-flutter-autoroll/plugins that referenced this issue Apr 1, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/plugins that referenced this issue Apr 1, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/plugins that referenced this issue Apr 1, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/plugins that referenced this issue Apr 1, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/plugins that referenced this issue Apr 1, 2022
@TahaTesser TahaTesser deleted the refactor_toggle_buttons branch Apr 1, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/plugins that referenced this issue Apr 1, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/plugins that referenced this issue Apr 1, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/plugins that referenced this issue Apr 1, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/plugins that referenced this issue Apr 1, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/plugins that referenced this issue Apr 1, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/plugins that referenced this issue Apr 1, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/plugins that referenced this issue Apr 1, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/plugins that referenced this issue Apr 1, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/plugins that referenced this issue Apr 1, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/plugins that referenced this issue Apr 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
f: material design framework waiting for tree to go green
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants