Skip to content

Conversation

@markusaksli-nc
Copy link
Contributor

@markusaksli-nc markusaksli-nc commented Oct 11, 2021

Adds a new widget to visually disable tooltips in a child subtree without losing semantics labels (based on the discussion in #66993).

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

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

enum WhyFarther { harder, smarter, selfStarter, tradingCharter }

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

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  WhyFarther? _selection;
  bool tooltipVisibility = false;
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      //showSemanticsDebugger: true,
      home: TooltipVisibility(
        visible: tooltipVisibility,
        child: Scaffold(
          appBar: AppBar(
            title: Text("Test"),
          ),
          body: Center(
              child: TooltipVisibility(
                visible: !tooltipVisibility,
                child: PopupMenuButton<WhyFarther>(
                  tooltip: null,
                  onSelected: (WhyFarther result) {
                    setState(() {
                      _selection = result;
                    });
                  },
                  itemBuilder: (BuildContext context) => <PopupMenuEntry<WhyFarther>>[
                    const PopupMenuItem<WhyFarther>(
                      value: WhyFarther.harder,
                      child: Text('Working a lot harder'),
                    ),
                    const PopupMenuItem<WhyFarther>(
                      value: WhyFarther.smarter,
                      child: Text('Being a lot smarter'),
                    ),
                    const PopupMenuItem<WhyFarther>(
                      value: WhyFarther.selfStarter,
                      child: Text('Being a self-starter'),
                    ),
                    const PopupMenuItem<WhyFarther>(
                      value: WhyFarther.tradingCharter,
                      child: Text('Placed in charge of trading charter'),
                    ),
                  ],
                ),
              )),
          drawer: Drawer(
            child: ListView(
              children: [
                const Text("Drawer item"),
              ],
            ),
          ),
          floatingActionButton: Switch(
            value: tooltipVisibility,
            onChanged:(value) => setState(()=> tooltipVisibility = value),
          ),
        ),
      ),
    );
  }
}

Fixes #66993, #60418

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.
  • All existing and new tests are passing.

@flutter-dashboard flutter-dashboard bot added f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels. labels Oct 11, 2021
@flutter-dashboard
Copy link

It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact Hixie on the #hackers channel in Chat.

If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix?

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

@google-cla google-cla bot added the cla: yes label Oct 11, 2021
@markusaksli-nc
Copy link
Contributor Author

markusaksli-nc commented Oct 11, 2021

I just implemented the change itself, for now, will get to tests and docs tomorrow.

@markusaksli-nc markusaksli-nc changed the title Added TooltipDisable class Added TooltipVisibility widget Oct 12, 2021
@markusaksli-nc
Copy link
Contributor Author

markusaksli-nc commented Oct 12, 2021

Things that could be changed about this approach:

  • remove the GestureDetector and MouseRegion from build as well if !_visible
  • use a TooltipTheme property instead of a separate widget

@markusaksli-nc markusaksli-nc changed the title Added TooltipVisibility widget Add TooltipVisibility widget Oct 12, 2021
Copy link
Contributor

@gspencergoog gspencergoog left a comment

Choose a reason for hiding this comment

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

32384589-a60f0e74-c078-11e7-9bc1-e5b5287aea9d

Thanks, this looks pretty useful.

@markusaksli-nc
Copy link
Contributor Author

Thanks a lot, I figured I would add this to some See alsos as well so people can find it in the docs.

@markusaksli-nc markusaksli-nc removed the request for review from chunhtai October 19, 2021 07:27
@fluttergithubbot fluttergithubbot merged commit 6b94f2f into flutter:master Oct 19, 2021
@markusaksli-nc markusaksli-nc deleted the tooltip-disable branch October 19, 2021 11:53
@markusaksli-nc markusaksli-nc restored the tooltip-disable branch October 19, 2021 12:26
markusaksli-nc added a commit that referenced this pull request Oct 19, 2021
markusaksli-nc added a commit that referenced this pull request Oct 19, 2021
@markusaksli-nc
Copy link
Contributor Author

Turns out there was an analysis issue that only came out after this was merged, created #92090 to reland

clocksmith pushed a commit to clocksmith/flutter that referenced this pull request Oct 29, 2021
clocksmith pushed a commit to clocksmith/flutter that referenced this pull request Oct 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

Global enable/disable of tooltips in Flutter apps and provide API control over widget tooltips PopupMenuButton has no option remove tooltip

4 participants