From fcc2384a5e8a604e087457fff0f5e8b159ef311a Mon Sep 17 00:00:00 2001 From: Khushboo Verma Date: Fri, 8 Aug 2025 17:18:11 +0530 Subject: [PATCH 1/4] Fix build script for flutter --- README.md | 5 ++--- build.sh | 27 +++++++++++++++++---------- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 6c2f186..04d32d6 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ Alternatively, open the repository URL in `Android Studio` to clone it directly. ## 🛠️ Development Guide 1. **Configure Appwrite** - Navigate to `lib/data/repository/appwrite_repository.dart` and update the values to match your + Copy `.env.example` to `.env` and update the values to match your Appwrite project credentials. 2. **Customize as Needed** @@ -32,8 +32,7 @@ Alternatively, open the repository URL in `Android Studio` to clone it directly. integrations as per your needs. 3. **Run the App** - Select a target device (emulator or a connected physical device) in `Android Studio`, and - click **Run** to start the app. + Run by executing `./build.sh {device-name}` like `./build.sh chrome` --- diff --git a/build.sh b/build.sh index 91a0712..9cfec00 100755 --- a/build.sh +++ b/build.sh @@ -10,20 +10,27 @@ if [ ! -f .env ]; then fi # Read .env file and convert it to --dart-define arguments -ARGS="" +ARGS=() while IFS='=' read -r key value || [ -n "$key" ]; do # Ignore empty lines and comments if [[ -n "$key" && ! "$key" =~ ^# ]]; then - ARGS+=" --dart-define=${key}=\"${value}\"" + ARGS+=("--dart-define=${key}=${value}") fi done < .env -# Build Flutter web -eval flutter build web "$ARGS" - -# If --preview flag is provided, run a local preview server -if [ "$1" == "--preview" ]; then - echo "Starting preview server at http://localhost:3000..." - cd build/web || exit 1 - python3 -m http.server 3000 +# Check if device parameter is provided +if [ -z "$1" ]; then + echo "Usage: ./build.sh " + echo "Example: ./build.sh chrome" + echo "Example: ./build.sh 'iPhone 15'" + echo "" + echo "Available devices:" + flutter devices + exit 1 fi + +DEVICE_NAME="$1" + +# Run Flutter app on specified device +echo "Running Flutter app on device: $DEVICE_NAME" +flutter run -d "$DEVICE_NAME" "${ARGS[@]}" From c0cae9fcb7b19873d39129a9e8cd6f492f909381 Mon Sep 17 00:00:00 2001 From: Khushboo Verma Date: Fri, 8 Aug 2025 18:29:14 +0530 Subject: [PATCH 2/4] If no params passed, default to web --- build.sh | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/build.sh b/build.sh index 9cfec00..2f9c287 100755 --- a/build.sh +++ b/build.sh @@ -20,13 +20,9 @@ done < .env # Check if device parameter is provided if [ -z "$1" ]; then - echo "Usage: ./build.sh " - echo "Example: ./build.sh chrome" - echo "Example: ./build.sh 'iPhone 15'" - echo "" - echo "Available devices:" - flutter devices - exit 1 + echo "No device specified. Building for web..." + flutter build web "${ARGS[@]}" + exit 0 fi DEVICE_NAME="$1" From 9453e45cede4733bad1f065809f72b376263f05d Mon Sep 17 00:00:00 2001 From: Khushboo Verma Date: Fri, 8 Aug 2025 19:27:22 +0530 Subject: [PATCH 3/4] Simplify flutter starter --- .env.example | 3 -- README.md | 32 +++++++++++++++++--- build.sh | 32 -------------------- lib/config/environment.dart | 5 +++ lib/data/repository/appwrite_repository.dart | 7 +++-- prepare-env.sh | 13 ++++++++ 6 files changed, 50 insertions(+), 42 deletions(-) delete mode 100644 .env.example delete mode 100755 build.sh create mode 100644 lib/config/environment.dart create mode 100644 prepare-env.sh diff --git a/.env.example b/.env.example deleted file mode 100644 index 549edfc..0000000 --- a/.env.example +++ /dev/null @@ -1,3 +0,0 @@ -APPWRITE_PROJECT_ID= -APPWRITE_PROJECT_NAME= -APPWRITE_PUBLIC_ENDPOINT= diff --git a/README.md b/README.md index 04d32d6..3a1adf0 100644 --- a/README.md +++ b/README.md @@ -24,15 +24,39 @@ Alternatively, open the repository URL in `Android Studio` to clone it directly. ## 🛠️ Development Guide 1. **Configure Appwrite** - Copy `.env.example` to `.env` and update the values to match your - Appwrite project credentials. + Open `lib/config/environment.dart` and update the values with your Appwrite project credentials: + ```dart + class Environment { + static const String appwriteEndpoint = 'appwrite-endpoint'; + static const String appwriteProjectId = 'your-project-id'; + static const String appwriteProjectName = 'your-project-name'; + } + ``` 2. **Customize as Needed** Modify the starter kit to suit your app's requirements. Adjust UI, features, or backend integrations as per your needs. 3. **Run the App** - Run by executing `./build.sh {device-name}` like `./build.sh chrome` + Select a target device and run the app: + ```bash + # List available devices + flutter devices + + # Run on a specific device (replace 'device-id' with actual device) + flutter run -d device-id + + # Examples: + flutter run -d chrome # Web + flutter run -d "iPhone 15" # iOS Simulator + flutter run -d emulator-5554 # Android Emulator + flutter run -d macos # macOS Desktop + ``` + + **Build for Web:** + ```bash + flutter build web + ``` --- @@ -45,5 +69,5 @@ production : https://docs.flutter.dev/deployment ## 💡 Additional Notes -- This starter project is designed to streamline your Android development with Appwrite. +- This starter project is designed to streamline your Flutter development with Appwrite. - Refer to the [Appwrite Documentation](https://appwrite.io/docs) for detailed integration guidance. \ No newline at end of file diff --git a/build.sh b/build.sh deleted file mode 100755 index 2f9c287..0000000 --- a/build.sh +++ /dev/null @@ -1,32 +0,0 @@ -#!/bin/bash - -# Check if .env file exists -if [ ! -f .env ]; then - { - echo "APPWRITE_PROJECT_ID=$APPWRITE_PROJECT_ID" - echo "APPWRITE_PROJECT_NAME=$APPWRITE_PROJECT_NAME" - echo "APPWRITE_PUBLIC_ENDPOINT=$APPWRITE_PUBLIC_ENDPOINT" - } >> .env -fi - -# Read .env file and convert it to --dart-define arguments -ARGS=() -while IFS='=' read -r key value || [ -n "$key" ]; do - # Ignore empty lines and comments - if [[ -n "$key" && ! "$key" =~ ^# ]]; then - ARGS+=("--dart-define=${key}=${value}") - fi -done < .env - -# Check if device parameter is provided -if [ -z "$1" ]; then - echo "No device specified. Building for web..." - flutter build web "${ARGS[@]}" - exit 0 -fi - -DEVICE_NAME="$1" - -# Run Flutter app on specified device -echo "Running Flutter app on device: $DEVICE_NAME" -flutter run -d "$DEVICE_NAME" "${ARGS[@]}" diff --git a/lib/config/environment.dart b/lib/config/environment.dart new file mode 100644 index 0000000..bb6fe91 --- /dev/null +++ b/lib/config/environment.dart @@ -0,0 +1,5 @@ +class Environment { + static const String appwriteEndpoint = 'appwrite-endpoint'; + static const String appwriteProjectId = 'appwrite-project-id'; + static const String appwriteProjectName = 'appwrite-project-name'; +} diff --git a/lib/data/repository/appwrite_repository.dart b/lib/data/repository/appwrite_repository.dart index 4619a6f..bcec975 100644 --- a/lib/data/repository/appwrite_repository.dart +++ b/lib/data/repository/appwrite_repository.dart @@ -2,15 +2,16 @@ import 'package:intl/intl.dart'; import 'package:appwrite/appwrite.dart'; import 'package:appwrite_flutter_starter_kit/data/models/log.dart'; import 'package:appwrite_flutter_starter_kit/data/models/project_info.dart'; +import 'package:appwrite_flutter_starter_kit/config/environment.dart'; /// A repository responsible for handling network interactions with the Appwrite server. /// /// It provides a helper method to ping the server. class AppwriteRepository { static const String pingPath = "/ping"; - static const String appwriteProjectId = String.fromEnvironment('APPWRITE_PROJECT_ID'); - static const String appwriteProjectName = String.fromEnvironment('APPWRITE_PROJECT_NAME'); - static const String appwritePublicEndpoint = String.fromEnvironment('APPWRITE_PUBLIC_ENDPOINT'); + static const String appwriteProjectId = Environment.appwriteProjectId; + static const String appwriteProjectName = Environment.appwriteProjectName; + static const String appwritePublicEndpoint = Environment.appwriteEndpoint; final Client _client = Client() .setProject(appwriteProjectId) diff --git a/prepare-env.sh b/prepare-env.sh new file mode 100644 index 0000000..703e159 --- /dev/null +++ b/prepare-env.sh @@ -0,0 +1,13 @@ +#!/bin/sh +set -e + +# Script used during deployment on Appwrite Sites + +# Replace [appwriteEndpoint] with APPWRITE_ENDPOINT in environments files +sed -i "s|appwrite-endpoint|$APPWRITE_ENDPOINT|g" lib/config/environment.dart + +# Replace [appwriteProjectId] with APPWRITE_PROJECT_ID in environments files +sed -i "s|appwrite-project-id|$APPWRITE_PROJECT_ID|g" lib/config/environment.dart + +# Replace [appwriteProjectName] with APPWRITE_PROJECT_NAME in environments files +sed -i "s|appwrite-project-name|$APPWRITE_PROJECT_NAME|g" lib/config/environment.dart From 8e2361b825106a7b240b2a998219da2e3ba576da Mon Sep 17 00:00:00 2001 From: Khushboo Verma Date: Fri, 8 Aug 2025 19:34:58 +0530 Subject: [PATCH 4/4] Update placeholders --- README.md | 6 +++--- lib/config/environment.dart | 8 ++++---- prepare-env.sh | 12 ++++++------ 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 3a1adf0..794750c 100644 --- a/README.md +++ b/README.md @@ -27,9 +27,9 @@ Alternatively, open the repository URL in `Android Studio` to clone it directly. Open `lib/config/environment.dart` and update the values with your Appwrite project credentials: ```dart class Environment { - static const String appwriteEndpoint = 'appwrite-endpoint'; - static const String appwriteProjectId = 'your-project-id'; - static const String appwriteProjectName = 'your-project-name'; + static const String appwriteEndpoint = '[appwriteEndpoint]'; + static const String appwriteProjectId = '[appwriteProjectId]'; + static const String appwriteProjectName = '[appwriteProjectName]'; } ``` diff --git a/lib/config/environment.dart b/lib/config/environment.dart index bb6fe91..31cb53c 100644 --- a/lib/config/environment.dart +++ b/lib/config/environment.dart @@ -1,5 +1,5 @@ class Environment { - static const String appwriteEndpoint = 'appwrite-endpoint'; - static const String appwriteProjectId = 'appwrite-project-id'; - static const String appwriteProjectName = 'appwrite-project-name'; -} + static const String appwriteEndpoint = '[appwriteEndpoint]'; + static const String appwriteProjectId = '[appwriteProjectId]'; + static const String appwriteProjectName = '[appwriteProjectName]'; +} \ No newline at end of file diff --git a/prepare-env.sh b/prepare-env.sh index 703e159..6850457 100644 --- a/prepare-env.sh +++ b/prepare-env.sh @@ -3,11 +3,11 @@ set -e # Script used during deployment on Appwrite Sites -# Replace [appwriteEndpoint] with APPWRITE_ENDPOINT in environments files -sed -i "s|appwrite-endpoint|$APPWRITE_ENDPOINT|g" lib/config/environment.dart +# Replace [appwriteEndpoint] with APPWRITE_ENDPOINT in environment file +sed -i "s|\[appwriteEndpoint\]|$APPWRITE_ENDPOINT|g" lib/config/environment.dart -# Replace [appwriteProjectId] with APPWRITE_PROJECT_ID in environments files -sed -i "s|appwrite-project-id|$APPWRITE_PROJECT_ID|g" lib/config/environment.dart +# Replace [appwriteProjectId] with APPWRITE_PROJECT_ID in environment file +sed -i "s|\[appwriteProjectId\]|$APPWRITE_PROJECT_ID|g" lib/config/environment.dart -# Replace [appwriteProjectName] with APPWRITE_PROJECT_NAME in environments files -sed -i "s|appwrite-project-name|$APPWRITE_PROJECT_NAME|g" lib/config/environment.dart +# Replace [appwriteProjectName] with APPWRITE_PROJECT_NAME in environment file +sed -i "s|\[appwriteProjectName\]|$APPWRITE_PROJECT_NAME|g" lib/config/environment.dart