1

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

2
  • 2
    can you show us the code so far? Commented Mar 19, 2022 at 16:12
  • 1
    All fine I forgot an "," behind the ")" before :D Commented Mar 19, 2022 at 16:39

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.