How do I add two icons and multiple actions on a FAB in Flutter? - flutter

I want to add two icons on FAB Flutter, one icon will be a map(onPressed show map) and other icon will trigger showBottomModel. A kind of icon switch based floatingActionBar, I don't know if that is possible or please tell me a work around. Thanks.

You can use flutter_speed_dial package/dependency here or try below code hope its help to you.
floatingActionButton: Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
FloatingActionButton(
onPressed: () => {},
child: Icon(Icons.person),
),
FloatingActionButton(
onPressed: () => {},
child: Icon(Icons.home),
),
]
),
Your result screen ->

Related

not able to define web links that will open when icon button is pressed in listview builder which is already under expantionbar

(question1) i am not able to think how to pass 3 weblink link ( google.com, yahoo.com, youtube.com) that will open when 3 corresponding icons in topic 1 are pressed in code on :
https://github.com/sandeepnarula999/FlutterProjects/blob/main/ListViewUnderExpansionTile
pls try to share the complete code if u are able to resolve my issue ..as i shared full code above...pls do
not share just steps of how to do coz that may add up to errrors when i try
(question2)
As per below image suggestion when i try to change code from line 7 to 10 in abve code link i get errors.. are u able to get zero error with this below approach in image
Solution : add three Flexible widgets in the Row widget ;)
if (root.children.isEmpty) {
return ListTile(
title: Text(root.title),
subtitle: root.subtitle == null ? null : Text(root.subtitle!),
trailing: Row(
mainAxisSize: MainAxisSize.min,
children: [
Flexible(
child: IconButton(
onPressed: () {},
icon: const Icon(Icons.auto_stories),
iconSize: 30,
tooltip: 'Documents',
),flex: 1,
),
Flexible(
child: IconButton(
onPressed: () {},
icon: const Icon(Icons.video_collection_rounded),
iconSize: 30,
tooltip: 'Videos',
),
flex: 1,
),
Flexible(
child: IconButton(
onPressed: () {},
icon: const Icon(Icons.favorite),
iconSize: 20,
tooltip: 'Shortlist',
),flex: 1,
),
],
),
);
}
enter image description here

How do I change a flatbutton.icon to a textbutton in Flutter?

I have made a flatbutton icon, but it seems this is depreciated in the current flutter version. I have tried to upgrade it to a text button, but it does not show the text next to the icon.
This is the original code that has to be adapted to become a text button. Should I have to define a class or function to make it so?
Row(
children: [
FlatButton.icon(
onPressed: () => print('Live'),
icon: const Icon(
icons.videocam,
color: Colors.red,
),
label: Text('Live'),
),
],
)
Thx! :)
you can use TextButton.icon() widget. here an example:
TextButton.icon(
onPressed: () => print('Live'),
icon: Icon(Icons.videocam_rounded),
label: Text('Live'),
),
and here the result:
You can use an IconButton widget:
Row(
children: [
IconButton(
onPressed: () => print('Live'),
icon: const Icon(icons.videocam, color: Colors.red),
),
Text('Live'),
]
)

Is there anything like PostfixIcon for TextField in flutter

I've already tried PrefixIcon for TextField in flutter but this time I'm looking for something like Postfix Clickable Icon in flutter. I'm attaching the image and I want to achieve something like that.
Where the Icon is clickable and on clicking the Icon it will display the other TextField.
Here's the Image:
Use a suffixIcon. If that doesn't behave how you'd expect, you can always use a Stack.
You can use a Stack Widget to do that. it works similar to a Row or a Column but its Stacks its children on top of each other.
https://api.flutter.dev/flutter/widgets/Stack-class.html
what you are trying to do this something like this,
Stack(
alignment: Alignment.centerRight,
children: <Widget>[
TextField(),
IconButton(icon: Icon(Icons.add), onPressed: (){
//Code
})
],
),
You can use a Stack Widget #Srilal Sachintha
Stack(
alignment: Alignment.centerRight,
children: <Widget>[
TextFormField(),
IconButton(icon: Icon(Icons.add), onPressed: (){
//Code
})
],
),
or Use a suffixIcon. If that doesn't behave how you'd expect, you can always use a Stack. #

Multiple floating buttons - Flutter

it's possible to create a float action button which open more float buttons, and If yes, can you give me a example?
Like these :
Flutter gives a named parameter in Scaffold Widget - ‘floatingActionButton’. And the named parameter floatingActionButton shouldn't take only FloatingActionButton widget, it should take Widget and it does. So you can assign another widget instead of FloatingActionButton like as Column, Row, Stack. And it works.
floatingActionButton: Row(
children: [
RaisedButton(child: Text('Button1'), onPressed: (){}),
RaisedButton(child: Text('Button1'), onPressed: (){}),
]
),
I just give you a reference example, it will work - you just need to customize the styles and positioning as you want. Hope it will be helpful.
Using the SpeedDial widget provided by flutter_speed_dial package you can use multiple float button as children of a parent floating action button. You can also add animated icons.
In your pubspec.yaml under dependecies, add:
dependencies:
flutter_speed_dial: ^1.2.5
Now you can use the SpeedDial widget in your FAB:
floatingActionButton: SpeedDial(
//provide here features of your parent FAB
children: [
SpeedDialChild(
child: Icon(Icons.accessibility),
label: 'First',
onTap: null,),
SpeedDialChild(
child: Icon(Icons.accessibility),
label: 'Second',
onTap: null,),
...
]
),
Try This
floatingActionButton: Column(
mainAxisAlignment: MainAxisAlignment.end,
children: [
FloatingActionButton(
onPressed: getImage,
child: Icon(Icons.camera),
),
SizedBox(height: 8,),
FloatingActionButton(
onPressed: getImage,
child: Icon(Icons.camera),
),
],
)

Floating Action Button centerDocked, overlapping any screen or dialogue?

I am using animated icons in my FloatingActionButton (FAB) at bottom navigation bar. But FAB overlapping any page or dialogue open from the BottomAppBar, how can I resolve this?
When I open a new page with Navigator.push, Navigator.pushNamed, modalBottomSheet or a dialogue, the fab overlapping them.
Only works when I use pushReplacementNamed to open a new page.
How can I show the modalSheet without the fab on it and a page using just pushNamed?
I use this reference.
floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
floatingActionButton: _buildFab(context, model),
bottomNavigationBar: BottomAppBar(
color: CustomTheme.getThemeData(context).getAccentColor(),
shape: CircularNotchedRectangle(),
notchMargin: 4.0,
child: new Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
IconButton(
icon: Icon(Icons.menu),
onPressed: () => _showModal(),
),
IconButton(
icon: Icon(Icons.home),
onPressed: () => {},
),
],
),
),
This is my FAB
And this happen when a show the modal or any page
Please I need your help..
I don't know what else to do. :-(
If this is happening with the Modal bottom sheet then try to increase the elevation of the bottom sheet. Like this
showModalBottomSheet(context: context, builder: (context) {
return AddressChangeBottomSheet(
title: "Change Area",
showAddress: false,
cityAreaList: list, onAddressChangeSubmit: () {
mainBloc.fetchUpdatedUser();
});
}, elevation: 10.0)