File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import 'dart:convert' ;
22
33import 'package:http/http.dart' as http;
4+ import 'package:flutter_dotenv/flutter_dotenv.dart' ;
45
56class OpenAIService {
6- // PENTING: Sebaiknya API Key tidak dismpan hardcode di sini, tapi di .env
7- // Namun untuk refactor ini kita ikuti existing code.
8- static const String _apiKey =
9- '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' ;
7+ // Load API key from .env (flutter_dotenv). Do NOT hardcode.
8+ String get _apiKey => dotenv.env['OPENAI_API_KEY' ] ?? '' ;
109 static const String _baseUrl = 'https://api.openai.com/v1/chat/completions' ;
1110
1211 Future <String ?> describeImage (String base64Image,
Original file line number Diff line number Diff line change @@ -270,6 +270,14 @@ packages:
270270 url: "https://pub.dev"
271271 source: hosted
272272 version: "1.1.9+2"
273+ flutter_dotenv:
274+ dependency: "direct main"
275+ description:
276+ name: flutter_dotenv
277+ sha256: b7c7be5cd9f6ef7a78429cabd2774d3c4af50e79cb2b7593e3d5d763ef95c61b
278+ url: "https://pub.dev"
279+ source: hosted
280+ version: "5.2.1"
273281 flutter_launcher_icons:
274282 dependency: "direct dev"
275283 description:
@@ -385,7 +393,7 @@ packages:
385393 source: hosted
386394 version: "0.2.5"
387395 http:
388- dependency: "direct main"
396+ dependency: transitive
389397 description:
390398 name: http
391399 sha256: "5895291c13fa8a3bd82e76d5627f69e0d85ca6a30dcac95c4ea19a5d555879c2"
Original file line number Diff line number Diff line change @@ -20,6 +20,8 @@ version: 1.0.0+1
2020
2121environment :
2222 sdk : ^3.6.0
23+ http : ^0.13.6
24+ flutter_dotenv : ^5.1.0.0
2325
2426# Dependencies specify other packages that your package needs in order to work.
2527# To automatically upgrade your package dependencies to the latest versions
@@ -36,7 +38,7 @@ dependencies:
3638 cupertino_icons : ^1.0.8
3739 camera : ^0.10.6
3840 image_picker : ^1.0.4
39- http : ^0.13.6
41+ flutter_dotenv : ^5.1.0
4042 path_provider : ^2.1.2
4143 path : ^1.9.0
4244 usb_serial : ^0.5.2
You can’t perform that action at this time.
0 commit comments