user19877113
user19877113

Reputation:

Colors not showing up in Flutter

I was trying to give my Container a Color but but it's saying, for example: red is not defined for the type 'Color'.

Does anyone know 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,
          )
        ],
      ),
    );
  }
}

Upvotes: 0

Views: 752

Answers (2)

Zeyad Mohamed
Zeyad Mohamed

Reputation: 84

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

Upvotes: 0

Dani3le_
Dani3le_

Reputation: 1463

It's Colors, not Color.

You can look up the Color Class on the official documentation.

Container(
  color: Colors.red,
)

Upvotes: 1

Related Questions