beingmathematician
beingmathematician

Reputation: 119

Giving color from Colors class as a parameter in Flutter

class colorSymbol extends StatelessWidget {
  final Colors color;
  
  colorSymbol(Colors this.color,  {Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Icon(
      Icons.accessibility,
      color: ,
      size: 64.0,
    );
  }
}

The code simply return a accessibility icon from Icons and I want this widget to change its color which is given by user. I created a variable from Colors class called color but I cannot move on. Thanks in advance

Upvotes: 0

Views: 53

Answers (2)

Alain C. Jiménez
Alain C. Jiménez

Reputation: 416

You should change your parameter type from Colors to Color :

    import 'package:flutter/material.dart';
    
    class colorSymbol extends StatelessWidget {
      final Color color;
      
      colorSymbol(Color this.color,  {Key? key}) : super(key: key);
    
      @override
      Widget build(BuildContext context) {
        return Icon(
          Icons.accessibility,
          color: color,
          size: 64.0,
        );
      }
    }

Upvotes: 1

Md. Yeasin Sheikh
Md. Yeasin Sheikh

Reputation: 63569

You like to have Color instead of Colors.

class colorSymbol extends StatelessWidget {
  final Color color;
  const colorSymbol(this.color, {super.key}) ;

Upvotes: 1

Related Questions