Skip to content

Instantly share code, notes, and snippets.

@suresh-kumara-gist
Created November 4, 2024 12:53
Show Gist options
  • Save suresh-kumara-gist/e73b2f26afe4df55328e79b97390c63b to your computer and use it in GitHub Desktop.
Save suresh-kumara-gist/e73b2f26afe4df55328e79b97390c63b to your computer and use it in GitHub Desktop.
create the Flutter project and set graddle version
```
#!/bin/bash
# Function to prompt for user input
prompt() {
read -p "$1" response
echo "$response"
}
# Get the directory to create the Flutter project
DIRECTORY=$(prompt "Enter the directory to create the Flutter project: ")
# Check if the directory exists, create it if it doesn't
if [ ! -d "$DIRECTORY" ]; then
echo "Directory does not exist. Creating directory: $DIRECTORY"
mkdir -p "$DIRECTORY"
if [ $? -ne 0 ]; then
echo "Failed to create directory. Exiting."
exit 1
fi
fi
# Change to the specified directory
cd "$DIRECTORY" || exit
# Get the project name
PROJECT_NAME=$(prompt "Enter the Flutter project name: ")
# Check if project name is provided
if [ -z "$PROJECT_NAME" ]; then
echo "Project name cannot be empty. Exiting."
exit 1
fi
# Create the Flutter project
flutter create "$PROJECT_NAME"
if [ $? -ne 0 ]; then
echo "Failed to create Flutter project."
exit 1
fi
# Ask for platforms to retain
PLATFORMS=$(prompt "Enter platforms to retain (android, ios, linux, web, macos, windows) separated by spaces: ")
# Define all possible platforms
ALL_PLATFORMS=("android" "ios" "linux" "web" "macos" "windows")
# Remove platforms not in the retain list
for PLATFORM in "${ALL_PLATFORMS[@]}"; do
if [[ ! " $PLATFORMS " =~ " $PLATFORM " ]]; then
if [ -d "$PROJECT_NAME/$PLATFORM" ]; then
rm -rf "$PROJECT_NAME/$PLATFORM"
echo "Removed $PLATFORM platform."
fi
fi
done
# Ask for Gradle version, default to 8.4 if empty
GRADLE_VERSION=$(prompt "Enter Gradle version (default is 8.4): ")
GRADLE_VERSION=${GRADLE_VERSION:-8.4}
# Change to the Android directory and set Gradle version
cd "$PROJECT_NAME/android" || exit
./gradlew wrapper --gradle-version="$GRADLE_VERSION"
if [ $? -ne 0 ]; then
echo "Failed to set Gradle version."
exit 1
fi
cd - || exit
# Ask for any packages to be installed
PACKAGES=$(prompt "Enter any packages to install (space-separated, or leave empty): ")
# If packages are provided, run flutter pub add
if [ -n "$PACKAGES" ]; then
# Change to the project directory
cd "$PROJECT_NAME" || exit
# Run flutter pub add with the provided packages
echo "Adding packages: $PACKAGES"
flutter pub add $PACKAGES
if [ $? -ne 0 ]; then
echo "Failed to add packages."
exit 1
fi
fi
# Initialize Git repository and make the first commit
cd "$PROJECT_NAME" || exit
git init
git branch -m master
git add .
git commit -m "first commit"
cd "$PROJECT_NAME"
echo "Flutter project '$PROJECT_NAME' created successfully!"
```
@suresh-kumara-gist
Copy link
Author

% ./create_flutter_project.sh 
Enter the directory to create the Flutter project: ContactEase
Enter the Flutter project name: voicy
Creating project voicy...
Resolving dependencies in `voicy`... (3.5s)
Downloading packages... 
Got dependencies in `voicy`.
Wrote 129 files.

All done!
You can find general documentation for Flutter at: https://docs.flutter.dev/
Detailed API documentation is available at: https://api.flutter.dev/
If you prefer video documentation, consider: https://www.youtube.com/c/flutterdev

