Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dart's DirectoryEntry.getFile with 'options' parameter throws NoSuchMethodError

I tried using a piece of dart code creating a file with HTML5 file API. The code was found on some dart slides, slightly fixed to be able to run under M1. I'm using latest Dart SDK 0.2.1.2_r14167. Code is simple (I also tried calling it with last two parameters (callbacks) set with the same result).

import 'dart:html';

void main() {
  window.webkitRequestFileSystem(LocalWindow.TEMPORARY, 50*1024*1024, (fs) {
    fs.root.getFile('log.txt', {"create": true}, null, null);
  });
}

It throws:

Exception: NoSuchMethodError: incorrect number of arguments passed to method named 'getFile' Receiver: Instance of '_DirectoryEntryImpl@0x33cc944a' Tried calling: getFile("log.txt", Instance of 'LinkedHashMapImplementation', null, null) Found: getFile(path, options, successCallback, errorCallback) Stack Trace: #0 Object.noSuchMethod (dart:core-patch:772:3)

Am I doing something wrong or SDK is broken?

like image 570
rgripper Avatar asked Feb 19 '26 14:02

rgripper


1 Answers

Yes you are doing it basically wrong, but I wouldn't blame you since even the IDE seems to do it the way you are doing it!

Here's how to do it properly:

import 'dart:html';

void main() {
  window.webkitRequestFileSystem(LocalWindow.TEMPORARY, 50*1024*1024, (DOMFileSystem fs) {
    fs.root.getFile('log.txt', options: {'create': true}, successCallback: (FileEntry e) {
      print(e.fullPath);
    });
  });
}

It uses named parameters and the signature for getFile is:

void getFile(String path, {Map options, EntryCallback successCallback, ErrorCallback errorCallback});

So, if you look carefully, the first parameter is compulsory, but the rest aren't and in fact can be specified in any order as long as you specify them by their names.

If you are still confused, read about the named parameters.

like image 140
Kai Sellgren Avatar answered Feb 22 '26 04:02

Kai Sellgren



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!