Home > Net >  How to get color inside a function that returns a widget?
How to get color inside a function that returns a widget?

Time:07-16

I am learning flutter, I am trying to do something like 'values/color.xml' (which is used in android studio) to keep my colors in a file so that i can use them throughout my app easily. i have stored them in a class but when i use it inside a function that returns widget the colors are not appearing.

Color Values Class:

import 'package:flutter/material.dart';

class ColorValues {
  static Color highlightColor = const Color(0xFF202d35);
}

my function:

Container currentPage() {
    return Container(
      height: 20.0,
      width: double.infinity,
      child: Text("index"),
      color: ColorValues.highlightColor, //Doesn't work.
      color: Colors.Black, // But this works perfectly.
    );
  }

Inside this container widget i will be displaying the index of current page of PageView. I am using ColorValues.highlightColor inside my build function and it is working fine there. help me please.

Thank you.

CodePudding user response:

Try this once. Remove the static keyword and if you are working in flutter then rename your color file as color.dart not as color.xml

CodePudding user response:

just rename your color file as color_value.dart not color.xml, it's will be ok.

  • Related