I have a problem. I want to add text below the Icon and I want to add a border with a background. How can I do that?
I don’t know how can I add a text inside the border with a background. What is the best option?
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import '../utils/definitions.dart';
import 'icons.dart';
import '../model/label.dart';
class LabelButton extends IconButton {
final Label? label;
//counter feedback!
LabelButton(
{required this.label, required VoidStringCallback? process, Key? key})
: super(
key: key,
icon: Icon(iconList
.firstWhere((element) => element.name == label!.uiIcon)
.icon),
iconSize: 80,
onPressed: () {
process!(label!.name);
HapticFeedback.lightImpact();
});
const LabelButton._(this.label, {Key? key})
: super(key: key, icon: const Icon(null), onPressed: null);
static LabelButton createBlank() {
return const LabelButton._(null);
}
}
What I tried:
I tried to change this with an ElevatedButton that I can use a background and label.
class LabelButton extends ElevatedButton {
final Label? label;
//counter feedback!
LabelButton(
{required this.label, required VoidStringCallback? process, Key? key})
: super(
key: key,
icon: Icon(iconList
.firstWhere((element) => element.name == label!.uiIcon)
.icon),
iconSize: 80,
label: Text('Test'),
child: ,
onPressed: () {
process!(label!.name);
HapticFeedback.lightImpact();
});
const LabelButton._(this.label, {Key? key})
: super(key: key, icon: const Icon(null), onPressed: null);
static LabelButton createBlank() {
return const LabelButton._(null);
}
}
2
Answers
You can create your own custom button and customise it.
If you want an icon with the text, then replace the Text with Row or Column and add an Icon widget.
Below is an example:
Use it like this wherever you need it.
Don’t forget to import the class like this.
Try out below code