0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Flutter OSによってimportエラーになりビルドできない対処法

Posted at

以下のように dart:html は Windows では使わないのにビルドするとエラーになります。

import 'dart:html' as html;

function() {
  if (!Platform.isWindows) {
    String hostname = html.window.location.hostname;
  }
}

エラー文
Dart library 'dart:html' is not available on this platform.

対処法

ダミーのファイル (win_html.dart) を作ります。

win_html.dart
class window {
  static Map<String, String> sessionStorage = {};
  static _location location = _location();
}

class _location {
  String hostname = '';
}

Windowsのときだけダミーファイルをimportします。これでビルドができるようになります。

import 'win_html.dart' if (dart.library.html) 'dart:html' as html;

function() {
  if (!Platform.isWindows) {
    String hostname = html.window.location.hostname;
  }
}

ios,androidのシミュレーターって重いですよね。Windowsでやると動作テストが楽です。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?