Skip to content

Commit

Permalink
fix: http post android unhandled exception
Browse files Browse the repository at this point in the history
upgraded gradle, replaced flutter_config with dotenv, use --dart-define for google_maps key for now
  • Loading branch information
popoway committed Mar 4, 2024
1 parent 002bf46 commit 4d423fa
Show file tree
Hide file tree
Showing 31 changed files with 48 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/dart.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
# - uses: dart-lang/setup-dart@v1
- uses: subosito/flutter-action@v1
with:
flutter-version: '3.13.0'
flutter-version: '3.19.2'
channel: 'stable'

- name: Install dependencies
Expand Down
12 changes: 11 additions & 1 deletion android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,17 @@ plugins {
id "kotlin-android"
id "dev.flutter.flutter-gradle-plugin"
}
apply from: project(':flutter_config').projectDir.getPath() + "/dotenv.gradle"

def dartEnvironmentVariables = []

if (project.hasProperty('dart-defines')) {
dartEnvironmentVariables = project.property('dart-defines')
.split(',')
.collectEntries { entry ->
def pair = new String(entry.decodeBase64(), 'UTF-8').split('=')
[(pair.first()): pair.last()]
}
}

def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
Expand Down Expand Up @@ -58,6 +67,7 @@ android {
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
multiDexEnabled true
manifestPlaceholders['GOOGLE_MAPS_API_KEY'] = dartEnvironmentVariables.GOOGLE_MAPS_API_KEY
}

