Dart/Flutter JsonWebclient and Unknown Types - Works in Android

I have a flutter app, very basic and have published an android and web version. The code is the same except for the JsonServiceClient vs JsonWebClient. I tested against the android app first and added all the necessary unknown types. It works great. The web version (published via flutter build web) however is throwing this error. There is no type Listminified:cx in the project, that is some reference to something internal.

As a side note, I can see the network requests, they are all correct in the browser.

Before logging a ticket in Github I wanted to get some feedback.

Uncaught Invalid argument(s): Unknown Type 'List<minified:cx>', see: https://docs.servicestack.net/dart-add-servicestack-reference#generating-unknown-types
    at Object.a (https://localhost:44317/inhouse/main.dart.js?v=2817320789:2599:3)
    at ie.gkA (https://localhost:44317/inhouse/main.dart.js?v=2817320789:47195:20)
    at n1.eU (https://localhost:44317/inhouse/main.dart.js?v=2817320789:47292:5)
    at Object.aE (https://localhost:44317/inhouse/main.dart.js?v=2817320789:6928:18)
    at fh.N (https://localhost:44317/inhouse/main.dart.js?v=2817320789:46814:7)
    at Object.eval (eval at a6k (https://localhost:44317/inhouse/main.dart.js?v=2817320789:2739:8), <anonymous>:3:37)
    at https://localhost:44317/inhouse/main.dart.js?v=2817320789:47489:5
    at a0I.a (https://localhost:44317/inhouse/main.dart.js?v=2817320789:4007:72)
    at a0I.$2 (https://localhost:44317/inhouse/main.dart.js?v=2817320789:25004:23)
    at Object.aq (https://localhost:44317/inhouse/main.dart.js?v=2817320789:3993:20)

EDIT:
I think the issue is the minification and how the SS classes are deserialized using their names. I’m going to confirm but I assume it would impact all apps using SS DTO’s that are built for production using flutter web build. I will try to confirm.

I confirmed that in order to use a flutter web project with SS generated DTO’s you won’t be able to run a production build. I assume that the TypeContext lookups by string name are getting mangled in the minifaction process so they aren’t found.

To temporarily solve this issue you can flutter build web --profile and it will create a non minified build.

I’m guessing that changing the DTO generation process won’t be easy… :frowning:

I’ve tested this with the https://todoworld.servicestack.net Hello World Service as per this Dart / Flutter Demo: https://www.youtube.com/watch?v=EwOwbZ9mUZk

Code added in the demo:

import 'package:servicestack/web_client.dart' if (dart.library.io) 'package:servicestack/client.dart';

//...

class _MyHomePageState extends State<MyHomePage> {
  String result = '';
  IServiceClient client = ClientFactory.create("https://todoworld.servicestack.net");

  Future<void> _callService() async {
    var response = await client.get(Hello()..name="Flutter");
    setState(() {
      result = response.result;
    });
  }

UI in build():

//...
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Text(
              'HTTP API Example',
            ),
            Text(
              '$result',
              style: Theme.of(context).textTheme.headline4,
            ),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _callService,
        tooltip: 'HTTP API Example',
        child: Icon(Icons.play_arrow),
      ), // This trailing comma makes auto-formatting nicer for build methods.

Built with

$ flutter build web

Then running a http-server in the build\web lets me call the API without issue:

It says flutter web is still in beta so may have to wait till it’s officially released to try working around any issues with tree shaking, but if you have a simple stand-alone repro I can take a quick look.

I’ll see if I can clean up a small demo but if I can suggest adding an autoquery service and/or something that returns a list to fully confirm it works.

You are right it is in beta and it updated recently.