Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Null check operator used on a null value package:source_gen/src/type_checker.dart 215:74 TypeChecker.isSuperTypeOf #735

Open
romanlapa opened this issue Jan 16, 2025 · 0 comments

Comments

@romanlapa
Copy link

romanlapa commented Jan 16, 2025

Describe the bug
I am getting this error when I try to generate a retrofit service.

Null check operator used on a null value
package:source_gen/src/type_checker.dart 215:74             TypeChecker.isSuperTypeOf

yaml:

name: data
description: "A new Flutter project."
version: 0.0.1
homepage:
publish_to: none

environment:
  sdk: ^3.5.1
  flutter: ">=1.17.0"

dependencies:
  flutter:
    sdk: flutter

  domain:
    path: ../domain

  shared_preferences: ^2.3.3
  dio: ^5.7.0
  retrofit: ^4.4.1
  logger: ^2.4.0  # for logging purpose
  json_annotation: ^4.9.0

dev_dependencies:
  flutter_test:
    sdk: flutter
  flutter_lints: ^4.0.0
  build_runner: ^2.4.13
  retrofit_generator: '>=8.0.0 <10.0.0' # for Dart 3.3 use ^9.0.0
  
global_options:
  freezed:
    runs_before:
      - json_serializable
  json_serializable:
    runs_before:
      - retrofit_generator

model:

class Token {

	Token(this.token);

	String? token;

	factory Token.fromJson(Map<String, String?> data) {
		if (data
		case {
		'token': String token,
		}) {
			return Token(token);
		} else {
			if (data['token'] is! String) {
				throw FormatException('Invalid JSON: required "token" field of type String in $data');
			}
			throw FormatException('Invalid JSON: $data');
		}
	}

	Map<String, String?> toJson() {
		// return a map literal with all the non-null key-value pairs
		return {
			'token': token,
		};
	}

}
Or like this:
import 'package:json_annotation/json_annotation.dart';

part 'token.g.dart';

@JsonSerializable()
class Token {

	Token(this.token);

	final String? token;

	factory Token.fromJson(Map<String, dynamic> json) => _$TokenFromJson(json);

	Map<String, dynamic> toJson() => _$TokenToJson(this);

}

service:

import 'package:data/models/Token.dart';
import 'package:dio/dio.dart';
import 'package:retrofit/retrofit.dart';

part '***.g.dart';

@RestApi(baseUrl: "https://dev-api.***.com")
abstract class AppRetrofitService {
  // helper methods that help you instanciate your service
  factory AppRetrofitService(Dio dio, {String baseUrl}) = _AppRetrofitService;

  @POST("/api/v1/login")
  Future<Token> login(@Body() Map<String, String> body);
  
}

To Reproduce
Steps to reproduce the behavior:
Run fvm dart run build_runner build --delete-conflicting-outputs or dart run build_runner build --delete-conflicting-outputs depends on do you use fvm or not.

Expected behavior
Successfuly generated class.

Additional context
Add any other context about the problem here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant