Openapi-generator: [REQ] Can this tool used for generating flutter mobile api code?

Created on 2 Aug 2019  路  4Comments  路  Source: OpenAPITools/openapi-generator

Use generated api classes for mobile flutter dev

This is my flutter doctor:

[鉁揮 Flutter (Channel beta, v1.6.3, on Mac OS X 10.14.5 18F132, locale en-CN)
[鉁揮 Android toolchain - develop for Android devices (Android SDK version 28.0.3)
[鉁揮 iOS toolchain - develop for iOS devices (Xcode 10.3)
[鉁揮 Android Studio (version 3.4)
[鉁揮 VS Code (version 1.36.0)
[鉁揮 Connected device (1 available)

I'm trying to use this tool to generate the api code which give these files.
Screen Shot 2019-08-02 at 18 18 19

And when i import these files to flutter project, i want to use api_client to instead of my code.
Compiler gives me this :

Compiler message:
file:///Users/xxxx/flutter/.pub-cache/hosted/pub.dartlang.org/http-0.12.0+2/lib/src/browser_client.dart:97:25: Error: Type 'HttpRequest' not found.
  void _openHttpRequest(HttpRequest request, String method, String url,
                        ^^^^^^^^^^^
file:///Users/xxxx/flutter/.pub-cache/hosted/pub.dartlang.org/http-0.12.0+2/lib/src/browser_client.dart:32:25: Error: 'HttpRequest' isn't a type.
  final _xhrs = new Set<HttpRequest>();
                        ^^^^^^^^^^^
file:///Users/xxxx/flutter/.pub-cache/hosted/pub.dartlang.org/http-0.12.0+2/lib/src/browser_client.dart:46:19: Error: Method not found: 'HttpRequest'.
    var xhr = new HttpRequest();
                  ^^^^^^^^^^^
file:///Users/xxxx/flutter/.pub-cache/hosted/pub.dartlang.org/http-0.12.0+2/lib/src/browser_client.dart:57:45: Error: Method not found: 'Blob'.
      var blob = xhr.response == null ? new Blob([]) : xhr.response;
                                            ^^^^
file:///Users/xxxx/flutter/.pub-cache/hosted/pub.dartlang.org/http-0.12.0+2/lib/src/browser_client.dart:58:24: Error: Method not found: 'FileReader'.
      var reader = new FileReader();

I checked the lib, seems the 'dart:html' is not used for flutter mobile development.

Could you add support for mobile? Or maybe i missed something?

Thank you.

Dart Question

All 4 comments

I'm no expert in Dart. Let's see if the Dart technical committees have an answer to your question: @ircecho (2017/07) @swipesight (2018/09) @jaumard (2018/09)

I'm no expert in Dart. Let's see if the Dart technical committees have an answer to your question: @ircecho (2017/07) @swipesight (2018/09) @jaumard (2018/09)

Thanks. I think i solved the problem. I removed the 'dart: html', and edit the 'api_client.mustache' file, change 'browserClient' to 'BaseClient'...and it works...thanks anyway. I will close this for now, if there is no other issues.

@YLoveX I don't know about the default dart generator, but the dart jaguar generator can be used with flutter, I use it on multiple projects. If you want to give it a try ^^

@YLoveX I don't know about the default dart generator, but the dart jaguar generator can be used with flutter, I use it on multiple projects. If you want to give it a try ^^

@jaumard, thank you for your suggestion, I will give it a try. ^ ^

Was this page helpful?
0 / 5 - 0 ratings