4

I'd like to implement this feature:

When user click on disabled radio buttons, it should display a hint text to tell user that it is not allowed to change choices.

I've checked Tooltip, it is said:

Wrap the button in a Tooltip widget to show a label when the widget long pressed (or when the user takes some other appropriate action).

Regarding to Tooltip, I only know how to implement it when user long pressed the widget to show tooltip. I don't know how to achieve when the user takes some other appropriate action mentioned in above.

In my case, the appropriate action to trigger tooltip is one click on the disabled Radio button.

Other things I've tried:

Still can't figure out.

More Information:

It doesn't have to be Tooltip, please advise any appropriate solution. I am new to Flutter/Dart, I hope I have explained the issue clearly.

Thank you.

mtv_piba
  • 67
  • 1
  • 8

1 Answers1

12

You can show Tooltip whenever user Taps on RadioButton in following way.

Following is the code for your reference: Run on DartPad

import 'package:flutter/material.dart';

main() => runApp(MaterialApp(home: MyApp()));

class MyApp extends StatelessWidget {

  GlobalKey _toolTipKey = GlobalKey();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: GestureDetector(
            onTap: () {
              final dynamic tooltip = _toolTipKey.currentState;
              tooltip.ensureTooltipVisible();
            },
            child: Tooltip(
              key: _toolTipKey,
              message: 'button is disabled',
              child: Radio(
                groupValue: null,
                onChanged: null,
                value: null,
              ),
            ),
          ),
      ),
    );
  }
}

enter image description here

Kalpesh Kundanani
  • 5,413
  • 4
  • 22
  • 32