[FIXED] Why colors doesn't show in Flutter?

Issue

Hi I was trying to give my Container a color in Flutter but but it says "red" for Example is not defined for the type ‘Color’. Does anyone knows how to fix this?

import 'package:flutter/material.dart';
import 'package:color/color.dart';


class HomePage extends StatefulWidget {
  const HomePage({Key? key}) : super(key: key);

  @override
  State<HomePage> createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Stack(
        children: [
          Container(
            color: Color.red,
          )
        ],
      ),
    );
  }
}

Solution

import 'package:flutter/material.dart';
import 'package:color/color.dart';


class HomePage extends StatefulWidget {
  const HomePage({Key? key}) : super(key: key);

  @override
  State<HomePage> createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Stack(
        children: [
          Container(
            color: Colors.red,
          )
        ],
      ),
    );
  }
}

Answered By – Zeyad Mohamed

Answer Checked By – Mildred Charles (Easybugfix Admin)

Leave a Reply

(*) Required, Your email will not be published