To add an icon alongside text in Flutter, you should not directly embed an Icon widget inside a Text widget. Instead, you should use a layout widget like Row, Wrap or Text.rich to place them inside text button.
Solution from google search.
Using Wrap:
Wrap(
crossAxisAlignment: WrapCrossAlignment.center,
children: [
Text('Click'),
Icon(Icons.add),
Text('to add'),
],
)
Using Row:
Row(
mainAxisSize: MainAxisSize.min,
children: [
Text('Click'),
Icon(Icons.add),
Text('to add'),
],
)
Using Text.rich:
Text.rich(
TextSpan(
children: [
TextSpan(text: 'Click'),
WidgetSpan(child: Icon(Icons.add)),
TextSpan(text: 'to add'),
],
),
)
Here is my own code solution – placed icon with button with text.
SizedBox(width:8,),
// button2
SizedBox(
// padding: const EdgeInsets.symmetric(vertical: 16),
child: ElevatedButton(
style: ElevatedButton.styleFrom(
backgroundColor: const Color.fromARGB(255, 81, 81, 82),
//minimumSize: const Size(double.infinity, 250),
foregroundColor: Colors.white,
//padding: EdgeInsets.symmetric(horizontal: 50, vertical: 20),
textStyle: TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold)),
onPressed: () {
/* Navigator.push(
context,
MaterialPageRoute(builder: (context) => const MyApp_register()),
);*/
},
child: Wrap(
crossAxisAlignment: WrapCrossAlignment.center,
children: [
Text('Cancel'),
Icon(Icons.delete),
],
),
),
),

Leave a Reply