Skip to content

Commit

Permalink
프로젝트 환경설정 ( API 키 추가 & 필요없는 기능 삭제 및 메인 화면 조정 ) (#3)
Browse files Browse the repository at this point in the history
* add logo

* add .env file

* add gitignore

* add gitignore

* add gitignore

* Remove lib/.env from tracking and add to .gitignore

* allow Setting file ignore

* add git ignore and manifest

* add shell script for make env

* fix command

* fix command

* fix make file and shell script

* fix makeFile

* fix make file

* fix api key generate file

* fix workflow

* fix for using api_key

* fix to .env api key controll

* add env file generater fix

* add make file chang e
  • Loading branch information
jwson-automation authored Aug 13, 2024
1 parent 3fc6d21 commit 1c3a51d
Show file tree
Hide file tree
Showing 15 changed files with 246 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/blueberry-build-test-action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ jobs:
firebase_options_dart: ${{secrets.FIREBASE_OPTION}}
run: echo "$firebase_options_dart" > lib/firebase_options.dart

- name: Create .env file
env:
ENV_CONTENT: ${{ secrets.ENV_CONTENT }}
run: echo "$ENV_CONTENT" > .env

- name: 'Set Flutter Version Latest'
uses: subosito/flutter-action@v2
with:
Expand Down
15 changes: 13 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
# Ignore platform folders.
# 이유: 개발자마다 환경이 다르므로 설정 파일이 충돌해 코드 공유가 어려울 수 있습니다. 예를 들어, 쇼핑몰 개발 시 페이팔, Stripe, 인앱결제를 사용하려면 AndroidManifest, google-service.json, Info.plist, GoogleService-Info.plist 등의 파일 수정이 필요하지만, 이 정보는 공유되지 않아야 하며, 공유가 되면, 필요 없는 설정이 추가되거나 자신의 설정이 삭제되거나 하는 일이 발생 합니다. 따라서 각 개발자가 필요한 플랫폼을 직접 설정하도록 합니다.
/android/
/ios/
/web/
/linux/
/macos/
/windows/

# Allow Android platform folder.
!/android/app/src/main/AndroidManifest.xml
!/android/app/src/main/app/build.gradle
!/android/app/src/main/res/values/strings.xml
!/ios/Podfile

!/ios/.gitignore
!/android/.gitignore

# Miscellaneous
*.class
*.log
Expand Down Expand Up @@ -75,4 +83,7 @@ lib/firebase_options.dart
.vscode/launch.json

# secret key
sign_in_key.dart
sign_in_key.dart

# env
.env
23 changes: 23 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,20 @@ endif
# Define the default target to call all necessary targets
all: init analyze apply format buildRunner

# Define the init target to initialize the project
first : create init analyze buildRunner env
setting : init buildRunner
lint : analyze apply format

# Define the init target
create:
@echo "Create ios and android floder..."
ifeq ($(DETECTED_OS), Windows)
@flutter create .
else
@$(FLUTTER) create .
endif

# Define the init target
init:
@echo "Initializing Flutter project..."
Expand Down Expand Up @@ -61,3 +75,12 @@ else
@$(FLUTTER) pub run build_runner build --delete-conflicting-outputs
endif

# Define the env target for Unix-like systems
env:
ifeq ($(DETECTED_OS), Windows)
@echo "Using PowerShell script to create .env file."
@powershell -ExecutionPolicy Bypass -File generate_env.ps1
else
@echo "Using bash script to create .env file."
@bash generate_env.sh
endif
16 changes: 16 additions & 0 deletions android/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
gradle-wrapper.jar
/.gradle
/captures/
/gradlew
/gradlew.bat
/local.properties
GeneratedPluginRegistrant.java

# Manifest file which is auto generated
!/android/app/src/main/AndroidManifest.xml

# Remember to never publicly share your keystore.
# See https://flutter.dev/docs/deployment/android#reference-the-keystore-from-the-app
key.properties
**/*.keystore
**/*.jks
46 changes: 46 additions & 0 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
plugins {
id "com.android.application"
id "kotlin-android"
// The Flutter Gradle Plugin must be applied after the Android and Kotlin Gradle plugins.
id "dev.flutter.flutter-gradle-plugin"
}

android {
namespace = "com.example.blueberry_voice"
compileSdk = flutter.compileSdkVersion
ndkVersion = flutter.ndkVersion

compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}

kotlinOptions {
jvmTarget = JavaVersion.VERSION_1_8
}

defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId = "com.example.blueberry_voice"
// You can update the following values to match your application needs.
// For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration.
minSdk = 29
targetSdk = 35
versionCode = flutter.versionCode
versionName = flutter.versionName

buildConfigField "String", "API_KEY", "\"${System.getenv('GOOGLE_API_KEY')}\""
}

