fluttergoogle-fontsflutter-text

Invalid Constant Value Text Flutter Google Fonts


I am having Text which i am styling with Google fonts and is working okay but when i add const before Text i get Invalid Constant Value Error

Below is how i have implemented without const


Text(
    'Voila',
     style: GoogleFonts.dawningOfANewDay(fontSize: 30),
),

Below is how i have tried implementing with const


const Text(
        'Voila',
         style: GoogleFonts.dawningOfANewDay(fontSize: 30),
),

Below is how i have tried making google fonts constant but the error still persists


const Text(
              'Voila',
              style: const GoogleFonts.dawningOfANewDay(fontSize: 30),
            )


Solution

  • You have to remove const from your code because constant values are expected to be hard coded but the font style or font family you are using is coming dynamically to const won't allow this.

    Text(
             'Voila',
             style: const GoogleFonts.dawningOfANewDay(fontSize: 30),
         )