Skip to content

ToggleButtons with MaterialTapTargetSize.padded and height constrained to 32 #97302

Description

@HansMuller

This issue corresponds to Google internal issue b/204226713. It does not need additional triage.

The ToggleButtons height has been constrained to 32 but the input area has been padded, per MaterialTapTargetSIze.padded, to 48. The Toggle button has been wrapped in a green Container to highlight the input padding.

Code sample
import 'package:flutter/material.dart';

class Home extends StatefulWidget {
  const Home({ Key? key }) : super(key: key);

  @override
  _HomeState createState() => _HomeState();
}

class _HomeState extends State<Home> {
  int selectedTabIndex = 0;

  @override
  Widget build(BuildContext context) {
    final ColorScheme colorScheme = Theme.of(context).colorScheme;
    return Scaffold(
      body: Center(
        child: Container(
          color: Colors.green.withOpacity(0.15),
          child: ToggleButtons(
            tapTargetSize: MaterialTapTargetSize.padded,
            isSelected: [
              selectedTabIndex == 0,
              selectedTabIndex == 1,
            ],
            onPressed: (int index) {
              setState(() { selectedTabIndex = index; });
            },
            borderRadius: const BorderRadius.all(Radius.circular(8)),
            selectedBorderColor: colorScheme.primary,
            selectedColor: colorScheme.primary,
            constraints: const BoxConstraints.tightFor(
              width: 86,
              height: 32,
            ),
            children: [
              Text('Locks'),
              Text('Unlocks'),
            ],
          ),
        ),
      ),
    );
  }
}
void main() {
  runApp(const MaterialApp(home: Home()));
}

Activity

  1. added
    frameworkflutter/packages/flutter repository. See also f: labels.
    p: material_uimaterial_ui package in flutter/packages
    on Jan 26, 2022
  2. math1man commented on Jan 26, 2022

    @math1man
    Contributor

    I think I've figure out the problem. In #93259 you're padding around each button, but you're not creating a new SemanticsNode for the padding. In contrast, ButtonStyleButton wraps its _InputPadding widget in a Semantics widget so that the SemanticsNode has the larger size. In the case of ToggleButtons, this should in theory be solvable by wrapping the _InputPadding widget in a MergedSemantics. Unfortunately, it looks like ToggleButtons wraps the whole group of individual buttons in _InputPadding as opposed to each individual button, so adding MergedSemantics is not trivial.

  3. added
    a: accessibilityAccessibility, e.g. VoiceOver or TalkBack. (aka a11y)
    on Feb 24, 2022
  4. self-assigned this
    on Mar 14, 2022
  5. added
    r: fixedIssue is closed as already fixed in a newer version
    on Apr 1, 2022
  6. removed
    r: fixedIssue is closed as already fixed in a newer version
    on Apr 7, 2022
  7. Piinks commented on Apr 7, 2022

    @Piinks
    Contributor

    Reopening as the change is being reverted

  8. reopened this on Apr 7, 2022
  9. github-actions commented on May 11, 2022

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  10. locked as resolved and limited conversation to collaborators on May 11, 2022
  11. moved this to Done (PR merged) in Nevercodeon Jul 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

a: accessibilityAccessibility, e.g. VoiceOver or TalkBack. (aka a11y)customer: googleVarious Google teamsframeworkflutter/packages/flutter repository. See also f: labels.p: material_uimaterial_ui package in flutter/packages

Type

No type

Projects

  • Status
    Done (PR merged)

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions