Add text button to tooltip Flutter - flutter

Is there a way to add a TextButton or Button to a Tooltip?
I want to display a summary in the Tooltip, with a link to an article that explains more about it.
Using a richMessage with a GestureDetector doesn't seem to work as tapping anywhere on the tooltip will close the tooltip instead of triggering the onTap:
Tooltip(
preferBelow: false,
padding: EdgeInsets.all(12.0),
showDuration: Duration(
seconds: 10,
),
richMessage: TextSpan(
text: "This is some basic info... ",
children: <InlineSpan>[
WidgetSpan(
alignment: PlaceholderAlignment.baseline,
baseline: TextBaseline.alphabetic,
child: GestureDetector(
onTap: (() {
bloc.launchURL(
LaunchLink.learnMore,
);
}),
child: TextButton(
child: Text(
'LEARN MORE',
style: TextStyle(color: Colors.blue),
),
onPressed: (() {
bloc.launchURL(
LaunchLink.learnMore,
);
}),
),
)),
const TextSpan(
text: '.',
),
],
),
triggerMode: TooltipTriggerMode.tap,
child: Icon(
Icons.info_rounded,
color: Color(AppColors.blue),
size: 18,
),
),

Assign a key to tool tip
final key = GlobalKey();
Tooltip(
key: key,
...
),
then on pressed you can make keep it visible like
onPressed: () {
final dynamic _tooltip = key.currentState;
_tooltip.ensureTooltipVisible();
},
and to close the tooltip you can use
tooltip.deactivate()

Related

How to make each _buildrow go the next page in Flutter?

i got problem when i dont know to make each buildrow go to each page?this is for buildDrawer can you help me with this?
builDrawer fuction this for profile screen.dart
_buildDrawer() {
return ClipPath(
clipper: OvalRightBorderClipper(),
child: Drawer(
Container(
height: 90,
alignment: Alignment.center,
decoration: BoxDecoration(
shape: BoxShape.circle,
gradient:
LinearGradient(colors: [Colors.pink, Colors.red])),
child: CircleAvatar(
radius: 40,
backgroundImage: NetworkImage(profile),
),
),
SizedBox(height: 5.0),
Text(
"Mohd Amin bin Yaakob",
style: TextStyle(color: Colors.white, fontSize: 18.0),
),
Text(
"Pegawai",
style: TextStyle(color: active, fontSize: 16.0),
),
SizedBox(height: 30.0),
_buildRow(Icons.home, "Home"),
_buildDivider(),
_buildRow(Icons.person_pin, "Your profile"),
_buildDivider(),
_buildRow(Icons.settings, "Settings"),
_buildDivider(),
_buildRow(Icons.email, "Contact us"),
_buildDivider(),
_buildRow(Icons.info_outline, "Help"),
_buildDivider(),
],
),
),
),
),
),
);
}
How to make Functional Navigator each buildRow
You need to make rows with clickable widgets like listtile.
Try this inside your _buildRow()
Widget _buildRow(IconData icon, String title) {
final TextStyle tStyle = TextStyle(color: active, fontSize: 16.0);
return ListTile(
title: Text( title, style: tStyle, ),
leading: Icon( icon, color: active, ),
onTap: () {
// Your navigation code here
},
);
}
You can remove the container as well and try contentPadding in ListTile
Its explained in the drawer documentation https://docs.flutter.dev/cookbook/design/drawer
You can require an onTap function in your _buildRow method. Also wrap you Container inside an InkWell widget and this function in onTap property.
Following is the revised code:
Widget _buildRow(IconData icon, String title, VoidCallback onTap) {
final TextStyle tStyle = TextStyle(color: active, fontSize: 16.0);
return InkWell(
child: Container(
padding: const EdgeInsets.symmetric(vertical: 8.0),
child: Row(
children: [
Icon(
icon,
color: active,
),
SizedBox(width: 10.0),
Text(
title,
style: tStyle,
),
],
),
),
onTap: onTap,
);
}
When calling the above function, provide the onTap callback like this:
_buildRow(Icons.home, "Home", () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) {
return HomePage();
},
),
);
});

