InterfaceType is not a subtype of Class in VariableGet
I have updated the flutter version to 1.20.2, and I have not encountered any problems, knowing that I use JsonSerializable
as well, try this:
Remove these files:
pubspec.lock
.packages
.flutter-plugins
.flutter-plugins-dependencies
then apply flutter pub get
command
xip
Updated on December 23, 2022Comments
-
xip over 1 year
Getting the following error when trying to build my app after upgrading to Flutter 1.20.1.
Unhandled exception: Crash when compiling null, at character offset null: InterfaceType(PagingResponse<Assignment*>*) is not a subtype of Class(Response) in VariableGet(response{PagingResponse<Assignment*>*}) #0 TypeEnvironment.typeError (package:kernel/type_environment.dart:164:7) #1 Expression.getStaticTypeAsInstanceOf (package:kernel/ast.dart:3037:10) #2 PropertyGet.getStaticType (package:kernel/ast.dart:3200:20) #3 transformAsExpression (package:kernel/transformations/type_casts_optimizer.dart:22:45) #4 _Lowering.visitAsExpression (package:vm/transformations/lowering.dart:65:12) #5 AsExpression.accept (package:kernel/ast.dart:4913:44) #6 VariableSet.transformChildren (package:kernel/ast.dart:3154:21) #7 Transformer.defaultTreeNode (package:kernel/visitor.dart:653:10) #8 TreeVisitor.defaultExpression (package:kernel/visitor.dart:144:43) #9 TreeVisitor.visitVariableSet (package:kernel/visitor.dart:148:43) #10 VariableSet.accept (package:kernel/ast.dart:3144:44) #11 ExpressionStatement.transformChildren (package:kernel/ast.dart:5794:31) // bunch of stack that doesn't look important #133 KernelTarget.buildComponent (package:front_end/src/fasta/kernel/kernel_target.dart:355:12) #134 IncrementalCompiler.computeDelta.<anonymous closure> (package:front_end/src/fasta/incremental_compiler.dart:274:28) <asynchronous suspension> #135 IncrementalCompiler.computeDelta.<anonymous closure> (package:front_end/src/fasta/incremental_compiler.dart) #136 CompilerContext.runInContext.<anonymous closure>.<anonymous closure> (package:front_end/src/fasta/compiler_context.dart:123:46) #137 new Future.sync (dart:async/future.dart:223:31) #138 CompilerContext.runInContext.<anonymous closure> (package:front_end/src/fasta/compiler_context.dart:123:19) #139 _rootRun (dart:async/zone.dart:1190:13) #140 _CustomZone.run (dart:async/zone.dart:1093:19) #141 _runZoned (dart:async/zone.dart:1630:10) #142 runZoned (dart:async/zone.dart:1550:10)
Assignment
is just a json_serializable model.Here's what
PagingResponse
looks like:@JsonSerializable() class PagingResponse<T> { PagingResponse( this.status, this.message, this.code, this.dataJson, ); String status; String message; String code; @JsonKey(ignore: true) PagingResponseData<T> data; @JsonKey(name: 'data') Map<String, dynamic> dataJson; factory PagingResponse.fromJson( Map<String, dynamic> json, PagingResponseDataDataGeneratorFunction<T> rowsFromJson, ) { PagingResponse<T> response = _$PagingResponseFromJson<T>(json); // Our API sometimes returns data directly and at other times nested under // another object. Check if data directly has a rows field. If not, this // probably means that data is nested inside an object. if (response.dataJson?.containsKey('rows') ?? false) { response.data = new PagingResponseData<T>.fromJson(response.dataJson); response.data.rows = rowsFromJson(response.data.rowsJson); } else if (response.dataJson?.isNotEmpty ?? false) { response.data = new PagingResponseData<T>.fromJson(response.dataJson.values.first); response.data.rows = rowsFromJson(response.data.rowsJson); } return response; } Map<String, dynamic> toJson() => _$PagingResponseToJson(this); } typedef List<T> PagingResponseDataDataGeneratorFunction<T>(List<dynamic> json);
Here's various versions:
[✓] Flutter (Channel stable, 1.20.1, on Mac OS X 10.15.4 19E287, locale en-US) • Flutter version 1.20.1 at /Users/------/dev/tools/flutter • Framework revision 2ae34518b8 (9 days ago), 2020-08-05 19:53:19 -0700 • Engine revision c8e3b94853 • Dart version 2.9.0
I'm omitting the rest of the
doctor
output as this happens for both Android and iOS builds.Looking around on the internet, I wasn't able to find anyone else with this issue who had a solution that applied. Here's some though:
- https://github.com/flutter/flutter/issues/48071
- https://github.com/dart-lang/build/issues/2478
- https://github.com/flutter/flutter/issues/33013
I tried:
- deleting every use of
PagingResponse<Assignment>
and running a build - got the same error message with a different model class; flutter clean
- deleting
~/.pub-cache
- various other stuff I don't remember at this point
If anyone has as much as an idea on what this could be even related to, I would appreciate it, as currently I'm looking at code and making blind changes in hope I get a hit. Especially some hints on what this Dart stack is about would be appreciated, if some more knowledgeable folks stumble upon this question.
UPDATE: Ended up opening an issue for this and we are heading towards a resolution there: https://github.com/flutter/flutter/issues/64155
-
farouk osama almost 4 yearsYou may also need to update your packages via "flutter pub upgrade" command
-
xip almost 4 yearsThank you for taking the time to answer. Unfortunately, the error persists.
-
farouk osama almost 4 yearsHow to show this error when building an application, It should appear when you invoke 'PagingResponse.fromJson'
-
xip over 3 yearsjson_serializable supports other json_serializable classes as class fields. The model presented in my question has no issues in that regard and it has been working fine for over 2 years now.
-
xip over 3 yearsDone all that and no dice.
-
Kapur over 3 yearsWhy don't you try upgrading first without having any code and then trying to rebuild your app?
-
xip over 3 yearsThe app consists of about 650 dart files, so it's not exactly an easy project to do that on. Anyway though, I updated the OP with a link to a Flutter issue, where the culprit was discovered. You might want to check it out.
-
Kapur over 3 yearsOk, I will make sure to do so!