Flutter build fails on UnmodifiableUint8ListView from a package
Error: 'UnmodifiableUint8ListView' is restricted and can't be extended or implemented.Short answer
Dart deprecated the UnmodifiableUint8ListView family in 3.3 and removed it in 3.5. The replacement is the asUnmodifiableView() method. If the error points into a package cache path, an old dependency still uses the class, so upgrade it. If it points into lib/, change your own code.
Fix it fast
1Find out which cause you have
Read the file path printed above the error. A path under .pub-cache means a dependency; a path under your own lib/ means your code.
flutter pub outdated2Match what you see, then jump to its fix
- 1
The path in the error contains .pub-cache/hosted/pub.dev/<package>-<version>A dependency still uses the removed classFix - 2
The path in the error starts with lib/Your own code constructs the classFix - 3
dart pub upgrade keeps the old version; pub outdated shows a newer Latest than ResolvableConstraints in pubspec.yaml stop the fix from resolvingFix
- 1
What does the error look like?
Error: 'UnmodifiableUint8ListView' is restricted and can't be extended or implemented.
Cause 1 of 3
A dependency still uses the removed class
1Check
Find which package pulls it in; transitive dependencies are hidden unless you ask for them.
dart pub outdated --transitive
dart pub deps2Fix
Upgrade the named package, and the package that depends on it if it is only transitive. Upgrade just those packages first to keep other versions locked.
dart pub upgrade <package-name>
dart pub upgrade --unlock-transitive <package-name>3Verify
The build should compile past the old error.
flutter build apk --debugConfirmed by dart.dev
Cause 2 of 3
Your own code constructs the class
1Check
Search the project for the class and its siblings (the other Unmodifiable...View typed-data classes were removed together).
grep -rn "Unmodifiable.*View(" lib/2Fix
Replace the constructor call with the asUnmodifiableView() method, which exists since Dart 3.3.
// before
final view = UnmodifiableUint8ListView(bytes);
// after
final view = bytes.asUnmodifiableView();3Verify
Run the analyzer; the undefined class error should be gone.
dart analyzeConfirmed by raw.githubusercontent.com
Cause 3 of 3
Constraints in pubspec.yaml stop the fix from resolving
1Check
Resolvable is the newest version that fits every constraint. If it is lower than Latest, an upper bound is blocking the fixed release.
dart pub outdated2Fix
Preview, then allow the major upgrade. This rewrites constraints in pubspec.yaml, so commit first.
dart pub upgrade --major-versions --dry-run
dart pub upgrade --major-versions3Verify
Run pub outdated again; Upgradable should now match the version you wanted.
dart pub outdatedConfirmed by dart.dev
How do I stop it coming back?
- Run flutter pub outdated before every Flutter SDK upgrade and update packages in the same change.
- Commit pubspec.lock so builds use the same versions on every machine.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- Qist BazaarA buy-now-pay-later marketplace built from a blank repo, now past 100K downloads on Google Play.
- SessionBirdAn omnichannel engagement suite in Flutter: campaigns, chatbot, tickets, analytics and live calling.
Related fixes
Mobile apps
AudioCache has no play method after updating audioplayers
The method 'play' isn't defined for the type 'AudioCache'.
Since audioplayers 1.0, AudioCache only turns asset files into local files and caches them.
2 causes, each with a fixMobile apps
Flutter Bloc throws that emit was called after the event handler completed
emit was called after an event handler completed normally.
Each on<Event> handler gets its own Emitter, and it stops working the moment the handler's returned Future completes.
2 causes, each with a fixMobile apps
analysis_options.yaml: the URI it includes can't be found
include_file_not_found
The analyzer reports include_file_not_found when the file named after include: in analysis_options.yaml does not resolve.
2 causes, each with a fixMobile apps
Dart error: the body might complete normally and return null for a non-nullable type
body_might_complete_normally
Dart found a path through your function or callback that reaches the closing brace without a return.
3 causes, each with a fixMobile apps
Dart throws ConcurrentModificationError while looping over a list
ConcurrentModificationError
Dart throws this when a collection changes size while something iterates it.
2 causes, each with a fixMobile apps
Dart cannot turn a compact timestamp like 20201101153000 into a DateTime
FormatException: Invalid date format
DateTime.parse accepts a subset of ISO 8601, and a time part must be introduced by T or a space.
2 causes, each with a fix