Modal with centered title and right aligned close/X button

I recently picked up Flutter and Dart and am attempting to create an app that has a modal with three parts: a header, actual content, and a footer.
For the header I am looking to add a title (Text) center aligned and a close button right aligned.
I have the following code:
Column(
children: [
Row(
children: [
Expanded(
child: Text(
"Filters",
style: const TextStyle(
fontSize: 25,
fontWeight: FontWeight.bold,
),
textAlign: TextAlign.center,
),
),
IconButton(
icon: const Icon(Icons.close),
onPressed: () {
Navigator.pop(context);
},
),
],
),
],
),
)
Visually, this looks like so:
At a glance this looks fine but if you stare at it for a bit it doesn't. The "Filters" title isn't actually centered because (I assume) of the width of the X-button. I am struggling to figure out how to deal with this.
What is the proper way to solve this?
You can add empty SizedBox with width as much as IconButton takes, try this:
Row(
children: [
SizedBox(
width: width: 24 +
8 +
8, // the default size of icon + two default horizontal padding for IconButton
),
Expanded(
child: Text(
"Filters",
style: const TextStyle(
fontSize: 25,
fontWeight: FontWeight.bold,
),
textAlign: TextAlign.center,
),
),
IconButton(
icon: const Icon(Icons.close),
onPressed: () {
Navigator.pop(context);
},
),
],
),
or you can add on other IconButton with opacity 0 to hide the button and make title center, like this:
Row(
children: [
Opacity(
opacity: 0,
child: IconButton(
icon: const Icon(Icons.close),
onPressed: () {},
),
),
Expanded(
child: Text(
"Filters",
style: const TextStyle(
fontSize: 25,
fontWeight: FontWeight.bold,
),
textAlign: TextAlign.center,
),
),
IconButton(
icon: const Icon(Icons.close),
onPressed: () {
Navigator.pop(context);
},
),
],
),

Flutter: How to add two text lines to one button?

Dear Stackoverflow People,
I need to program a button in Flutter as follows:
How can I do that in Flutter?
I have the problem that TextButton() allows only to add "one line of text". However, I need a title and a description with different font sizes within a button. How can this be done?
Thanks a lot!
You can use Text.rich widget as a TextButton child. I tried on this online IDE and it works.In Text.rich , You can define List<TextSpan> children, and add text spans has different Text Styles . My code sample is here:
TextButton(
style: TextButton.styleFrom(
padding: const EdgeInsets.all(16.0),
primary: Colors.white,
textStyle: const TextStyle(fontSize: 20),
),
onPressed: () {},
child: const Text.rich(
TextSpan(
text: 'Hello', // default text style
children: <TextSpan>[
TextSpan(text: ' beautiful\n', style: TextStyle(fontStyle: FontStyle.italic)),
TextSpan(text: 'world', style: TextStyle(fontWeight: FontWeight.bold)),
],
),
),
)
Try below code hope its helpful to you. you can use Inkwell or GestureDetector Widget
InkWell(
onTap: () {
// write here your button pressed function
print('Button Pressed');
},
child: Container(
decoration: BoxDecoration(
border: Border.all(),
borderRadius: BorderRadius.circular(15.0),
),
child: ListTile(
title: Text('Language'),
subtitle: Text('Tap to change'),
),
),
),
Your result screen->
You could create your own button.
Something like this:
GestureDetector(
onTap: () {},
child: Container(
decoration: BoxDecoration(),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text("text big"),
Text("text small"),
],
),
),
),
You can give "Column" (with your text) to the "child" property of any button.
in your case OutlinedButton
OutlinedButton(
onPressed: () {},
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Language',
style: Theme.of(context).textTheme.subtitle1,
),
Text(
'Tap To Change',
style: Theme.of(context).textTheme.caption,
),
],
),
),
and then you can use the style properties of Test Widget to change their style
You can use this
Text("Language\nTap To Change")

