From a53b4f0c2491a704f5bc914e41de009abdc9b9dc Mon Sep 17 00:00:00 2001 From: Trevor Wang Date: Mon, 23 Oct 2023 14:15:50 +0800 Subject: [PATCH] fix: fix #630 Null check operator used on a null value --- example/lib/auth_client.dart | 38 ++++++++++++++++++++++++++++++++ generator/CHANGELOG.md | 6 +++++ generator/lib/src/generator.dart | 2 +- 3 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 example/lib/auth_client.dart diff --git a/example/lib/auth_client.dart b/example/lib/auth_client.dart new file mode 100644 index 000000000..0cf926c39 --- /dev/null +++ b/example/lib/auth_client.dart @@ -0,0 +1,38 @@ +import 'package:dio/dio.dart'; +import 'package:retrofit/retrofit.dart'; + +part 'auth_client.g.dart'; + +@RestApi() +abstract class AuthClient { + factory AuthClient(Dio dio, {String? baseUrl}) = RestClientYmlp; + + @POST('/api/auth/mqttClient/authentication') + Future authenticationUsingPost({ + @Body() required RegisterModel submitModel, + }); +} + +class RegisterModel { + const RegisterModel({ + this.channel, + this.mobile, + this.verfiyCode, + }); + + factory RegisterModel.fromJson(Map json) => RegisterModel( + channel: json['channel'] as String?, + mobile: json['mobile'] as String?, + verfiyCode: json['verfiyCode'] as String?, + ); + + final String? channel; + final String? mobile; + final String? verfiyCode; + + Map toJson() => { + 'channel': channel, + 'mobile': mobile, + 'verfiyCode': verfiyCode, + }; +} diff --git a/generator/CHANGELOG.md b/generator/CHANGELOG.md index b842163c2..136cbba5d 100644 --- a/generator/CHANGELOG.md +++ b/generator/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 8.0.2 + +- fix #630 Null check operator used on a null value + ## 8.0.1 - Add option class-name to customize the name of retrofit generator @@ -10,6 +14,7 @@ - Add PreventNullToAbsent annotation to allow null sent to server ## 7.0.8 + - Use `toJson()` instead of `.name` if enums have `toJson()`. ## 7.0.7 @@ -20,6 +25,7 @@ ## 7.0.6 - Fix DateTime.toIso8601String() issue #586 + ## 7.0.3 - Add support for analyzer 6.0.0 diff --git a/generator/lib/src/generator.dart b/generator/lib/src/generator.dart index de3691f7c..35cf5e920 100644 --- a/generator/lib/src/generator.dart +++ b/generator/lib/src/generator.dart @@ -849,7 +849,7 @@ You should create a new class to encapsulate the response. ) .statement, ); - } else if (returnType.toString() == 'dynamic') { + } else if (returnType is DynamicType || returnType.isDartCoreObject) { blocks ..add( declareFinal(_resultVar)