Home > Enterprise >  Flutter remove tooltip text from drawer
Flutter remove tooltip text from drawer

Time:06-29

I am trying to remove the "Open Navigation Menu" text that appears when you hover over the menu icon of a drawer. Attached is my code:

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

  @override
  Widget build(BuildContext context) {
    final currentWidth = MediaQuery.of(context).size.width;
    return Scaffold(
        appBar: AppBar(
          leading: Padding(
            padding: EdgeInsets.fromLTRB(16.0, 0, 0, 0),
            child: IconButton(
                splashColor: Colors.transparent,
                highlightColor: Colors.transparent,
                icon: Image.asset("assets/Logo/Logo-DarkMode-Transparent.png"),
                iconSize: 32,
                padding: EdgeInsets.zero,
                onPressed: () {
                  // Navigator.of(context)
                  //     .pushNamedAndRemoveUntil('/', (route) => false);
                  // Navigator.pushNamed(context, '/');
                }),
          ),
        ),
        endDrawer: mobileDrawer(),
        body: const Center(
          child: Text(
            "COMING SOON!",
            style: TextStyle(
              fontSize: 70,
              color: Colors.white,
            ),
            textAlign: TextAlign.center,
          ),
        ));
  }
}

I tried to manually add the button as suggested in other questions however I want the logo on the left and the drawer on the right and adding it manually would always cause the 2 to overlap. I also tried using:

@override
String get openAppDrawerTooltip => 'Open navigation menu';

To override the text however that didn't change anything, Possibly because I may have put it in the wrong place.

I simply want to remove the text and have nothing display when hovering on the option.

Thanks!

CodePudding user response:

You can try wrap your page with TooltipVisibility example:

 MaterialApp(
  home: TooltipVisibility(
    visible: false,
    child: Scaffold(
      appBar: AppBar(),
      drawer: Drawer(),
      body: Container(),
    ),
  ),
);

CodePudding user response:

you just need to remove tooltip from app bar . Please check below code

AppBar(
          leading: Padding(
            padding: EdgeInsets.fromLTRB(16.0, 0, 0, 0),
            child: IconButton(
                splashColor: Colors.transparent,
                highlightColor: Colors.transparent,
                icon: Icon(Icons.menu)/*Image.asset("assets/Logo/Logo-DarkMode-Transparent.png")*/,
                iconSize: 32,
                padding: EdgeInsets.zero,
                onPressed: () {
                  // Navigator.of(context)
                  //     .pushNamedAndRemoveUntil('/', (route) => false);
                  // Navigator.pushNamed(context, '/');
                },
              //Note : comment this line
              // tooltip: 'Something else',
            ),
          ),
        ),

CodePudding user response:

There's another way to open drawer by using ScaffoldState. you can add new IconButton and call drawer when user press the button.

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

  final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>();

  @override
  Widget build(BuildContext context) {
    final currentWidth = MediaQuery.of(context).size.width;
    return Scaffold(
      key: _scaffoldKey, // dont forget to set the scaffoldKey
      endDrawer: const mobileDrawer(), // open drawer on the right side
      // drawer: const mobileDrawer(), // if you want to open drawer on left side
      appBar: AppBar(
        leading: IconButton(
          onPressed: () {},
          icon: const Icon(Icons.abc),
        ),
        actions: [
          IconButton(
              onPressed: () {
                _scaffoldKey.currentState?.openEndDrawer();
                // _scaffoldKey.currentState?.openDrawer();  // if you want to open drawer on left side
              },
              icon: const Icon(Icons.menu))
        ],
      ),
    );
  }
}

the tooltip will not appear anymore when you hover. but in case you want to add tooltip, you can wrap the iconButton with Tooltip widget.

  • Related