Do not close ontap inside tooltip - flutter

How to have interactions inside a tooltip?
By default, as soon as you tap inside, it closes the toolip, except I would like to have clickable links for example:
Tooltip(
height: 50,
padding: const EdgeInsets.all(80),
richMessage: makeTooltip(context, issuerAddress, issuerName),
child: Text('Hover me'));
InlineSpan makeTooltip(BuildContext context, String address, String name) {
return WidgetSpan(
child: Column(
children: [
GestureDetector(
onTap: () {
Clipboard.setData(ClipboardData(text: address));
},
child: Text(
address,
),
),
const SizedBox(height: 5),
Text(name),
]),
);
}
Currently GestureDetector does not work, tooltip closes instead.

Have you tried using the GestureDetector with a Material? I'm assuming you want the tooltip to be dismissible as well.
child: Column(
children: [
GestureDetector(
onTap: () {
Clipboard.setData(ClipboardData(text: address));
},
child: Material(
child: InkWell(
child: Text(
address,
),
),
),
),
const SizedBox(height: 5),
Text(name),
]),
);

Related

Flutter - How to make the first element of a dynamic list fixed (unscrollable) at top?

PopupMenuButton<String>(
///Icon
child: SizedBox(
child: Stack(
children: [
const Icon(
Icons.notifications_outlined,
),
Container(
child: Container(
child: Padding(
padding: const EdgeInsets.all(0.0),
child: Center(
child: Text(
''
),
),
),
),
)
],
),
),
onSelected: (value) {},
itemBuilder: (BuildContext context) {
///generating list on the fly
var myList = someList!.map((listItem) {
return PopupMenuItem<String>(
value: listItem.id.toString(),
child: SizedBox(
child: Column(
children: [
Text(
listItem.name!,
),
],
),
),
);
}).toList();
var closeButtonList = [
PopupMenuItem<String>(
child: Column(
children: [
Align(
alignment: Alignment.centerRight,
child: IconButton(
onPressed: Navigator.of(context).pop,
icon: const Icon(
Icons.close,
),
),
),
],
),
),
///appending list using spread operator
...myList
];
return closeButtonList;
},
This code works fine and displays a cross(close) icon as the first element of the list.
The problem is when I scroll the list, the icon get scrolled and disappears from the screen.
How can I make it fixed while the rest of the list is scrollable?

flutter: how to customize cuperinoAlertDialog style?

I'm working with flutter. I want to make a CupertinoAlertDialog(iOS style is required). My problem is UI designers require the background color of the alert dialog should be #F0F0F0. But I can only adjust its theme into dark or light(e.g. following picture). The code I completed is placed below.
showCupertinoDialog(
context: context,
builder: (BuildContext context){
return Theme(
data: ThemeData.dark(),
child: CupertinoAlertDialog(
title: Text('Title'),
content: Text('Some message here'),
actions: <Widget>[
FlatButton(
onPressed: () {
Navigator.of(context).pop();
},
child: Text('Cancle'),
),
FlatButton(
onPressed: () {
Navigator.of(context).pop();
},
child: Text('OK'),
),
],
),
);
}
);
Is that possible? Thanks for any advice.
If I recall correctly, the background color for CupertinoAlertDialog is hardcoded. However, you can create a custom dialog that can change the background color of it as well as the functions of the buttons.
You need to create a type Dialog for the showDialog function instead of showCupertinoDialog:
Dialog customDialog = Dialog(
backgroundColor: Color(0xfff0f0f0), // your color
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(40)), // change 40 to your desired radius
child: CustomAlertDialog(),
);
I also created a stateless widget called CustomAlertDialog, but if you don't want to, you can replace the CustomAlertDialog() with its content.
class CustomAlertDialog extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Container(
height: 150,
child: Column(
children: [
Expanded(
flex: 2,
child: Container(
decoration: BoxDecoration(
border: Border(
bottom: BorderSide(color: Colors.grey, width: 1),
),
),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Container(
child: Center(
child: Text(
"Title",
style: TextStyle(
fontWeight: FontWeight.bold, fontSize: 20),
),
),
),
Container(
child: Center(
child: Text("Some message here"),
),
),
],
),
),
),
Expanded(
flex: 1,
child: Row(
children: [
Expanded(
flex: 1,
child: GestureDetector(
child: Container(
decoration: BoxDecoration(
border: Border(
right: BorderSide(color: Colors.grey, width: 1),
),
),
child: Center(
child: Text("Cancel"),
),
),
onTap: () {
Navigator.of(context).pop(); // replace with your own functions
},
),
),
Expanded(
flex: 1,
child: GestureDetector(
child: Container(
child: Center(
child: Text("OK"),
),
),
onTap: () {
Navigator.of(context).pop(); // replace with your own functions
},
),
),
],
),
),
],
),
);
}
}
Lastly, replace your whole showCupertinoDialog with this showDialog function:
showDialog(
barrierDismissible: true, // set false if you dont want the dialog to be dismissed when user taps anywhere [![enter image description here][1]][1]outside of the alert
context: context,
builder: (context) {
return customDialog;
},
);
Result: https://i.stack.imgur.com/cV13A.png