Flutter Icon Button Speed Dial

Is there an existing speed dial widget that would work with regular buttons or any onclick event? I have found this widget which works great with the FloatingActionButton, but I need something that would work with an IconButton or RaisedButton. I tried using the SpeedDial Widget inside of a container, like so:
Container(
child: SpeedDial(
overlayOpacity: 0.2,
animatedIcon: AnimatedIcons.menu_close,
children: [
SpeedDialChild(
child: Icon(Icons.ac_unit),
label: 'Second',
onTap: () => print('SECOND'),
),
SpeedDialChild(
child: Icon(Icons.accessibility),
backgroundColor: Colors.red,
label: 'First',
labelStyle: TextStyle(fontSize: 18.0),
onTap: () => print('FIRST'),
),
],
),
),
But no luck, unfortunately. I get an infinity pixels on the right.
Please use padding in right and bottom side. Check the below code. You need to set a TextStyle for Text, you also need to use manual height and width for your child.
Padding(
padding: const EdgeInsets.fromLTRB(0, 0, 20, 20),
child: Container(
child: SpeedDial(
overlayOpacity: 0.2,
animatedIcon: AnimatedIcons.menu_close,
children: [
SpeedDialChild(
child: Icon(Icons.ac_unit),
label: 'Second',
onTap: () => print('SECOND'),
),
SpeedDialChild(
child: Icon(Icons.accessibility),
backgroundColor: Colors.red,
label: 'First',
labelStyle: TextStyle(fontSize: 18.0),
onTap: () => print('FIRST'),
),
],
),
),
)

Flutter: ShowDialog not working with the OnTap() method of a ListTile

I am using a drawer to create a menu that houses ListTiles for the options. I want to create a popup when the tiles are tapped by the user. Currently, the code displays nothing when the tiles are tapped even though after the showDialog there is a Navigator.pop().
// Drawer that includes the ListTiles in question
Drawer(
child: ListView(
padding: EdgeInsets.zero,
children: <Widget>[
DrawerHeader(
child: Text('Smash Tracker'),
),
),
ListTile(
title: Text(
'About',
style: TextStyle(
fontFamily: 'Smash',
fontSize: 15.0,
color: Color.fromRGBO(77, 114, 152, 1.0),
),
),
onTap: () {
// Show PopUp
showDialog(context: context, child:
new AlertDialog(
title: new Text(
'About',
style: TextStyle(fontFamily: "Smash"),
),
content: new Text(
'This is a placeholder. This is a placeholder. This is a placeholder. This is a placeholder.',
style: TextStyle(fontFamily: "Smash"),
),
)
);
// Doesn't run
Navigator.pop(context);
},
),
Here is a demo:
via GIPHY
The other ListTiles have the only have Navigator.pop() inside of their onTap() method.
The dialog isn't showing because you are popping it immediately with the Navigator.pop(context). You can await the Dialog since it returns a Future<T> before popping.
I added a demo using your widget tree as an example:
Drawer(
child: ListView(
padding: EdgeInsets.zero,
children: <Widget>[
DrawerHeader(
child: Text('Smash Tracker'),
),
ListTile(
title: Text(
'About',
style: TextStyle(
fontFamily: 'Smash',
fontSize: 15.0,
color: Color.fromRGBO(77, 114, 152, 1.0),
),
),
onTap: () async { // mark the function as async
print('tap');
// Show PopUp
// await the dialog
await showDialog(
context: context,
child: new AlertDialog(
title: new Text(
'About',
style: TextStyle(fontFamily: "Smash"),
),
content: new Text(
'This is a placeholder. This is a placeholder. This is a placeholder. This is a placeholder.',
style: TextStyle(fontFamily: "Smash"),
),
));
// Doesn't run
Navigator.pop(context);
},
),
],
),
),
OUTPUT: