package_flutter_env 0.0.2
package_flutter_env: ^0.0.2 copied to clipboard
Using MIAppBarWidget to create a custom app bar.
Custom script for generating environment-specific code for different platforms #
Features #
The flutter_env.dart file appears to be a custom script for generating environment-specific code for different platforms (Dart, Objective-C, and Gradle for Android). It reads from an environment file (.env by default), and generates code based on the key-value pairs in the environment file.
Here's a basic usage guide:
- Create an environment file: Create a .env file in your project root (or specify a different file using the envfile argument). This file should contain key-value pairs, one per line, like this:
API_KEY=123456
BASE_URL=https://api.example.com
2.Run the script: You can run the DotENV class with the command-line arguments. For example:
void main(List<String> args) {
DotENV(args);
}
You can pass arguments to specify the platform (platform), the environment file (envfile), and the directory name (dirname). If not specified, it will use default values.
3.Generated code: The script will generate a Dart file (lib/env.dart by default) with a class ENV that contains static string properties for each key-value pair in the environment file. For example:
class ENV {
static String API_KEY = "123456";
static String BASE_URL = "https://api.example.com";
}
You can then import this file in your Flutter code and access the environment variables like this: ENV.API_KEY.
Please note that this is a basic guide and the actual usage may vary depending on your project setup and requirements. Also, remember to exclude your environment files from version control to avoid committing sensitive data.
Unit Test Command #
At the root of the project, run the following command:
flutter test test/dotenv_test.dart
Generate the env.dart file #
At the root of the example project, run the following command:
like: /Users/danli/Desktop/2024/packages/package_flutter_env/example
Because test is the development environment, the generated file is in the lib folder.
flutter test test/env_test.dart
trigger:
branches:
include:
- master
pool:
name: SelfHosted
stages:
- stage: Build_iOS
displayName: "Build iOS App"
jobs:
- job: Build
displayName: "Archive & Package iOS"
pool:
name: SelfHosted
variables:
APP_NAME: "Runner"
CONFIGURATION: "Release"
steps:
- task: DownloadSecureFile@1
name: DownloadEnv
inputs:
secureFile: ".env"
- script: |
cp "$(Agent.TempDirectory)/.env" .env
displayName: "Copy .env to project root"
- script: |
flutter pub get
flutter pub run build_runner build --delete-conflicting-outputs
displayName: "Generate env.g.dart"
- script: |
cd ios
rm -rf Pods Podfile.lock
pod install --repo-update --verbose
displayName: "Clean & Install CocoaPods"
- script: |
echo "📦 Ensure Flutter dependencies & generate iOS files"
flutter build ios --no-codesign --release
displayName: "Flutter build ios (prepare)"
- script: |
echo "🚀 Build & archive .xcarchive"
cd ios
xcodebuild \
-workspace ${APP_NAME}.xcworkspace \
-scheme ${APP_NAME} \
-configuration ${CONFIGURATION} \
-sdk iphoneos \
-derivedDataPath build \
archive \
-archivePath build/Build/Products/${CONFIGURATION}-iphoneos/${APP_NAME}.xcarchive
displayName: "xcodebuild archive"
- script: |
echo "📦 Export IPA"
cd ios
xcodebuild -exportArchive \
-archivePath build/Build/Products/${CONFIGURATION}-iphoneos/${APP_NAME}.xcarchive \
-exportPath build/export \
-exportOptionsPlist ExportOptions.plist
displayName: "xcodebuild exportArchive"
- script: |
echo "📂 Check export folder"
ls -la ios/build/export
displayName: "Check export folder contents"
- script: |
echo "💾 Collect IPA into artifact staging"
IPA_DIR="$(Build.ArtifactStagingDirectory)/iOS"
mkdir -p "$IPA_DIR"
cp ios/build/export/*.ipa "$IPA_DIR/"
ls -la "$IPA_DIR"
displayName: "Prepare IPA artifact"
- task: PublishPipelineArtifact@1
inputs:
targetPath: "$(Build.ArtifactStagingDirectory)/iOS"
artifact: "iOS"
publishLocation: "pipeline"
displayName: "Publish IPA artifact"
- stage: AppStoreRelease
displayName: "AppStore Release"
dependsOn: Build_iOS
jobs:
- job: BuildAndRelease
displayName: "Upload to TestFlight"
steps:
- download: current
artifact: iOS
displayName: "Download IPA artifact"
- task: AppStoreRelease@1
displayName: "Upload to TestFlight"
inputs:
ipaPath: "$(Pipeline.Workspace)/iOS/*.ipa"
serviceEndpoint: "AppleServiceConnection"
releaseTrack: "TestFlight"
appIdentifier: "com.bitidi.app.test"
appType: "iOS"
- stage: Build_Android
displayName: "Build Android App"
jobs:
- job: BuildAndroid
displayName: "Assemble Android APK"
pool:
name: SelfHosted
variables:
BUILD_MODE: "release"
steps:
- task: DownloadSecureFile@1
name: DownloadEnv
inputs:
secureFile: ".env"
- script: |
cp "$(Agent.TempDirectory)/.env" .env
displayName: "Copy .env to project root"
- script: |
flutter pub get
flutter pub run build_runner build --delete-conflicting-outputs
displayName: "Generate env.g.dart"
- script: |
flutter build apk --release
displayName: "Flutter build APK"
- script: |
mkdir -p "$(Build.ArtifactStagingDirectory)/Android"
cp build/app/outputs/flutter-apk/app-release.apk "$(Build.ArtifactStagingDirectory)/Android/"
displayName: "Collect APK Artifact"
- task: PublishPipelineArtifact@1
inputs:
targetPath: "$(Build.ArtifactStagingDirectory)/Android"
artifact: "Android"
publishLocation: "pipeline"
displayName: "Publish APK Artifact"