Im writing my first code and I want to display a Icon, and I try to use the command Icon (Icons.star, color: Colors.red, size: 100, ),
. But it doesn't work. Can somebody help me. Thx
Welcome to Stackoverflow
. Try the following code. Your above code is also correct.
Try to check below line in your pubspec.yaml
file
flutter:
uses-material-design: true
ReferFlutter Icons
Full Example:
import 'package:flutter/material.dart';
void main() {
runApp(
MyApp(),
);
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
body: Center(
child: MyWidget(),
),
),
);
}
}
class MyWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Center(
child: Icon(
Icons.star,
color: Colors.red,
size: 100,
),
);
}
}
You can also test the code on Dartpad
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.