Skip to content

Instantly share code, notes, and snippets.

@demirdev
Created June 28, 2025 19:47
Show Gist options
  • Select an option

  • Save demirdev/35c4e5f88d7f03b9ab66af2d15633916 to your computer and use it in GitHub Desktop.

Select an option

Save demirdev/35c4e5f88d7f03b9ab66af2d15633916 to your computer and use it in GitHub Desktop.
Ensures a Flutter app always uses the correct local IP for backend access, even when the IP changes. Run it before every flutter run command.
#!/bin/bash
TARGET_FILE=./lib/local_constants.dart
IP_ADDRESS=$(ifconfig en0 | grep 'inet ' | awk '{ print $2 }')
content="const localBaseURL = 'http://$IP_ADDRESS';"
if [ -f $TARGET_FILE ]; then
if [ "$(cat $TARGET_FILE)" != "$content" ]; then
echo "File exists and content is not the same"
echo "$content" > $TARGET_FILE
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment