v1.0.4 webapi fixes

This commit is contained in:
Tibor Bossanyi
2023-02-13 19:56:15 +01:00
parent 65e9daa273
commit 0f58f893e6
20 changed files with 199 additions and 14 deletions
+75
View 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),
),
],
)
],
),
),
));
}
}