Created
June 28, 2025 19:47
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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