Flutterの学習がてら、bookmark-with-image(Electron + Vue.js)のFlutterへの移植に挑戦した。(ひとまずは一部分の機能のみであるが、移植版はbookmark_with_image_flutterに置いている。)この過程で学習した事項を以下に整理した。
Dartの基本を学ぶ
- Language tour
- Library tour
- Effective Dart:コーディングスタイルやドキュメンテーションなど
開発環境を構築する (Windows)
- zipファイルをダウンロードしてPATHを通せばOK。
- 参考:Flutter Docs - Windows install
- chocolateyのパッケージは残念ながらあまりメンテされていない。
- エディタはプラグラインが提供されているAndroid Studio, IntelliJ, VS Code, Emacsのいずれかを推奨とのこと。
Windowsアプリ(Beta)をビルドする
- WindowsアプリはBetaとしてサポートされている。
- 以下の手順でWindowsアプリのビルドを有効化できる。
- Flutterの設定でWIndowsを有効化する:
flutter config --enable-windows-desktop
- Visual Studio Community 2019をインストールする
- 新規プロジェクト作成時にWindowsを有効化するオプションを指定する:
flutter create --platforms=windows
- 既存のプロジェクトにDesktopを有効化することもできる。
- Flutterの設定でWIndowsを有効化する:
- ビルドしたアプリはMSIXインストーラーに固めることもができるが、手軽にzipファイルにで配布する方法も取れる。
画面(ページ)切り替えを実装する
- 以下のいずれかの方法で実現できる。
-
Navigate to a new screen and back
- Navigator.push()/Navigator.pop()で遷移・戻るを実装する。
-
Navigate with named routes
- MaterialAppのコンストラクタにてルーティング設定(initialRouteとroutes)を定義して、Navigator.pushNamed()でルートの名前指定で遷移する。
-
Navigate to a new screen and back
Widgetを跨いだ状態管理
トーストの出し方
- SnackBarを使えばよい。
URLを開く
-
url_launcherを使う。(参考)
スクレイピング
画像ファイルのダウンロード・保存
ウィンドウ幅に応じた折り返し表示
一部分のみスクロールバーを表示する
-
Expandedの子要素にSingleChildScrollViewを入れる。
- WindowsだとScrollのthicknessを指定してもマウスオーバー時の影は細いままになる。(不具合かも。)
- 参考:flutterで一部だけスクロールさせたい
Containerにクリックイベントを設定する
- InkWellもしくはGestureDetectorを使う。
OSのコマンドを実行する
- Process.start() を使う。
SQLiteでデータを永続化する
- モバイル + MacOSではsqfliteが定番だが、Windows/Linuxではsqflite_common_ffiを使えとのこと。
- API仕様はsqfliteとほぼ同じのようなのでドキュメントはここを見ればよさそう。
- ドキュメントにはリリースモードでは手動でsqlite3.dllを入れる必要あり、との記載があるが、入れなくてもちゃんと動いた。
- 参考:Persist data with SQLite