0
Text(' '),
                  const Padding(
                    padding: EdgeInsets.only(left: 35.0),
                    child: Text(
                      'Cape Coast',
                      style: boldTextStyle(),
                    ),

After refractoring my TextStyle widget, It give an error of invalid constant value

Refactoring code is below

TextStyle boldTextStyle() {
    return const TextStyle(
      fontSize: 40,
      fontFamily: 'Dongle',
      fontWeight: FontWeight.w700,
    );
  }

1 Answers1

0

const means that the object's entire deep state can be determined entirely at compile time and that the object will be frozen and completely immutable.

On style: boldTextStyle(), this style can be archived on runtime. Remove const from Padding

 Padding(
          padding: const EdgeInsets.only(left: 35.0),
          child: Text(
            'Cape Coast',
            style: boldTextStyle(),
          ),
        )

More about const

Md. Yeasin Sheikh
  • 54,221
  • 7
  • 29
  • 56