v1.0.4 webapi fixes
16
.vscode/launch.json
vendored
Normal file
@ -0,0 +1,16 @@
|
||||
{
|
||||
// launch.json
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "Util Example",
|
||||
"type": "dart",
|
||||
"request": "launch",
|
||||
"program": "lib/example/lib/main.dart",
|
||||
"args": [
|
||||
"-d",
|
||||
"chrome"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
@ -1,5 +1,8 @@
|
||||
Workout Test and Diet 4 You Common Util Functions
|
||||
|
||||
Version 1.0.4
|
||||
webapi client fixes
|
||||
|
||||
Version 1.0.3
|
||||
Warning fixes, webapi client
|
||||
|
||||
|
75
lib/example/lib/main.dart
Normal file
@ -0,0 +1,75 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:workouttest_util/model/cache.dart';
|
||||
import 'package:workouttest_util/service/openai_service.dart';
|
||||
|
||||
void main() {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
runApp(const MyApp());
|
||||
}
|
||||
|
||||
class MyApp extends StatefulWidget {
|
||||
const MyApp({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<MyApp> createState() => _MyAppState();
|
||||
}
|
||||
|
||||
|
||||
|
||||
class _MyAppState extends State<MyApp> {
|
||||
String _response = "";
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
}
|
||||
|
||||
void _fetchData() async {
|
||||
var api = OpenAIApi();
|
||||
String response = await api.getOpenAICompletion("Who wrote the song 'yellow submarine'?");;
|
||||
setState(() {
|
||||
_response = response;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
Cache().setLocalBaseUrl();
|
||||
|
||||
return MaterialApp(
|
||||
home: Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text("Example"),
|
||||
),
|
||||
body: Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: <Widget>[
|
||||
const Text(
|
||||
'AI answer:',
|
||||
),
|
||||
Text(
|
||||
_response,
|
||||
style: Theme.of(context).textTheme.headline4,
|
||||
),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
||||
children: [
|
||||
FloatingActionButton(
|
||||
onPressed:() => {
|
||||
_fetchData()
|
||||
},
|
||||
tooltip: 'Send question',
|
||||
child: const Icon(Icons.ad_units),
|
||||
),
|
||||
|
||||
],
|
||||
)
|
||||
|
||||
],
|
||||
),
|
||||
),
|
||||
));
|
||||
}
|
||||
}
|
@ -71,7 +71,7 @@ class APIClient with Common, Logging {
|
||||
return webClient.post(endPoint, body);
|
||||
}
|
||||
final url = Cache().getBaseUrl() + endPoint;
|
||||
trace(" ------------ http/post body $body - url: $url ");
|
||||
log(" ------------ http/post body $body - url: $url ");
|
||||
try {
|
||||
String authToken = Cache().getAuthToken();
|
||||
if (authToken.isEmpty) {
|
||||
@ -91,7 +91,7 @@ class APIClient with Common, Logging {
|
||||
request.write(body);
|
||||
HttpClientResponse result = await request.close();
|
||||
client.close();
|
||||
trace(" ------------post response code: ${result.statusCode}");
|
||||
log(" ------------post response code: ${result.statusCode}");
|
||||
if (result.statusCode == 200) {
|
||||
return await result.transform(utf8.decoder).join();
|
||||
} else if (result.statusCode == 404) {
|
||||
@ -115,7 +115,7 @@ class APIClient with Common, Logging {
|
||||
}
|
||||
final url = Cache().getBaseUrl() + endPoint + param;
|
||||
try {
|
||||
trace("-------- API get $url");
|
||||
log("-------- API get $url");
|
||||
String authToken = Cache().getAuthToken();
|
||||
if (authToken.isEmpty) {
|
||||
var responseJson = await authenticateUser(Cache.username, Cache.password);
|
||||
@ -132,7 +132,7 @@ class APIClient with Common, Logging {
|
||||
request.write("");
|
||||
HttpClientResponse result = await request.close();
|
||||
client.close();
|
||||
trace(" ------------get response code: ${result.statusCode}");
|
||||
log(" ------------get response code: ${result.statusCode}");
|
||||
if (result.statusCode == 200) {
|
||||
return await result.transform(utf8.decoder).join();
|
||||
} else if (result.statusCode == 404) {
|
||||
|
@ -43,7 +43,7 @@ class APIWebClient with Common, Logging {
|
||||
log("Authentication status: ${result.statusCode}, response: $response");
|
||||
final data = jsonDecode(response);
|
||||
return data;
|
||||
} catch (exception) {
|
||||
} on Exception catch (exception) {
|
||||
log(exception.toString());
|
||||
try {
|
||||
await Sentry.captureException(exception);
|
||||
@ -57,7 +57,7 @@ class APIWebClient with Common, Logging {
|
||||
|
||||
Future<String> post(String endPoint, String body) async {
|
||||
final url = Cache().getBaseUrl() + endPoint;
|
||||
trace(" ------------ http/post body $body - url: $url ");
|
||||
log(" ------------ http/post body $body - url: $url ");
|
||||
try {
|
||||
String authToken = Cache().getAuthToken();
|
||||
if (authToken.isEmpty) {
|
||||
@ -70,7 +70,7 @@ class APIWebClient with Common, Logging {
|
||||
"Content-Type": "application/json",
|
||||
"Authorization": 'Bearer $authToken',
|
||||
});
|
||||
trace(" ------------post response code: ${result.statusCode}");
|
||||
log(" ------------post response code: ${result.statusCode}");
|
||||
if (result.statusCode == 200) {
|
||||
return result.body;
|
||||
} else if (result.statusCode == 404) {
|
||||
@ -90,7 +90,7 @@ class APIWebClient with Common, Logging {
|
||||
Future<String> get(String endPoint, String param) async {
|
||||
final url = Cache().getBaseUrl() + endPoint + param;
|
||||
try {
|
||||
trace("-------- API get $url");
|
||||
log("-------- API get $url");
|
||||
String authToken = Cache().getAuthToken();
|
||||
if (authToken.isEmpty) {
|
||||
var responseJson = await authenticateUser(Cache.username, Cache.password);
|
||||
@ -103,7 +103,7 @@ class APIWebClient with Common, Logging {
|
||||
"Authorization": 'Bearer $authToken',
|
||||
});
|
||||
|
||||
trace(" ------------get response code: ${result.statusCode}");
|
||||
log(" ------------get response code: ${result.statusCode}");
|
||||
if (result.statusCode == 200) {
|
||||
return result.body;
|
||||
} else if (result.statusCode == 404) {
|
||||
|
@ -1,6 +1,6 @@
|
||||
name: workouttest_util
|
||||
description: Workout Test app and web functions.
|
||||
version: 1.0.3
|
||||
version: 1.0.4
|
||||
homepage:
|
||||
|
||||
environment:
|
||||
|
@ -1,5 +1,3 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:workouttest_util/model/cache.dart';
|
||||
import 'package:workouttest_util/service/api.dart';
|
||||
|
BIN
web/Icon-192.png
Normal file
After Width: | Height: | Size: 5.2 KiB |
BIN
web/Icon-512.png
Normal file
After Width: | Height: | Size: 8.1 KiB |
BIN
web/Icon-maskable-192.png
Normal file
After Width: | Height: | Size: 5.5 KiB |
BIN
web/Icon-maskable-512.png
Normal file
After Width: | Height: | Size: 20 KiB |
BIN
web/favicon.png
Normal file
After Width: | Height: | Size: 917 B |
BIN
web/icons/Icon-192.png
Normal file
After Width: | Height: | Size: 5.2 KiB |
BIN
web/icons/Icon-512.png
Normal file
After Width: | Height: | Size: 8.1 KiB |
BIN
web/icons/Icon-maskable-192.png
Normal file
After Width: | Height: | Size: 5.5 KiB |
BIN
web/icons/Icon-maskable-512.png
Normal file
After Width: | Height: | Size: 20 KiB |
58
web/index.html
Normal file
@ -0,0 +1,58 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<!--
|
||||
If you are serving your web app in a path other than the root, change the
|
||||
href value below to reflect the base path you are serving from.
|
||||
|
||||
The path provided below has to start and end with a slash "/" in order for
|
||||
it to work correctly.
|
||||
|
||||
For more details:
|
||||
* https://developer.mozilla.org/en-US/docs/Web/HTML/Element/base
|
||||
|
||||
This is a placeholder for base href that will be replaced by the value of
|
||||
the `--base-href` argument provided to `flutter build`.
|
||||
-->
|
||||
<base href="$FLUTTER_BASE_HREF">
|
||||
|
||||
<meta charset="UTF-8">
|
||||
<meta content="IE=Edge" http-equiv="X-UA-Compatible">
|
||||
<meta name="description" content="A new Flutter project.">
|
||||
|
||||
<!-- iOS meta tags & icons -->
|
||||
<meta name="apple-mobile-web-app-capable" content="yes">
|
||||
<meta name="apple-mobile-web-app-status-bar-style" content="black">
|
||||
<meta name="apple-mobile-web-app-title" content="diet4you">
|
||||
<link rel="apple-touch-icon" href="icons/Icon-192.png">
|
||||
|
||||
<!-- Favicon -->
|
||||
<link rel="icon" type="image/png" href="favicon.png"/>
|
||||
|
||||
<title>diet4you</title>
|
||||
<link rel="manifest" href="manifest.json">
|
||||
|
||||
<script>
|
||||
// The value below is injected by flutter build, do not touch.
|
||||
var serviceWorkerVersion = null;
|
||||
</script>
|
||||
<!-- This script adds the flutter initialization JS code -->
|
||||
<script src="flutter.js" defer></script>
|
||||
</head>
|
||||
<body>
|
||||
<script>
|
||||
window.addEventListener('load', function(ev) {
|
||||
// Download main.dart.js
|
||||
_flutter.loader.loadEntrypoint({
|
||||
serviceWorker: {
|
||||
serviceWorkerVersion: serviceWorkerVersion,
|
||||
}
|
||||
}).then(function(engineInitializer) {
|
||||
return engineInitializer.initializeEngine();
|
||||
}).then(function(appRunner) {
|
||||
return appRunner.runApp();
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
35
web/manifest.json
Normal file
@ -0,0 +1,35 @@
|
||||
{
|
||||
"name": "diet4you",
|
||||
"short_name": "diet4you",
|
||||
"start_url": ".",
|
||||
"display": "standalone",
|
||||
"background_color": "#0175C2",
|
||||
"theme_color": "#0175C2",
|
||||
"description": "A new Flutter project.",
|
||||
"orientation": "portrait-primary",
|
||||
"prefer_related_applications": false,
|
||||
"icons": [
|
||||
{
|
||||
"src": "icons/Icon-192.png",
|
||||
"sizes": "192x192",
|
||||
"type": "image/png"
|
||||
},
|
||||
{
|
||||
"src": "icons/Icon-512.png",
|
||||
"sizes": "512x512",
|
||||
"type": "image/png"
|
||||
},
|
||||
{
|
||||
"src": "icons/Icon-maskable-192.png",
|
||||
"sizes": "192x192",
|
||||
"type": "image/png",
|
||||
"purpose": "maskable"
|
||||
},
|
||||
{
|
||||
"src": "icons/Icon-maskable-512.png",
|
||||
"sizes": "512x512",
|
||||
"type": "image/png",
|
||||
"purpose": "maskable"
|
||||
}
|
||||
]
|
||||
}
|