buildTypes {
release {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig = signingConfigs.debug
}
}
}

flutter {
source = "../.."
}
63 changes: 63 additions & 0 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />

<application
android:name="${applicationName}"
android:icon="@mipmap/ic_launcher"
android:label="boyvoice"
android:enableOnBackInvokedCallback="true">
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="@string/google_map_api_key" />
<activity
android:name=".MainActivity"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:exported="true"
android:hardwareAccelerated="true"
android:launchMode="singleTop"
android:taskAffinity=""
android:theme="@style/LaunchTheme"
android:windowSoftInputMode="adjustResize">
<!-- Specifies an Android theme to apply to this Activity as soon as
the Android process has started. This theme is visible to the user
while the Flutter UI initializes. After that, this theme continues
to determine the Window background behind the Flutter UI. -->
<meta-data
android:name="io.flutter.embedding.android.NormalTheme"
android:resource="@style/NormalTheme"/>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!-- Don't delete the meta-data below.
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
<meta-data
android:name="flutterEmbedding"
android:value="2" />
</application>
<!-- Required to query activities that can process text, see:
https://developer.android.com/training/package-visibility and
https://developer.android.com/reference/android/content/Intent#ACTION_PROCESS_TEXT.
In particular, this is used by the Flutter engine in io.flutter.plugin.text.ProcessTextPlugin. -->
<queries>
<intent>
<action android:name="android.intent.action.PROCESS_TEXT" />
<data android:mimeType="text/plain" />
</intent>
<intent>
<action android:name="android.intent.action.VIEW" />
<data android:scheme="sms" />
</intent>
<intent>
<action android:name="android.intent.action.VIEW" />
<data android:scheme="tel" />
</intent>
<intent>
<action android:name="android.support.customtabs.action.CustomTabsService" />
</intent>
</queries>
</manifest>
3 changes: 3 additions & 0 deletions android/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<resources>
<string name="google_map_api_key" translatable="false">${BuildConfig.GOOGLE_MAP_API_KEY}</string>
</resources>
Binary file added assets/logo/voice_logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 19 additions & 0 deletions generate_env.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# PowerShell 스크립트로 .env 파일 생성

# 현재 작업 중인 디렉터리 경로 가져오기
$TargetDir = Get-Location

# .env 파일 내용
$envContent = @"
# please replace 'your_api_key_here' with your actual API key
GOOGLE_API_KEY=your_api_key_here
GPT_API_KEY=your_api_key_here
# Other environment variables can be added here
"@

# .env 파일 생성
$envFilePath = Join-Path -Path $TargetDir -ChildPath ".env"
Write-Output "Creating .env file at: $envFilePath"

