Skip to content

Instantly share code, notes, and snippets.

@Ansh-Rathod
Last active November 11, 2023 08:25
Show Gist options
  • Select an option

  • Save Ansh-Rathod/9b72aa55ca8616b92d8bd5cdc731e1aa to your computer and use it in GitHub Desktop.

Select an option

Save Ansh-Rathod/9b72aa55ca8616b92d8bd5cdc731e1aa to your computer and use it in GitHub Desktop.
flutter auto hot reload script.
#!/bin/bash
chmod 777 ./hotreloader.sh
echo 'Script is running';
while true
do
find lib/ -name '*.dart' | entr -dnp ./hotreloader.sh /_
done
#!/bin/bash
set -euo pipefail
PIDFILES=($(compgen -G "/tmp/flutter*.pid"))
if [[ "${1-}" != "" && ${#PIDFILES[@]} > 0 ]]; then
echo $1
PIDS=""
for pf in ${PIDFILES[@]}; do
PIDS+=$(cat $pf)
PIDS+=" "
done
if [[ "$1" =~ \/state\/ || "$1" =~ backend ]]; then
echo "Restarting ${PIDS}"
kill -USR2 $PIDS
else
echo "Reloading ${PIDS}"
kill -USR1 $PIDS
fi
fi
#!/bin/bash
# Function to run flutter run in the background
run_flutter() {
flutter run --pid-file /tmp/flutter.pid
# When flutter run exits, exit the script
exit
}
# Run the hotreload.sh script
sh ./hotreload.sh &
# Run flutter run in the background
run_flutter
@Ansh-Rathod
Copy link
Copy Markdown
Author

brew install entr install this package first.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment