This commit is contained in:
Venba 2024-06-06 10:18:39 +05:30
parent d60bfdeb13
commit 86cd662522
8 changed files with 131 additions and 6 deletions

View File

@ -1 +1,3 @@
API_URL=https://venbait.in/nhance/dev/employeeRest/
API_URL=https://venbait.in/nhance/dev/employeeRest/
BASE_HREF=/nhance/app/dev/
ENV=development

View File

@ -1 +1,3 @@
API_URL=https://venbait.in/nhance/dev/employeeRest/
API_URL=https://venbait.in/nhance/uat/employeeRest/
BASE_HREF=/nhance/app/uat/
ENV=production

3
.env.test Normal file
View File

@ -0,0 +1,3 @@
API_URL=https://venbait.in/nhance/test/employeeRest/
BASE_HREF=/nhance/app/test/
ENV=test

34
build_web_dev.sh Executable file
View File

@ -0,0 +1,34 @@
#!/bin/bash
# Define the path to the .env.development file
ENV_FILE_PATH=".env.development"
# Check if the .env.development file exists
if [ ! -f $ENV_FILE_PATH ]; then
echo "$ENV_FILE_PATH does not exist"
exit 1
fi
# Copy the .env.development file to .env
cp $ENV_FILE_PATH .env
# Check if the BASE_HREF variable exists in the .env file
if ! grep -q BASE_HREF .env; then
echo "BASE_HREF not found in .env file"
exit 1
fi
# Extract the BASE_HREF value
BASE_HREF=$(grep BASE_HREF .env | cut -d '=' -f2)
# Check if the BASE_HREF value is empty
if [ -z "$BASE_HREF" ]; then
echo "BASE_HREF value is empty"
exit 1
fi
# Build the web app for development with base href
flutter build web --release --base-href "$BASE_HREF"
# Optionally, remove the .env file after the build
# rm .env

34
build_web_production.sh Executable file
View File

@ -0,0 +1,34 @@
#!/bin/bash
# Define the path to the .env file for production
ENV_FILE_PATH=".env.production"
# Check if the .env file exists
if [ ! -f $ENV_FILE_PATH ]; then
echo "$ENV_FILE_PATH does not exist"
exit 1
fi
# Copy the .env file for production to .env
cp $ENV_FILE_PATH .env
# Check if the BASE_HREF variable exists in the .env file
if ! grep -q BASE_HREF .env; then
echo "BASE_HREF not found in .env file"
exit 1
fi
# Extract the BASE_HREF value
BASE_HREF=$(grep BASE_HREF .env | cut -d '=' -f2)
# Check if the BASE_HREF value is empty
if [ -z "$BASE_HREF" ]; then
echo "BASE_HREF value is empty"
exit 1
fi
# Build the web app for production environment with base href
flutter build web --release --base-href "$BASE_HREF"
# Optionally, remove the .env file after the build
# rm .env

34
build_web_test.sh Executable file
View File

@ -0,0 +1,34 @@
#!/bin/bash
# Define the path to the .env file for testing
ENV_FILE_PATH=".env.test"
# Check if the .env file exists
if [ ! -f $ENV_FILE_PATH ]; then
echo "$ENV_FILE_PATH does not exist"
exit 1
fi
# Copy the .env file for testing to .env
cp $ENV_FILE_PATH .env
# Check if the BASE_HREF variable exists in the .env file
if ! grep -q BASE_HREF .env; then
echo "BASE_HREF not found in .env file"
exit 1
fi
# Extract the BASE_HREF value
BASE_HREF=$(grep BASE_HREF .env | cut -d '=' -f2)
# Check if the BASE_HREF value is empty
if [ -z "$BASE_HREF" ]; then
echo "BASE_HREF value is empty"
exit 1
fi
# Build the web app for test environment with base href
flutter build web --release --base-href "$BASE_HREF"
# Optionally, remove the .env file after the build
# rm .env

View File

@ -16,6 +16,7 @@ import 'package:nhancepolicy/hrPolicyDetails.dart';
import 'package:nhancepolicy/oldPolicy.dart';
Future<void> main() async {
// await dotenv.load(fileName: Environment.fileName);
await dotenv.load(fileName: Environment.fileName);
runApp(MaterialApp(

View File

@ -3,14 +3,29 @@ import 'package:flutter_dotenv/flutter_dotenv.dart';
class Environment {
static String get fileName {
if (kReleaseMode) {
return '.env.production';
}
const bool isProduction =
bool.fromEnvironment('dart.vm.product', defaultValue: false);
const bool isTest =
bool.fromEnvironment('dart.vm.environment', defaultValue: false);
return '.env.development';
if (isProduction) {
return '.env.production';
} else if (isTest) {
return '.env.test';
} else {
return '.env.development';
}
}
static String get apiUrl {
return dotenv.env['API_URL'] ?? 'API_URL not found!';
}
static String get baseHref {
return dotenv.env['BASE_HREF'] ?? 'BASE_HREF not found!';
}
static String get env {
return dotenv.env['ENV'] ?? 'ENV not found!';
}
}