skip to Main Content

In my project(flutter app) there is a file named color.dart inside the folder helper which is inside the lib folder. The content of the color.dart file is not getting imported in the other files(import code line of color.dart file is indicating yellow line as to indicate it is not used and the lines in the code which uses the content of the color.dart file [for example ‘primary’ a color that is defined in the color.dart file] are showing errors everywhere throughout the project). What could be the reason for this and how can I resolve this?

tried cleaning the build, rebooting the system many times, running ‘pub get’/’pub upgrade’ and clearing temp folder[enter
(https://i.stack.imgur.com/xJKVl.png)
enter image description here

enter image description here

2

Answers


  1. The default color property in the material or Cupertino plugin name as color.dart and you make your own color.dart file and now flutter is getting confused about where it takes colors property. You can simply change your class name something else like customColor or anything but color.dart and use static color in you customized color class

    Login or Signup to reply.
  2. try editing your Colors.dart file like:

    
    import 'package:flutter/material.dart';
    
    const white = Colors.white;
    

    Or

    try this:

    import '../Helpers/Colors.dart' as myColors;
    

    then

    TextStyle(color: myColors.white)
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search