floatingActionButton shows but figure is empty - flutter

Hello This is my code:
floatingActionButton: FloatingActionButton(onPressed:(){
Icon(Icons.edit);
} ,),
The problem is, when i add any icon (like icons.edit or icons.alarm etc.), it shows empty circular button.

floatingActionButton: FloatingActionButton(
onPressed: () {
//do something
},
child: Icon(Icons.edit),
),
This is because you are putting the Icon inside on onPressed. OnPressed is code that executes when the button is pressed, add a child Icon widget.

You haven't added a child to the FloatingActionButton.
Specify the child property of FloatingActionButton
floatingActionButton: FloatingActionButton(
child: Icon(Icons.edit, color: Colors.white),
onPressed:(){
// onPressed function
},
),

Related

How to get tap event inside absorb pointer

I have a page containing many widgets which is opened in view only mode. i used AbsorbPointer for ignoring user inputs. but in some cases i have to get onTap event on one button which is inside AbsorbPointer. how can i achieve that ?
I tried using GestureDetector but its not giving onTap event.
any idea??
AbsorbPointer(
absorbing:true,
child: Column(children: [
Text("HELLO"),
Text("HELLO 2"),
GestureDetector(
onTap: () {
showToast("I tried this");
},
child: IconButton(
icon: Icon(
Icons.local_offer,
color: Colors.red,
),
onPressed: () {
print("I need this event");
},
),
)
]),
);
use absorbing: property for your cases... set it to false in the case you want to allow the GestureDetector inside

TextButton.icon and ElevatedButton.icon: is it possible to show the label first then the icon?

I can't seem to find a parameter that lets the widgets TextButton.icon and ElevatedButton.icon place the label first then the icon. Is there a way or do I have to make a custom widget for this?
Example:
ElevatedButton.icon(
onPressed: () { /* code */ },
icon: Icon(Icons.arrow_forward),
label: Text('Some text'),
)
Both icon & label accepts a Widget. So you could do this:
ElevatedButton.icon(
icon: Text('A'),
label: Icon(Icons.add),
onPressed: () {},
),

How can I implement tap-able Text widget, Flutter?

I have a Text widget on pressing which another Route has to be shown. But I could not see any onPressed() method for the Text widget. Please Help.
In your case there are multiple routes where you can go.
Using material TextButton:
TextButton(onPressed: () {}, child: Text('Your child'))
Using InkWell Widget, which covers your widget with 'as button' properties, splashes etc, which allows you to have more customisable buttons taps:
InkWell(onTap: () {}, onDoubleTap: () {}, onLongPress: () {}, onHover: () {}, ..etc , child: Text('Your child widget'))
Using GestureDetector, is the most customisable solution for any gestures you can provide (from its name), can handle taps, long presses, double taps, drags etc.
Syntax is similar:
GestureDetector(onTap: () {}, child: Text('Your child widget'))
Try using TextButton widget:
TextButton(
onPressed: () {},
child: Text('Simple Button'),
),
The best way to make any widget tappable is to use GestrureDetector you just put it outside of the widget/widgets you want and you can use dozen of properties.
For example
GestureDetector(child:
onPressed: () {},
Text('Your text')
)

Flutter position Text in floating-action-button?

Is there anyway that I can position text in the extended floating action button.
For example I want to position text at the right corner of the button.
How can I do this ?
Thank you for your help.
The FloatingActionButton in the Scaffold accepts a widget. So you can do something like this:
floatingActionButton: Stack(
children: [
FloatingActionButton.extended(
// label cannot be null, but it's a widget
// so it can be an empty container or something else
label: Text("button"),
icon: Icon(Icons.add),
onPressed: () {},
),
Positioned(right: 0.0, top: 0.0, child: Text("text")),
],
),
try to wrap Text Widget with Padding or set padding to floating action button.

Long hold on back arrow of action bar in flutter shows a "Back" toast, how to remove that?

How to remove the toast displayed on the Action bar in a flutter on Long hold on back arrow.
In your appBar you can replace the leading parameter by what you want.
Try replacing it with :
AppBar(
leading: IconButton(
icon: Icon(Icons.arrow_back),
onPressed: () {
Navigator.of(context).pop();
},
),
),
It should remove the tooltip. If you want to customize it, see the tooltip parameter of IconButton
Use an IconButton as leading widget of your AppBar like,
Scaffold(
appBar: AppBar(
leading: IconButton(
onPressed: () {
Navigator.of(context).pop();
},
icon: Icon(Icons.arrow_back),
// tooltip: 'Back', // this cause the overlay
),
),
);