signingConfigs {
Expand Down
2 changes: 1 addition & 1 deletion android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
android:icon="@mipmap/launcher_icon"
android:localeConfig="@xml/locales_config">
<meta-data android:name="com.google.android.geo.API_KEY"
android:value="@string/GOOGLE_MAPS_API_KEY" />
android:value="${GOOGLE_MAPS_API_KEY}" />
<activity
android:name=".MainActivity"
android:exported="true"
Expand Down
14 changes: 13 additions & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ buildscript {
}

dependencies {
classpath 'com.android.tools.build:gradle:7.4.2'
classpath 'com.android.tools.build:gradle:8.3.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
Expand All @@ -16,6 +16,18 @@ allprojects {
google()
mavenCentral()
}
// This code is where all the magic happens and fixes the error.
subprojects {
afterEvaluate { project ->
if (project.hasProperty('android')) {
project.android {
if (namespace == null) {
namespace project.group
}
}
}
}
}
}

rootProject.buildDir = '../build'
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
3 changes: 3 additions & 0 deletions android/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
org.gradle.jvmargs=-Xmx1536M
android.useAndroidX=true
android.enableJetifier=true
android.defaults.buildfeatures.buildconfig=true
android.nonTransitiveRClass=false
android.nonFinalResIds=false
2 changes: 1 addition & 1 deletion android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Fri Aug 25 05:00:01 EDT 2023
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
10 changes: 5 additions & 5 deletions lib/chatknights.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import 'package:flutter/cupertino.dart';
import 'package:flutter/services.dart';
import 'package:url_launcher/url_launcher.dart';
import 'package:flutter_i18n/flutter_i18n.dart';
import 'package:flutter_config/flutter_config.dart';
import 'package:flutter_dotenv/flutter_dotenv.dart';

import 'package:flutter_chat_types/flutter_chat_types.dart' as types;
import 'package:flutter_chat_ui/flutter_chat_ui.dart';
Expand Down Expand Up @@ -70,9 +70,9 @@ class _MyChatPageState extends State<MyChatPage> {
lastName: 'AI',
imageUrl:
"https://github.com/popoway/goknights/blob/main/assets/icon/icon-scaled-128px.png?raw=true");
final _endpoint = FlutterConfig.get('OPENAI_API_ENDPOINT');
final _key = FlutterConfig.get('OPENAI_API_KEY');
final _model = FlutterConfig.get('OPENAI_API_MODEL');
final _endpoint = dotenv.env['OPENAI_API_ENDPOINT'];
final _key = dotenv.env['OPENAI_API_KEY'];
final _model = dotenv.env['OPENAI_API_MODEL'];

@override
Widget build(BuildContext context) {
Expand Down Expand Up @@ -250,7 +250,7 @@ class _MyChatPageState extends State<MyChatPage> {
"https://$_endpoint/openai/deployments/$_model/chat/completions?api-version=2023-12-01-preview"),
headers: <String, String>{
'Content-Type': 'application/json; charset=UTF-8',
'api-key': _key,
'api-key': _key!,
},
body: partialRequest);
} catch (e) {
Expand Down
4 changes: 2 additions & 2 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/scheduler.dart';
import 'package:flutter/services.dart';
import 'package:flutter_config/flutter_config.dart';
import 'package:flutter_dotenv/flutter_dotenv.dart';
import 'package:flutter_i18n/flutter_i18n.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:package_info_plus/package_info_plus.dart';
Expand All @@ -29,7 +29,7 @@ void _showReviewDialog() async {

Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await FlutterConfig.loadEnvVariables(); // load .env file
await dotenv.load(fileName: ".env"); // load .env file
SystemChrome.setSystemUIOverlayStyle(const SystemUiOverlayStyle(
statusBarColor: Colors.transparent, // transparent status bar for Android
));
Expand Down
4 changes: 2 additions & 2 deletions macos/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ SPEC CHECKSUMS:
geolocator_apple: 72a78ae3f3e4ec0db62117bd93e34523f5011d58
in_app_review: a850789fad746e89bce03d4aeee8078b45a53fd0
package_info_plus: 02d7a575e80f194102bef286361c6c326e4c29ce
path_provider_foundation: 29f094ae23ebbca9d3d0cec13889cd9060c0e943
path_provider_foundation: 3784922295ac71e43754bd15e0653ccfd36a147c
share_plus: 76dd39142738f7a68dd57b05093b5e8193f220f7
shared_preferences_foundation: 5b919d13b803cadd15ed2dc053125c68730e5126
shared_preferences_foundation: b4c3b4cddf1c21f02770737f147a3f5da9d39695
url_launcher_macos: d2691c7dd33ed713bf3544850a623080ec693d95

PODFILE CHECKSUM: 236401fc2c932af29a9fcf0e97baeeb2d750d367
Expand Down
2 changes: 1 addition & 1 deletion macos/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0920;
LastUpgradeCheck = 1430;
LastUpgradeCheck = 1510;
ORGANIZATIONNAME = "";
TargetAttributes = {
331C80D4294CF70F00263BE5 = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1430"
LastUpgradeVersion = "1510"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
8 changes: 4 additions & 4 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -214,14 +214,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.6.12"
flutter_config:
flutter_dotenv:
dependency: "direct main"
description:
name: flutter_config
sha256: a07e6156bb6e776e29c6357be433155acda87d1dab1a3f787a72091a1b71ffbf
name: flutter_dotenv
sha256: "9357883bdd153ab78cbf9ffa07656e336b8bbb2b5a3ca596b0b27e119f7c7d77"
url: "https://pub.dev"
source: hosted
version: "2.0.2"
version: "5.1.0"
flutter_i18n:
dependency: "direct main"
description:
Expand Down
5 changes: 3 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
# In Windows, build-name is used as the major, minor, and patch parts
# of the product and file versions while build-number is used as the build suffix.
version: 2.3.1+54
version: 2.3.1+55

environment:
sdk: '>=3.1.0 <4.0.0'
Expand Down Expand Up @@ -45,7 +45,6 @@ dependencies:
material_floating_search_bar_2: ^0.5.0
geolocator: ^11.0.0
apple_maps_flutter: ^1.2.0
flutter_config: ^2.0.2
shared_preferences: ^2.2.1
back_button_interceptor: ^7.0.0
webview_flutter: ^4.4.2
Expand All @@ -60,6 +59,7 @@ dependencies:
flutter_chat_ui: ^1.6.10
http: ^1.1.0
flutter_svg: ^2.0.9
flutter_dotenv: ^5.1.0

dev_dependencies:
flutter_test:
Expand Down Expand Up @@ -92,6 +92,7 @@ flutter:
- assets/icon/icon-scaled.png
- assets/icon/SALogo.svg
- assets/knowledgebase/system-message.txt
- .env

# An image asset can refer to one or more resolution-specific "variants", see
# https://flutter.dev/assets-and-images/#resolution-aware
Expand Down

0 comments on commit 4d423fa

Please sign in to comment.