bogui/lib/screens/home.dart

168 lines
6.2 KiB
Dart

import 'package:bogui/global.dart';
import 'package:bogui/riverpods/openai.dart';
import 'package:bogui/widgets/parameters_sliders.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
// import 'package:flutter/gestures.dart';
// import 'dart:math';
class Bogui extends ConsumerStatefulWidget {
const Bogui({super.key, required this.title});
final String title;
@override
ConsumerState<Bogui> createState() => _BoguiState();
}
class _BoguiState extends ConsumerState<Bogui> {
late OpenAI gpt;
final promptFocus = FocusNode();
@override
void initState() {
gpt = OpenAI();
gpt.init();
super.initState();
}
_handleValidation() {
gpt.completionEasy(ref);
promptFocus.requestFocus();
}
@override
Widget build(BuildContext context) {
final scrollController = ScrollController();
screenWidth = MediaQuery.of(context).size.width;
// screenHight = MediaQuery.of(context).size.height;
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: SizedBox(
width: screenWidth,
child: Listener(
onPointerSignal: (_) {
// if (_ is PointerScrollEvent) {
// scrollController.jumpTo(
// max(
// min(
// scrollController.position.maxScrollExtent,
// scrollController.offset + _.scrollDelta.dx,
// ),
// scrollController.position.minScrollExtent,
// ),
// );
// }
},
child: SingleChildScrollView(
controller: scrollController,
child:
Row(mainAxisAlignment: MainAxisAlignment.center, children: [
const Spacer(flex: 3),
Column(children: <Widget>[
const SizedBox(height: 40),
Container(
constraints: const BoxConstraints(minWidth: 300),
width: screenWidth - 600,
child: CallbackShortcuts(
bindings: {
LogicalKeySet(LogicalKeyboardKey.control,
LogicalKeyboardKey.enter):
(() => _handleValidation()),
},
child: TextField(
scrollPhysics: const NeverScrollableScrollPhysics(),
focusNode: promptFocus,
controller: ref.read(gpt.prompt),
autofocus: true,
textInputAction: TextInputAction.search,
// minLines: 3,
maxLines: null,
keyboardType: TextInputType.multiline,
cursorColor: orangeC,
style: TextStyle(color: Colors.grey[400], fontSize: 16),
decoration: InputDecoration(
hintText: "Qu'ils aillent tous se faire enculer",
filled: true,
// fillColor: Colors.white,
prefixIconConstraints: const BoxConstraints(
minHeight: 32,
),
prefixIcon: const Padding(
padding: EdgeInsets.symmetric(horizontal: 17),
child: Icon(
Icons.fireplace_rounded,
color: orangeC,
size: 30,
)),
border: OutlineInputBorder(
borderSide: BorderSide(
color: Colors.grey[500]!, width: 2),
borderRadius: BorderRadius.circular(8)),
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(
color: Colors.grey[500]!, width: 2.5),
borderRadius: BorderRadius.circular(8),
),
contentPadding: const EdgeInsets.all(20),
),
onSubmitted: (value) => promptFocus.requestFocus(),
),
),
),
const SizedBox(height: 40),
SizedBox(
width: 250,
height: 50,
child: ElevatedButton(
style: ElevatedButton.styleFrom(
foregroundColor: Colors.white, elevation: 4,
backgroundColor: orangeC, // foreground
),
onPressed:
ref.watch(gpt.prompt).text.length > 100000000000
? null
: () {
_handleValidation();
},
child: ref.watch(gpt.isLoading)
? SizedBox(
height: 18,
width: 18,
child: CircularProgressIndicator(
color: Colors.grey[800],
strokeWidth: 4,
),
)
: const Text(
'Valider',
style: TextStyle(
fontSize: 21, fontWeight: FontWeight.w500),
),
),
),
const SizedBox(height: 40),
]),
const Spacer(),
Column(
children: [
CustomSlider(
parameter: gpt.temperature,
nameParameter: 'Température',
),
],
),
const Spacer(),
]),
),
),
),
),
);
}
}