How to make a row clickable? Flutter

I want to make this row clickable to redirect to a different page, how should I do it?
There are a bunch of these rows in the code.
body:
Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
Container(
padding: EdgeInsets.all(10.0),
color: Colors.white,
),
Row(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
Container(
padding: EdgeInsets.fromLTRB(10,16,0,16),
color: Colors.white,
child: Icon(Icons.favorite),
),
Container(
padding: EdgeInsets.fromLTRB(5,20,140,20),
color: Colors.white,
child: Text('Favoritos'),
),
Container(
padding: EdgeInsets.fromLTRB(145,16,5,16),
color: Colors.white,
child: Icon(Icons.keyboard_arrow_right),
),
],
),
You can wrap your widget with GestureDetector or InkWell like this:
GestureDetector(
onTap: (){
// Add what you want to do on tap
}
child: Row(
// Add your properties here
),
),
InkWell(
onTap: (){
// Add what you want to do on tap
}
child: Row(
// Add your properties here
),
),
To make the row clickable you will have to wrap it to either inkwell or GestureDetector, else you can chose IconButtons.
InkWell(
onTap: (){ print("Card Clicked"); }
child: Container(
padding: EdgeInsets.fromLTRB(10,16,0,16),
color: Colors.white,
child: Icon(Icons.favorite),
),//Container
);
To go to different activity onTap try this code inside onTap():
onTap: (){
print("Card Clicked");
Navigator.push(
context,
MaterialPageRoute(builder: (context) => SecondRoute()),//secondRoute is the
//second class you want to go to.
}
You can use hardik's answer if you want to make clickable columns. Hope it helps! Happy coding:)

Flutter How to partially block touch event inside GestureDetector

I have a listview with every Item wrap inside a GestureDetector to be clickable, but is there a way to have a portion of the Item view to be not clickable? Thanks
GestureDetector(
onTap: () {
...
},
behavior: HitTestBehavior.opaque,
child: Column(
children: <Widget>[
child: SizedBox( height: 40,
child: Container(
color: Colors.green,
child: Text("Hello world"), // want to make the text area not clikable
),
),
someOtherWidgets...
],
),
Yes then you have to take particular item click and it should be blank in that case, Example InkWell click and child Text
InkWell(
onTap: () {
...
},
behavior: HitTestBehavior.opaque,
child: Column(
children: <Widget>[
child: SizedBox( height: 40,
child: Container(
color: Colors.green,
child: GestureDetector(
onTap: (){}
,
child:Text("PBX",style: TextStyle(fontSize: 15.0),)), // you can use like this text will be blank click
),
),
someOtherWidgets...
],
),

Logout in bottom drawer navigation flutter

I want to make logout and settings in bottom of drawer navigation but I have tried many suggestion but doesn't work at all
any suggestion?
This is my drawer navigation
Drawer(
child: ListView(
padding: EdgeInsets.zero,
children: <Widget>[
_createHeader(),
_createDrawerItem(icon: Icons.event, text: 'Event', onTap: () => Navigator.pushReplacementNamed(context, Routes.event)
),
Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
_createFooterItem(icon: Icons.event, text: 'Settings', onTap: () => Navigator.pushReplacementNamed(context, Routes.event)),
_createFooterItem(icon: Icons.event, text: 'Logout', onTap: () => Navigator.pushReplacementNamed(context, Routes.event))
],
),
],
),
);
this is my widget for header
Widget _createHeader() {
return DrawerHeader(
margin: EdgeInsets.zero,
padding: EdgeInsets.zero,
decoration: BoxDecoration(
image: DecorationImage(
fit: BoxFit.fill,
image: AssetImage('res/images/drawer_header_background.png'))),
child: Stack(children: <Widget>[
Positioned(
bottom: 12.0,
left: 16.0,
child: Text("Flutter Step-by-Step",
style: TextStyle(
color: Colors.white,
fontSize: 20.0,
fontWeight: FontWeight.w500))),
]));
}
and this is my widget for footer item
Widget _createFooterItem({IconData icon, String text, GestureTapCallback onTap}){
return ListTile(
title: Row(
children: <Widget>[
Icon(icon),
Padding(
padding: EdgeInsets.only(left: 8.0),
child: Text(text),
)
],
),
onTap: onTap,
);
}
You can change the ListView to a Column then add a Expanded widget with a child Container
Drawer(
child: Column( // Changed this to a Column from a ListView
children: <Widget>[
_createHeader(),
ListTile(title: Text('First item')),
Expanded(child: Container()), // Add this to force the bottom items to the lowest point
Column(
children: <Widget>[
_createFooterItem(
icon: Icons.event,
text: 'Settings',
onTap: () => Navigator.pushReplacementNamed(context, '/')),
_createFooterItem(
icon: Icons.event,
text: 'Logout',
onTap: () => Navigator.pushReplacementNamed(context, '/'))
],
),
],
),
);
Dart Pad Example