Skip to content

Instantly share code, notes, and snippets.

@chooyan-eng
Last active December 10, 2021 05:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chooyan-eng/12c73011cbc6ef2d081803b64da86cc9 to your computer and use it in GitHub Desktop.
Save chooyan-eng/12c73011cbc6ef2d081803b64da86cc9 to your computer and use it in GitHub Desktop.
Shell script for create Flutter sample project of given Widget
#!/bin/bash
if [ $# -ne 1 ]; then
echo "USAGE: a single Widget name must be given as an argument. See example below" 1>&2
echo "USAGE: sh flutter_creater.sh InkWell" 1>&2
exit 1
fi
WIDGET_NAME=$1
WIDGET_NAME_LOWER=`echo ${WIDGET_NAME} | tr '[:upper:]' '[:lower:]'`
FOLDER_NAME="mysample_${WIDGET_NAME_LOWER}"
BASE_URL="https://api.flutter.dev/flutter/"
CATEGORY="material"
STATUS_CODE_MATERIAL=`curl -s ${BASE_URL}/${CATEGORY}/${WIDGET_NAME}-class.html -o /dev/null -w '%{http_code}\n' -s`
if [ $STATUS_CODE_MATERIAL -ne 200 ]; then
CATEGORY="widgets"
fi
CREATE_COMMAND=`curl --silent https://api.flutter.dev/flutter/${CATEGORY}/${WIDGET_NAME}-class.html | grep snippet-create-command | sed 's/<span class="snippet-create-command">//' | sed 's/<\/span>//' | sed "s/mysample/${FOLDER_NAME}/"`
if [ -z "$CREATE_COMMAND" ]; then
echo "ERROR: create command not found."
exit 1
fi
# FIXME: `sh $CREATE_COMMAND` causes an error for some reason
curl --silent https://api.flutter.dev/flutter/${CATEGORY}/${WIDGET_NAME}-class.html | grep snippet-create-command | sed 's/<span class="snippet-create-command">//' | sed 's/<\/span>//' | sed "s/mysample/${FOLDER_NAME}/" | sh
cd $FOLDER_NAME
flutter run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment