1
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?

More than 1 year has passed since last update.

Flutter on the Web でモバイルの時だけいろいろ消える

Last updated at Posted at 2021-02-17

あらすじ

Flutter on the Web でアプリケーションを作成して、Serverにアップロードしました。
モバイルとデスクトップで挙動が違いましたが、ビルド設定を変えたら対応できました。

詳細

PC版Chromeでは正常に見れましたが、モバイルでいくつかのWidgetが消えてました。
モバイル版でも、「PC版サイトを見る」ボタンまたはチェックボックスを使うと、ちゃんと動きました。
具体的に消えていたのは、Appbar の Bottom に入れた Tab のタイトルや、Appbar title のSVG画像などです。

コマンド

flutterbuild コマンドで、canvaskit を指定すると正常に表示されることが分かりました。

flutter build web --web-renderer canvaskit --release

canvaskit の代わりに htmlauto を指定すると表示されなくなりました。
vscodeでのビルドタスクを見ると、
下記のようにデフォルトでは autoになっています。

.vscode/tasks.json
{
	"tasks": [
		{
			"type": "flutter",
			"command": "flutter",
			"args": [
				"build",
				"web",
				"--web-renderer=auto"
			],
			"group": {
				"kind": "build",
				"isDefault": true
			},
			"problemMatcher": [],
			"label": "flutter: flutter build web"
		}
	]
}

これでいいと思う

  • autocanvaskit に変える
  • args--release を足す
  • "group": {"kind": "build","isDefault": true},で、ショートカットキーが使える
    • Win : Ctrl+Shift+B
    • Mac : Shift++B
.vscode/tasks.json
{
	"tasks": [
		{
			"type": "flutter",
			"command": "flutter",
			"args": [
				"build",
				"web",
				"--web-renderer=canvaskit",
				"--release"
			],
			"group": {
				"kind": "build",
				"isDefault": true
			},
			"problemMatcher": [],
			"label": "flutter: flutter build web"
		}
	]
}

参考

Webレンダラー | Flutter

まとめ

  • まだbetaだけど、今のところsvgでしかバグに遭遇してない
  • SVGがちょっとめんどい(別記事を書こうかな)
  • 副産物というかcanvaskitにするとちょっと速い
  • そして--releaseにするとちょっと速い
  • flutter 最高
  • flutterでサボろうクロスプラットフォームしよう!

Excelsior!

1
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
1
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?