bogui/lib/screens/home.dart

228 lines
8.5 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:url_launcher/url_launcher.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;
return Scaffold(
appBar: AppBar(
leading: Row(
children: [
const SizedBox(
width: 20,
),
InkWell(
onTap: () =>
launchUrl(Uri.parse('https://git.p2p.legal/librezo/bogui')),
child: Container(
height: 35,
decoration: BoxDecoration(
boxShadow: [
BoxShadow(
color: yellowC.withOpacity(0.4),
spreadRadius: 2,
blurRadius: 1,
offset:
const Offset(0, 0), // changes position of shadow
),
],
gradient: const RadialGradient(
center: Alignment(3, -3),
colors: [yellowC, orangeC],
radius: 3.4,
),
borderRadius: BorderRadius.circular(35),
// color: Colors.grey[400],
),
child: Image.asset(
'assets/gitea.png',
// color: yellowC,
scale: 45,
),
)),
],
),
bottomOpacity: 0.5,
backgroundColor: orangeC,
title: Center(
child: Text(
widget.title,
style: const TextStyle(fontSize: 16),
)),
),
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: [
Spacer(flex: screenWidth > 800 ? 3 : 2),
Column(children: <Widget>[
const SizedBox(height: 40),
Container(
constraints:
const BoxConstraints(minWidth: 500, maxWidth: 700),
width: screenWidth - 600,
child: CallbackShortcuts(
bindings: {
LogicalKeySet(LogicalKeyboardKey.control,
LogicalKeyboardKey.enter):
(() => _handleValidation()),
},
child: TextField(
autocorrect: false,
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: 14),
decoration: InputDecoration(
filled: true,
helperText:
"Laissez-le autocompléter votre texte plutôt que de lui poser une question...",
helperStyle: const TextStyle(fontSize: 10),
hintText: "Qu'ils aillent tous se faire recompiler",
hintStyle: TextStyle(
color: Colors.grey[50],
fontWeight: FontWeight.w100,
fontSize: 12),
// fillColor: Colors.white,
prefixIconConstraints: const BoxConstraints(
minHeight: 32,
),
prefixIcon: const Padding(
padding: EdgeInsets.symmetric(horizontal: 17),
child: Icon(
Icons.agriculture_outlined,
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),
Opacity(
opacity: 0.8,
child: 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: 5),
const Text(
'ctrl + entrer',
style: TextStyle(fontSize: 12, fontWeight: FontWeight.w100),
),
const SizedBox(height: 40),
]),
const Spacer(),
if (screenWidth > 800)
Column(
children: [
CustomSlider(
parameter: gpt.temperature,
nameParameter: 'Température',
),
],
),
const Spacer(),
]),
),
),
),
),
);
}
}