0

My flutter project used to run fine but after I update my flutter sdk to 3.3.4 I am getting two errors and couldn't compile the project.

The argument type 'EdgeInsets' can't be assigned to the parameter type 'Margins?'.

FittedBox(
                      child: Html(
                        data: article.title,
                        style: {
                          'body': Style(
                            margin: EdgeInsets.zero,
                            padding: EdgeInsets.zero,
                            fontSize: _articleTileFont(context),
                            lineHeight: const LineHeight(1.4),
                            fontWeight: FontWeight.bold,
                            maxLines: 3,
                            textOverflow: TextOverflow.ellipsis,
                          ),

I am using EdgeInsets.zero in multiple files but it is always throwing a error after I have updated.

EdgeInsets Error

Another Error I am getting is:

The constructor being called isn't a const constructor.

FontSize _articleTileFont(BuildContext context) {
    if (Responsive.isMobile(context)) {
      return const FontSize(25);
    } else if (Responsive.isTabletPortrait(context)) {
      return const FontSize(48);
    } else if (Responsive.isTablet(context)) {
      return const FontSize(65);
    } else {
      return const FontSize(25);
    }
  }

The constructor being called isn't a const constructor.

There is the same error on many pages. Please help me.

2
  • Neither Style nor FontSize are classes in the flutter framework. It must be from some package you use. Upgrading flutter is not what caused this, but the upgrading of that package
    – Ivo
    Oct 17, 2022 at 10:41
  • Thank You. But what can I do now can you help me????
    – Punkkk
    Oct 17, 2022 at 10:48

2 Answers 2

0

You can just remove the const wherever it complains about it. And you can replace

margin: EdgeInsets.zero,

with

margin: Margins.zero,

These are changes in the flutter_html package that you are using

5
  • Thank You It worked can you help me for another one: The constructor being called isn't a const constructor.
    – Punkkk
    Oct 17, 2022 at 10:55
  • @Punkkk just remove the word const
    – Ivo
    Oct 17, 2022 at 10:55
  • Thank You !!! Solved. Huge FAN of yours.
    – Punkkk
    Oct 17, 2022 at 13:30
  • Can I ask you one more thing ? I am getting error "There's no constant named 'NORMAL' in 'WhiteSpace'." ( Code: whiteSpace: WhiteSpace.NORMAL,)
    – Punkkk
    Oct 17, 2022 at 18:36
  • @Punkkk that should be WhiteSpace.normal. in small letters. It's really not hard to see yourself. When something doesn't exist just look at what does exist. Writing WhiteSpace. will give you suggestions of what could go after it. Or simply look at what WhatSpice looks like by ctrl + clicking it
    – Ivo
    Oct 18, 2022 at 6:18
0

1.You can try to add const in your code like

margin: const EdgeInsets.zero,

2.You have to remove const so that you text size will be responsive

FontSize _articleTileFont(BuildContext context) {
       if (Responsive.isMobile(context)) {
       return  FontSize(25);
     } else if (Responsive.isTabletPortrait(context)) {
      return  FontSize(48);
    } else if (Responsive.isTablet(context)) {
      return  FontSize(65);
      } else {
         return  FontSize(25);
     }
      }
2
  • I tried as you say. But its not working. Can you please help me?
    – Punkkk
    Oct 17, 2022 at 10:47
  • are you using any packages in this class?
    – Buddy
    Oct 17, 2022 at 10:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.