diff --git a/.vscode/launch.json b/.vscode/launch.json index c45c8b3..4d4d01d 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -9,7 +9,11 @@ "program": "lib/example/lib/main.dart", "args": [ "-d", - "chrome" + "chrome", + "--web-renderer", + "html", + "--web-port", + "48102", ] } ] diff --git a/README.md b/README.md index d75432e..4657437 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,9 @@ Workout Test and Diet 4 You Common Util Functions +### Version 1.0.23 + +webapi CORS solution with the API + ### Version 1.0.22 webapi CORS: only diet4you domains, plugins update diff --git a/lib/example/lib/main.dart b/lib/example/lib/main.dart index 8a969cc..9756922 100644 --- a/lib/example/lib/main.dart +++ b/lib/example/lib/main.dart @@ -1,9 +1,12 @@ import 'package:flutter/material.dart'; +import 'package:flutter_dotenv/flutter_dotenv.dart'; import 'package:workouttest_util/model/cache.dart'; +import 'package:workouttest_util/service/customer_service.dart'; import 'package:workouttest_util/service/openai_service.dart'; -void main() { +void main() async { WidgetsFlutterBinding.ensureInitialized(); + await dotenv.load(fileName: ".env"); runApp(const MyApp()); } @@ -14,31 +17,30 @@ class MyApp extends StatefulWidget { State createState() => _MyAppState(); } - - class _MyAppState extends State { String _response = ""; - + @override void initState() { super.initState(); } void _fetchData() async { - var api = OpenAIApi(); - String response = await api.getOpenAICompletion("Who wrote the song 'yellow submarine'?"); + //var api = OpenAIApi(); + //String response = await api.getOpenAICompletion("Who wrote the song 'yellow submarine'?"); + await CustomerApi().getCustomer(72); + String response = "OK"; setState(() { - _response = response; + _response = response; }); } - @override Widget build(BuildContext context) { Cache().setLocalBaseUrl(); - + return MaterialApp( - home: Scaffold( + home: Scaffold( appBar: AppBar( title: const Text("Example"), ), @@ -57,16 +59,12 @@ class _MyAppState extends State { mainAxisAlignment: MainAxisAlignment.spaceAround, children: [ FloatingActionButton( - onPressed:() => { - _fetchData() - }, + onPressed: () => {_fetchData()}, tooltip: 'Send question', child: const Icon(Icons.ad_units), ), - ], ) - ], ), ), diff --git a/lib/service/webapi.dart b/lib/service/webapi.dart index d9af7a5..a0f09be 100644 --- a/lib/service/webapi.dart +++ b/lib/service/webapi.dart @@ -27,7 +27,6 @@ class APIWebClient with Common, Logging { final body = jsonEncode({'username': email, 'password': password}); var uri = Uri.parse(url); var result = await http.post(uri, body: body, headers: { - "Access-Control-Allow-Origin": 'https://*.diet4you.eu, https://*.diet4you.hu, http://localhost', "Content-Type": "application/json", "Authorization": "1", }); @@ -65,10 +64,6 @@ class APIWebClient with Common, Logging { } var uri = Uri.parse(url); var result = await http.post(uri, body: body, headers: { - "Access-Control-Allow-Origin": 'https://*.diet4you.eu, https://*.diet4you.hu, http://localhost', - "Access-Control-Allow-Headers": "Origin,Content-Type,Authorization,locale", - "Access-Control-Allow-Credentials": 'true', // Required for cookies, authorization headers with HTTPS - "Access-Control-Allow-Methods": "POST, GET, OPTIONS", "Content-Type": "application/json", "Authorization": 'Bearer $authToken', }); @@ -102,10 +97,6 @@ class APIWebClient with Common, Logging { var uri = Uri.parse(url); var result = await http.get(uri, headers: { "Content-Type": "application/json", - "Access-Control-Allow-Origin": 'https://*.diet4you.eu, https://*.diet4you.hu, http://localhost', - "Access-Control-Allow-Headers": "Origin,Content-Type,Authorization,locale", - "Access-Control-Allow-Credentials": 'true', // Required for cookies, authorization headers with HTTPS - "Access-Control-Allow-Methods": "POST, GET, OPTIONS", "Authorization": 'Bearer $authToken', }); diff --git a/pubspec.yaml b/pubspec.yaml index b516faf..b323cda 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: workouttest_util description: Workout Test app and web functions. -version: 1.0.22 +version: 1.0.23 environment: sdk: ">=2.18.6 <3.0.0"