0
1

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でコミット時に自動フォーマットする方法(Windows)

Last updated at Posted at 2025-09-11

とても簡単で便利なので記事にします。
チーム開発でWindowsを使用している人向けです。

目次

1. 自動フォーマットを導入する人がやること
2. 他のメンバーがやること

1.自動フォーマットを導入する人がやること

Lefthookをインストールします。

winget install --id=evilmartians.lefthook -e

lefthook.ymlを生成します。

lefthook install

lefthook.ymlを編集します。
ステージングされている.dartファイルを成型するコマンドを走らせてます。

pre-commit:
  commands:
    format:
      glob: "*.dart"
      run: dart format {staged_files} && git add {staged_files}

設定を反映します

lefthook install

これで設定は完了です。

2.他のメンバーがやること

Lefthookをインストールします。

winget install --id=evilmartians.lefthook -e

プロジェクトでLefthookを有効化します。

lefthook install

以上。

追記(エラーの報告)

現在、Github DesktopやVSCodeの「Commit」ボタンを押すと、

C:/Users/.../flutter/bin/dart: No such file or directory

というエラーが出るようです。
VSCodeのターミナル上でコミットする場合は問題なく動きます。
GUIでのコミットが正しく動作しないようです。誰かこのエラーの原因がわかる人がいたら、情報提供してほしいです。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?