I wrote the below code in Dartpad and it return me this error:
Error compiling to JavaScript: unsupported import:
package:collection/collection.dart
import "package:collection/collection.dart";
main(List<String> args) {
var data = [
{"title": 'Avengers', "release_date": '10/01/2019'},
{"title": 'Creed', "release_date": '10/01/2019'},
{"title": 'Jumanji', "release_date": '30/10/2019'},
];
var newMap = groupBy(data, (obj) =>
(obj as dynamic)['release_date']
);
print(newMap);
}
Is there any way to resolve it?
From documentation: "DartPad supports dart:* libraries that work with web apps; it doesn't support dart:io or libraries from packages. If you want to use dart:io, use the Dart SDK instead. If you want to use a package, get the SDK for a platform that the package supports."
Give a filename to it and the extension should be . dart. Step 2: Go to your main file where you want to refer to your second file. Step 3: Now start writing “import” on the top of your “main.
To import libraries found in packages, use the package: prefix: The Dart runtime takes everything after package: and looks it up within the .packages file for your app. You can also use this style to import libraries from within your own package. Let’s say that the transmogrify package is laid out as follows:
Importing makes the components in a library available to the caller code. The import keyword is used to achieve the same. A dart file can have multiple import statements. Built in Dart library URIs use the dart: scheme to refer to a library. Other libraries can use a file system path or the package: scheme to specify its URI.
Built in Dart library URIs use the dart: scheme to refer to a library. Other libraries can use a file system path or the package: scheme to specify its URI. Libraries provided by a package manager such as the pub tool uses the package: scheme. If you want to use only part of a library, you can selectively import the library.
Use pub to get your package’s dependencies. If your Dart code depends on a library in the package, import the library. The pubspec is a file named pubspec.yaml that’s in the top directory of your application. The simplest possible pubspec lists only the package name:
It appears that importing packages is not currently supported. There's an open issue request this here:
https://github.com/dart-lang/dart-pad/issues/901
After waiting... It seems that the issue has solved by the new update of dartpad.dev website.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With