In order to run your application, type:

  $ cd voicy
  $ flutter run

Your application code is in voicy/lib/main.dart.

The configured version of Java detected may conflict with the Gradle version in your
new Flutter app.

[RECOMMENDED] If so, to keep the default Gradle version 8.3, make
sure to download a compatible Java version
(Java 17 <= compatible Java version < Java 21).
You may configure this compatible Java version by running:
`flutter config --jdk-dir=<JDK_DIRECTORY>`
Note that this is a global configuration for Flutter.


Alternatively, to continue using your configured Java version, update the Gradle
version specified in the following file to a compatible Gradle version (compatible
Gradle version range: 8.4 - 8.7):
/Users/skn/Documents/fluttermobile/projects/ContactEase/voicy/android/gradle/wrapper/gr
adle-wrapper.properties

You may also update the Gradle version used by running
`./gradlew wrapper --gradle-version=<COMPATIBLE_GRADLE_VERSION>`.

See
https://docs.gradle.org/current/userguide/compatibility.html#java for details
on compatible Java/Gradle versions, and see
https://docs.gradle.org/current/userguide/gradle_wrapper.html#sec:upgrading_wrapper
for more details on using the Gradle Wrapper command to update the Gradle version
used.



Enter platforms to retain (android ios, linux, web, macos, windows) separated by spaces: android
Removed ios platform.
Removed linux platform.
Removed web platform.
Removed macos platform.
Removed windows platform.
Enter Gradle version (default is 8.4): 
Starting a Gradle Daemon, 1 busy and 1 incompatible and 1 stopped Daemons could not be reused, use --status for details

BUILD SUCCESSFUL in 2m 20s
5 actionable tasks: 5 executed
/Users/skn/Documents/fluttermobile/projects/ContactEase
Enter any packages to install (space-separated, or leave empty): 
Initialized empty Git repository in /Users/skn/Documents/fluttermobile/projects/ContactEase/voicy/.git/
[master (root-commit) 0ec9193] first commit
 Committer: SKN <[email protected]>
Your name and email address were configured automatically based
on your username and hostname. Please check that they are accurate.
You can suppress this message by setting them explicitly:

    git config --global user.name "Your Name"
    git config --global user.email [email protected]

After doing this, you may fix the identity used for this commit with:

    git commit --amend --reset-author

 27 files changed, 824 insertions(+)
 create mode 100644 .gitignore
 create mode 100644 .metadata
 create mode 100644 README.md
 create mode 100644 analysis_options.yaml
 create mode 100644 android/.gitignore
 create mode 100644 android/app/build.gradle
 create mode 100644 android/app/src/debug/AndroidManifest.xml
 create mode 100644 android/app/src/main/AndroidManifest.xml
 create mode 100644 android/app/src/main/kotlin/com/example/voicy/MainActivity.kt
 create mode 100644 android/app/src/main/res/drawable-v21/launch_background.xml
 create mode 100644 android/app/src/main/res/drawable/launch_background.xml
 create mode 100644 android/app/src/main/res/mipmap-hdpi/ic_launcher.png
 create mode 100644 android/app/src/main/res/mipmap-mdpi/ic_launcher.png
 create mode 100644 android/app/src/main/res/mipmap-xhdpi/ic_launcher.png
 create mode 100644 android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
 create mode 100644 android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
 create mode 100644 android/app/src/main/res/values-night/styles.xml
 create mode 100644 android/app/src/main/res/values/styles.xml
 create mode 100644 android/app/src/profile/AndroidManifest.xml
 create mode 100644 android/build.gradle
 create mode 100644 android/gradle.properties
 create mode 100644 android/gradle/wrapper/gradle-wrapper.properties
 create mode 100644 android/settings.gradle
 create mode 100644 lib/main.dart
 create mode 100644 pubspec.lock
 create mode 100644 pubspec.yaml
 create mode 100644 test/widget_test.dart
./create_flutter_project.sh: line 94: cd: voicy: No such file or directory
Flutter project 'voicy' created successfully!

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