Slidable(
groupTag: 0,
key: UniqueKey(),
endActionPane: ActionPane(
children: [
SlidableAction(
onPressed: (BuildContext context) {
//whatever I will do here
},
icon: Icons.delete
)// SvgPicture.asset(Assets.svg.trash.svg()),)
],
),
child: _makeColumnTile(
myCard,
),
);
This is just a basic slidable item, which I am doing for every list item I have. I understand, and can work with slidable and listTile. However, I want to put my own custom svg file I saved in my assets folder, not pre-built Icons. But the icon: is apparently only wanting IconData
I tried putting svg directly with SvgPicture.asset(Assets.svg.trash.svg()), but the error is
The argument type SvgPicture can't be assigned to the parameter type IconData?,
also when I want to assign Icon to icon, this error pops up.
The argument type 'Icon' can't be assigned to the parameter type 'IconData?.
I understand why I cannot assign those properties, but isn't there any way I could solve this problem?
The SlidableAction only accepts IconData in its icon property. A list of MaterialIcons is available here.
SlidableAction(
icon: Icons.archive,
),
For your use case, you can instead use a CustomSlidableAction (check the package's API reference here).
CustomSlidableAction (
child: //Your action's icon or label.
)
You can pass your SVG as a child to it.
Flutter can't generate IconData from svgs. You must convert it to a ttf file and use it as your icon source.
You can use an online converter like https://fluttericon.com or do it locally with a package like https://pub.dev/packages/icon_font_generator
Then import it as following in your pubspec.yaml:
fonts:
- family: MyIcons
fonts:
- asset: assets/fonts/MyIcons.ttf
Then pass the Icon to your widget:
SlidableAction(
onPressed: (_) {},
backgroundColor: Color(0xFFFE4A49),
foregroundColor: Colors.white,
icon: MyIcons.Delete,
label: 'Delete',
),
Related
I am trying to create a backspace button (using an ElevatedButton()). I don't want the button to be circular, but instead have the same shape as the icon. Also, when tapping the button, I want the splash effect to be the same size and shape as the button.
I've attached a reference image below of the shape I'm trying to replicate.
Extra challenge: I'm also trying to set the fill color of the button to be black and the color of the button to be grey (like the example).
You can use the IconButton() widget instead of ElevtaedButton() as well as defining the splashRadius to change the size of the splash effect:
IconButton(
splashRadius: 1, // Set the Size of the splash area
color: Colors.grey,
icon: Icon(Icons.backspace),
onPressed: () {},
),
Result:
Or, if you want to use ElevatedButton(), use the .icon constructor:
ElevatedButton.icon(
style: ElevatedButton.styleFrom(primary: Colors.grey.shade300),
label: Text('Hello World'),
icon: Icon(
Icons.backspace,
color: Colors.grey,
),
onPressed: () {},
)
Result:
There are many default icons in class Icons are not good-looking for your app. You can use some design platform, such as Figma, then download it as svg. Then the code could be:
InkWell(
onTap: () {},
child: SvgPicture.asset(path_to_svg_icon)
)
This way, you can edit color, shape, style... for your icon. Good luck!
I use vscode + flutter plugin. Why 'title' in BottomNavigationBarItem or 'RaisedButton' are crossed out by flutter?
BottomNavigationBarItem(icon: Icon(Icons.map_outlined), title: Text("help"))
vscode screen
They are being deprecated, which means that the Flutter Team now recommends that you don't use them anymore, and gives you some alternatives.
For BottomNavigationBarItem's title property, use the label property instead:
BottomNavigationBarItem(icon: Icon(Icons.map_outlined), label: "help")
and for the RaisedButton, now use ElevatedButton:
ElevatedButton(onPressed: () => null, child: Text("Click Me"));
Also, with the ElevatedButton styling has become a little different.
To style an ElevatedButton use:
ElevatedButton(
onPressed: () => null,
child: Text("Click Me"),
style: ElevatedButton.styleFrom(primary: Colors.green, etc....)
);
Put this code in pubspec.yaml
flutter_svg: ^0.19.3
Even I put in assets these
assets:
- assets\icons\logo.jpg
- assets\icons\menuicon.svg
- assets\icons\searchIcon.svg
In code it looks like this
IconButton(
icon: Icon(Icons.searchicon.svg),
onPressed: () {},
The Icon parameter accept any kind of widget not only Icon So you can use any widget like below
IconButton(icon: SvgPicture.asset(
assetName,
color: Colors.red,
semanticsLabel: 'Label'
),onPressed: () {},
I saved the google logo a as .png because I want to keep its colors. I am aware there are some packages for predefined sign-in buttons like google or with the google Icon(but I can't keep the colors obviously in this case), but I would like to know if I can somehow make so the .png image acts like an Icon.
You can use whatever button widget you like or you can create your custom button...
According to your image you can use outline button or flat button... then in your child parameter add Row with image and text
OutlineButton(child: Row(children: Image.asset(your_image_location), Text('Sign in with Google')))
body: Stack(
children: <Widget>[
Center(
child: IconButton(
icon: Image.asset('path/the_image.png'),
iconSize: 50,
onPressed: () {},
)
Positioned(
child: Container(
child: Center(child: Text('Sign in With Google')),
)),
],
)
Just noticed that ListTile cover button animation when wrapped inside a container with background color set to anything but transparent. Wrapping ListTile in a container with set color is the only way I know to change background color of ListTile. Is there any other way to change background color of the ListTile without loosing button animation?
Container(
color: Colors.green,
child: ListTile(
title: Text('Test'),
trailing: IconButton(
icon: Icon(Icons.add),
onPressed: () {},
),
),
)
OUTPUT
This is because of the way InkWell works (Some buttons, like the IconButton, use InkWell or InkResponse as their parent). You can read about it more on this github issue page.
In order to make that ripple effect to display on top of the decorated Container (the green one in your code) - it needs a Material widget above the Container in the widget display tree.
So you should edit the code and add a Material widget with transparency in your Container, so the widget display tree will look like Container -> Material -> Ink.
Container(
color: Colors.green,
child: Material(
type: MaterialType.transparency,
child: ListTile(
title: Text('Test'),
trailing: IconButton(
icon: Icon(Icons.add),
onPressed: () {},
),
),
),
),