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'),
]
)
Related
I have created a resources folder to store my images.
part of 'resources.dart';
class IconImages {
IconImages._();
static const String test1 = 'assets/images/test1.jpg';
static const String test2 = 'assets/images/test2.jpg';
static const String test3 = 'assets/images/test3.jpg';
}
I write them to the Map collection
final imagesIcon = <int, String>{
1: IconImages.test1,
2: IconImages.test2,
3: IconImages.test3,
};
and then pass the recorded images to the button.
icon: Image(image: AssetImage(imagesIcon.values.toString())),
// full button
Column(
children: [
Container(
color: Colors.lightBlueAccent,
child: IconButton(
icon: Image(image: AssetImage(imagesIcon.values.toString())),
onPressed: () {},),
),
SizedBox(height: 40,),
Container(
color: Colors.lightBlueAccent,
child: IconButton(
icon: Image(image: AssetImage(imagesIcon.values.toString())),
onPressed: () {},),
),
SizedBox(height: 40,),
Container(
color: Colors.lightBlueAccent,
child: IconButton(
icon: Image(image: AssetImage(imagesIcon.values.toString())),
onPressed: () {},),
),
],
),
When I execute my code, I get the following exception
Everything works when I transmit the image in this form
icon: Image(image: AssetImage(IconImages.test2)),
But when I try to get a path from Map in this way, the above error is obtained
icon: Image(image: AssetImage(imagesIcon.values.toString())),
You are using your map wrong:
IconButton(
icon: Image(image: AssetImage(imagesIcon[1].toString())),
onPressed: () {},
),
I think it may be because you're passing icons as strings. Instead of using images with a class like:
ImageIcon(
AssetImage("images/icon.png"),
color: Colors.red,
size: 24,
),
Edit: after recreating the situation in my project I've found the reason behind that. You use imagesIcon.values.toString() to pass the value of an Icon. Did you check what this function returns? In my case it returned:
(assets/images/test1.jpg, assets/images/test2.jpg,
assets/images/test3.jpg)
No wonder the image is unreadable according to flutter because that is not a proper path or file.
Instead you can use your solution like this:
imagesIcon.values.elementAt(1) //0,1,2 whatever index you need from map
I want to add a filter option button without adding a search bar.
ScreenShot
You can do like this
InkWell(
onTap: () =>
child: const Icon(
Icons.tune,
color: Colors.grey,
),
),
Make use of IconButton like below
IconButton(
icon: Icon(Icons.tune),
onPressed: () {},
)
(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
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: () {},
),
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),
),
],
)