skip to Main Content
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

2

Answers


  1. You like to have Color instead of Colors.

    class colorSymbol extends StatelessWidget {
      final Color color;
      const colorSymbol(this.color, {super.key}) ;
    
    Login or Signup to reply.
  2. 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,
            );
          }
        }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search