Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to import library in DartPad?

Tags:

dart

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?

like image 755
Ramin Bateni Avatar asked Sep 22 '20 17:09

Ramin Bateni


People also ask

How do you add a library to DartPad?

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."

How do I import files to Dart?

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.

How do I import libraries from another package in Dart?

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:

What is the use of import statement in Dart?

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.

How do I use a library Uri in Dart?

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.

How do I find the dependencies of a dart package?

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:


2 Answers

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

like image 189
Danny Tuppeny Avatar answered Oct 20 '22 22:10

Danny Tuppeny


After waiting... It seems that the issue has solved by the new update of dartpad.dev website.

enter image description here

like image 43
Ramin Bateni Avatar answered Oct 20 '22 22:10

Ramin Bateni