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 WebのアプリをLAN内の他のデバイスでデバッグする方法

Posted at

1. ローカルのIPアドレスを取得

ifconfig | grep "inet " | grep -v "127.0.0.1" | awk '{print $2}' | head -n 1

2. 取得したアドレスでアプリを立ち上げ

以下のコードのIP_ADDRESSに1で取得したアドレスを入れる

flutter run -d web-server --web-hostname=IP_ADDRESS --web-port=50505

上記をコマンド1つで行うジョブスクリプト

#!/bin/bash

# 実行端末以外のスマホなどでも同じ環境wi-fi下でデバッグを可能にする

# 1. ifconfigからローカルIPアドレスを取得し、変数に格納する
#    - grep -v "127.0.0.1" でループバックアドレスを除外
#    - awk '{print $2}' で2番目のフィールド(IPアドレス)のみを抽出
#    - head -n 1 で最初の1行だけを取得する
IP_ADDR=$(ifconfig | grep "inet " | grep -v "127.0.0.1" | awk '{print $2}' | head -n 1)

# 取得したIPアドレスが見つからない場合のエラー処理
if [ -z "$IP_ADDR" ]; then
  echo "ローカルIPアドレスの取得に失敗しました。"
  exit 1
fi

# 2. 取得したIPアドレスを使ってFlutterアプリを実行する
echo "IPアドレス: $IP_ADDR で開発サーバーを起動します..."
fvm flutter run -d web-server --web-hostname=$IP_ADDR --web-port=50505
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?