skip to Main Content

Greetings iam working on a flutter app( mobile + web + desktop)
my backend is asp.net core
when iam trying to call my API (on mobile and desktop) it works perfectly but when I am calling from the web (chrome) iam get this error

Unsupported operation: Platform._version

my question is it something related to flutter or asp.net core
i really did some research but none helped can someone help me in that

2

Answers


  1. Chosen as BEST ANSWER

    The all idea is to enable CORS on the web api here is what you need to do in Startup.cs Go to ConfigureServices and add this code

     services.AddCors(options =>
            {
                options.AddPolicy("AllowAll",
                    builder => {
                        builder
                                            .AllowAnyHeader()
                                            .AllowAnyMethod()
                         .AllowAnyOrigin();
                   });
            });
    

    now in the Configure method add this code

      app.UseCors("AllowAll");
    

    also in every controller you need to add [EnableCors] this worked for me


  2. The issue is most likely related to using dart:io which is not compatible with web.

    If you post the full stack trace we can get a better idea.

    Try using https://pub.dev/packages/universal_io instead or even better https://pub.dev/packages/dio

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search