flutter text with icon
To display text with an icon in Flutter, you can use the Text
widget along with the Icon
widget. Here's an example:
import 'package:flutter/material.dart';
class MyWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Flutter Text with Icon'),
),
body: Center(
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(Icons.star), // Replace 'star' with the desired icon
SizedBox(width: 8), // Add some spacing between the icon and text
Text(
'Hello World',
style: TextStyle(fontSize: 20),
),
],
),
),
);
}
}
In this example, the Icon
widget is used to display an icon (in this case, the star icon) and the Text
widget is used to display the text "Hello World". The SizedBox
widget is used to add some spacing between the icon and the text. You can replace the 'star' icon with any other icon from the available icon set in Flutter.
Please note that you need to have the flutter/material.dart
package imported in your file for this code to work.