Error: Dart library ‘dart:ui’ is not available on this platform.
import ‘dart:ui’ show lerpDouble;
im trying to run a dummy flutter project and it shows me error it is not running properly i want it to run properly
erorr arise is
Error: Dart library ‘dart:ui’ is not available on this platform.
import ‘dart:ui’ show lerpDouble;
2
Answers
The ‘dart:ui’ library can only be used when running code in a Flutter context. If you try to import it in other environments like a Dart command line app or web app, you’ll get an error that the library is not available.
To fix this:
Double check that you are running the code in a Flutter app or package by using flutter run or similar. Dart UI code won’t work outside of Flutter!
Instead of importing dart:ui, you need to import the Flutter equivalent:
Then access any UI capabilities like lerpDouble() through the Flutter libraries:
The key points are:
Flutter UI code must run in a Flutter environment
Import package:flutter/rendering.dart instead of dart:ui
Use the Flutter libraries to access UI functions
Follow those steps and you should be able to fix the error! Let me know if you have any other questions and If my answer helps you don’t forget to vote 🙏️.
In order to avoir this kind of issues when running on several platform, you can do this.
Create a file to be imported where you need your widget(your_widget.dart):
Create a common file (your_widget_common.dart):
And then create files by platform (your_widget_mobile.dart):
(your_widget_web.dart):
Now, when calling your_widget.dart, you will automatically switch to the correct platform implementation of your widget.