# UTF-8 인코딩으로 파일 생성
$envContent | Out-File -FilePath $envFilePath -Encoding utf8
5 changes: 5 additions & 0 deletions generate_env.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# .env 파일 생성
echo "# please replace 'your_api_key_here' with your actual API key" > ".env"
echo "GOOGLE_API_KEY=your_api_key_here" >> ".env"
echo "GPT_API_KEY=your_api_key_here" >> ".env"
echo "# Other environment variables can be added here" >> ".env"
35 changes: 35 additions & 0 deletions ios/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
**/dgph
*.mode1v3
*.mode2v3
*.moved-aside
*.pbxuser
*.perspectivev3
**/*sync/
.sconsign.dblite
.tags*
**/.vagrant/
**/DerivedData/
Icon?
**/Pods/
**/.symlinks/
profile
xcuserdata
**/.generated/
Flutter/App.framework
Flutter/Flutter.framework
Flutter/Flutter.podspec
Flutter/Generated.xcconfig
Flutter/ephemeral/
Flutter/app.flx
Flutter/app.zip
Flutter/flutter_assets/
Flutter/flutter_export_environment.sh
ServiceDefinitions.json
Runner/GeneratedPluginRegistrant.*

# Exceptions to above rules.
!default.mode1v3
!default.mode2v3
!default.pbxuser
!default.perspectivev3

3 changes: 2 additions & 1 deletion lib/core/TopScreen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';

import '../feature/admin/AdminUserListPage.dart';
import '../feature/login/LoginScreen.dart';
import '../feature/map/PoliceMapScreen.dart';
import '../feature/match/MatchScreen.dart';

/// TopScreen.dart
Expand All @@ -25,7 +26,7 @@ class TopScreen extends ConsumerWidget {
final selectedIndex = ref.watch(selectedIndexProvider);

final List<Widget> pages = [
const PostScreen(),
const PoliceMapScreen(),
const MatchScreen(),
const LoginScreen(),
const AdminUserListPage()
Expand Down
4 changes: 3 additions & 1 deletion lib/feature/map/provider/PoliceStationProvider.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import 'dart:convert';

import 'package:blueberry_flutter_template/model/GoogleMapPlace.dart';
import 'package:flutter_dotenv/flutter_dotenv.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';
import 'package:http/http.dart' as http;

//Google Map API key 등록 필요
const String apiKey = ''; //TODO: 'Google Map API Key 입력 필요
String apiKey = dotenv.env['GOOGLE_MAP_API_KEY'] ?? 'AIzaSyDEGMHYfH7pQ1ks39pXrhfmXZJRosp755w';
// Android : AndroidManifest.xml 에 API Key와 권한 추가 필요
// iOS : AppDelegate.swift, Info.plist 에 API Key와 권한 추가 필요

Expand Down
9 changes: 8 additions & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import 'package:firebase_core/firebase_core.dart';
import 'package:firebase_crashlytics/firebase_crashlytics.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_dotenv/flutter_dotenv.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:intl/date_symbol_data_local.dart';

Expand All @@ -19,7 +20,6 @@ Future<void> main() async {
runZonedGuarded(() async {
// 날짜 형식 초기화
WidgetsFlutterBinding.ensureInitialized();
await initializeDateFormatting('en_US', null);
await Firebase.initializeApp(
options: DefaultFirebaseOptions.currentPlatform,
);
Expand All @@ -34,6 +34,13 @@ Future<void> main() async {
FirebaseCrashlytics.instance.setCrashlyticsCollectionEnabled(true);
}

if (kIsWeb) {
talker.info('Web environment can not use dotenv');
} else {
await dotenv.load(fileName: '.env');
}

await initializeDateFormatting('en_US', null);
runApp(const ProviderScope(
child: MyApp(),
));
Expand Down
5 changes: 5 additions & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ dependencies:
# map
google_maps_flutter: ^2.9.0
geolocator: ^12.0.0
flutter_dotenv: ^5.1.0

# apiKey


dev_dependencies:
flutter_test:
Expand All @@ -120,6 +124,7 @@ dev_dependencies:
flutter:
uses-material-design: true
assets:
- .env
- assets/
- assets/600x400/
- assets/300x420/
Expand Down

0 comments on commit 1c3a51d

Please sign in to comment.