v1.0.4 webapi fixes
This commit is contained in:
@@ -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),
|
||||
),
|
||||
|
||||
],
|
||||
)
|
||||
|
||||
],
|
||||
),
|
||||
),
|
||||
));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user