0
votes

I was using Flutter version 1.25 (beta channel) and it worked just fine. After upgrading to version 2.0.0 and switching to stable channel i'm getting this error when i try to run the app either on mobile or web.

../../../AppData/Roaming/Pub/Cache/hosted/pub.dartlang.org/provider-3.2.0/lib/src/delegate_widget.dart:194:18: Error: Superclass has no method named 'inheritFromElement'.
    return super.inheritFromElement(ancestor, aspect: aspect);
                 ^^^^^^^^^^^^^^^^^^
../../../AppData/Roaming/Pub/Cache/hosted/pub.dartlang.org/provider-3.2.0/lib/src/provider.dart:259:19: Error: The method 'inheritFromWidgetOfExactType' isn't defined for the class 'BuildContext'.
 - 'BuildContext' is from 'package:flutter/src/widgets/framework.dart' ('/C:/flutter/packages/flutter/lib/src/widgets/framework.dart').
Try correcting the name to the name of an existing method, or defining a method named 'inheritFromWidgetOfExactType'.
        ? context.inheritFromWidgetOfExactType(type) as InheritedProvider<T>
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
../../../AppData/Roaming/Pub/Cache/hosted/pub.dartlang.org/provider-3.2.0/lib/src/provider.dart:260:19: Error: The method 'ancestorInheritedElementForWidgetOfExactType' isn't defined for the class 'BuildContext'.
 - 'BuildContext' is from 'package:flutter/src/widgets/framework.dart' ('/C:/flutter/packages/flutter/lib/src/widgets/framework.dart').
Try correcting the name to the name of an existing method, or defining a method named 'ancestorInheritedElementForWidgetOfExactType'.
        : context.ancestorInheritedElementForWidgetOfExactType(type)?.widget
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Unhandled exception:
NoSuchMethodError: The getter 'name' was called on null.
Receiver: null
Tried calling: name
#0      Object.noSuchMethod (dart:core-patch/object_patch.dart:54:5)
#1      ProgramCompiler._emitSuperTarget (package:dev_compiler/src/kernel/compiler.dart:5109:41)
#2      ProgramCompiler.visitSuperMethodInvocation (package:dev_compiler/src/kernel/compiler.dart:5102:24)
#3      SuperMethodInvocation.accept (package:kernel/ast.dart:5109:44)
#4      ProgramCompiler._visitExpression (package:dev_compiler/src/kernel/compiler.dart:3623:20)
#5      ProgramCompiler.visitAsExpression (package:dev_compiler/src/kernel/compiler.dart:5677:18)
#6      AsExpression.accept (package:kernel/ast.dart:6062:44)
#7      ProgramCompiler._visitExpression (package:dev_compiler/src/kernel/compiler.dart:3623:20)
#8      ProgramCompiler.visitReturnStatement (package:dev_compiler/src/kernel/compiler.dart:4152:38)
#9      ReturnStatement.accept (package:kernel/ast.dart:7786:43)
#10     ProgramCompiler._visitStatement (package:dev_compiler/src/kernel/compiler.dart:3551:20)
#11     MappedListIterable.elementAt (dart:_internal/iterable.dart:411:31)
#12     ListIterator.moveNext (dart:_internal/iterable.dart:340:26)
#13     new _GrowableList._ofEfficientLengthIterable (dart:core-patch/growable_array.dart:188:27)
#14     new _GrowableList.of (dart:core-patch/growable_array.dart:150:28)
#15     new List.of (dart:core-patch/array_patch.dart:50:28)
#16     ListIterable.toList (dart:_internal/iterable.dart:211:44)
#17     ProgramCompiler.visitBlock (package:dev_compiler/src/kernel/compiler.dart:3717:62)
#18     Block.accept (package:kernel/ast.dart:7048:43)
#19     ProgramCompiler._visitStatement (package:dev_compiler/src/kernel/compiler.dart:3551:20)
#20     ProgramCompiler._emitFunctionScopedBody (package:dev_compiler/src/kernel/compiler.dart:3562:18)
#21     ProgramCompiler._emitSyncFunctionBody.<anonymous closure> (package:dev_compiler/src/kernel/compiler.dart:3355:17)
#22     ProgramCompiler._withLetScope (package:dev_compiler/src/kernel/compiler.dart:2235:25)
#23     ProgramCompiler._withCurrentFunction (package:dev_compiler/src/kernel/compiler.dart:3389:18)
#24     ProgramCompiler._emitSyncFunctionBody (package:dev_compiler/src/kernel/compiler.dart:3351:17)
#25     ProgramCompiler._emitFunction (package:dev_compiler/src/kernel/compiler.dart:3165:11)
#26     ProgramCompiler._emitMethodDeclaration (package:dev_compiler/src/kernel/compiler.dart:1843:12)
#27     ProgramCompiler._emitClassMethods (package:dev_compiler/src/kernel/compiler.dart:1784:23)
#28     ProgramCompiler._emitClassDeclaration (package:dev_compiler/src/kernel/compiler.dart:658:21)
#29     ProgramCompiler._emitClass (package:dev_compiler/src/kernel/compiler.dart:580:21)
#30     List.forEach (dart:core-patch/growable_array.dart:403:8)
#31     ProgramCompiler._emitLibrary (package:dev_compiler/src/kernel/compiler.dart:529:23)
#32     List.forEach (dart:core-patch/growable_array.dart:403:8)
#33     ProgramCompiler.emitModule (package:dev_compiler/src/kernel/compiler.dart:394:15)
#34     JavaScriptBundler.compile (package:frontend_server/src/javascript_bundle.dart:144:33)
<asynchronous suspension>
#35     FrontendCompiler.writeJavascriptBundle (package:frontend_server/frontend_server.dart:632:5)
<asynchronous suspension>
#36     FrontendCompiler.compile (package:frontend_server/frontend_server.dart:545:9)
<asynchronous suspension>
#37     listenAndCompile.<anonymous closure> (package:frontend_server/frontend_server.dart:1105:11)
<asynchronous suspension>
Finished with error: the Dart compiler exited unexpectedly.
Failed to compile application.

I tried (from Android Studio) Tools > Flutter > Flutter Clean and File > Invalidate Caches / Restart... but it didn't help.

2
Use the dart fix to to migrate your Flutter project.Apealed
I ran dart fix --dry-run and it said Nothing to fix!Jrawat
It looks like your provider package is several versions out of date. You are on version 3.2.0 when the most recent release is 5.0.0. The older package is likely incompatible with the Flutter 2.0.0.Apealed
That worked thank you! Please write it as an answer so that i can set it as the correct answer. Also you can edit your last answer to precise that dart fix --dry-run should be executed from the Flutter SDK directory (I first executed it from my project directory)Jrawat
You will the latest version of dart to run dart fix with the --dry-run command: v2.12. HApealed

2 Answers

1
votes

From the dart.dev site.

The dart fix command (added in Dart 2.12) finds and fixes two types of issues:

  • Analysis issues that have associated automated fixes (sometimes called quick-fixes or code actions)
  • Issues that have associated package API migration information

To preview proposed changes, use the --dry-run flag:

$ dart fix --dry-run

To apply the proposed changes, use the --apply flag:

$ dart fix --apply

From Flutter 1.X to Flutter 2.X you will see breaking changes. Always review these changes before committing to the upgrade so you understand the changes.

0
votes

The package provider you're using is on version 3.2.0. It's likely that this package version is using incompatable methods, objects, etc with Flutter 2.0.0.

The latest version of provider is 5.0.0 which supports this new version of Flutter. Try upgrading the package to this version.