Kilikoo0
Kilikoo0

Reputation: 15

Dart Flutter display Icons

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

Upvotes: 1

Views: 1259

Answers (1)

Ravindra S. Patil
Ravindra S. Patil

Reputation: 14775

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

Refer Flutter 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,
      ),
    );
  }
}

Result screen-> image

You can also test the code on Dartpad.

Upvotes: 1

Related Questions