Skip to content

Commit

Permalink
feat: add build functionality and naming to PaintWindow
Browse files Browse the repository at this point in the history
  • Loading branch information
jacob-i committed Dec 26, 2023
1 parent 0632b12 commit b598ae7
Showing 1 changed file with 83 additions and 29 deletions.
112 changes: 83 additions & 29 deletions app/lib/paint_window.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,44 +7,98 @@ class PaintWindow extends StatefulWidget {

class _PaintWindowState extends State<PaintWindow> {
List<Offset?> points = [];
final TextEditingController nameController = TextEditingController();
String creationName = '';
bool isLoading = false;

@override
void dispose() {
nameController.dispose();
super.dispose();
}

Future<void> callOpenAI() async {
setState(() {
isLoading = true;
});
// Convert points to a suitable format and call OpenAI method
// For example, you might convert points to an image and then to base64
// String imageBase64 = convertToBase64(points); // Implement this function
// String htmlResponse = await OpenAI_API().getHtmlFromOpenAI(imageBase64, creationName);

// Do something with htmlResponse

setState(() {
isLoading = false;
});
}

@override
Widget build(BuildContext context) {
return AlertDialog(
title: const Text('Paint Window'),
content: Container(
width: double.infinity,
height: 300,
decoration: BoxDecoration(
border: Border.all(color: Colors.black),
color: Colors.white,
),
child: GestureDetector(
onPanUpdate: (DragUpdateDetails details) {
setState(() {
RenderBox renderBox = context.findRenderObject() as RenderBox;
points.add(renderBox.globalToLocal(details.localPosition));
});
},
onPanEnd: (DragEndDetails details) {
setState(() {
points.add(null); // Add a null to the list to separate the lines
});
},
child: CustomPaint(
painter: DrawingPainter(points: points),
size: Size.infinite,
),
content: SingleChildScrollView(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Container(
width: double.infinity,
height: 300,
decoration: BoxDecoration(
border: Border.all(color: Colors.black),
color: Colors.white,
),
child: GestureDetector(
onPanUpdate: (DragUpdateDetails details) {
setState(() {
RenderBox renderBox =
context.findRenderObject() as RenderBox;
points.add(renderBox.globalToLocal(details.localPosition));
});
},
onPanEnd: (DragEndDetails details) {
setState(() {
points.add(
null); // Add a null to the list to separate the lines
});
},
child: CustomPaint(
painter: DrawingPainter(points: points),
size: Size.infinite,
),
),
),
Padding(
padding: EdgeInsets.all(8.0),
child: TextField(
controller: nameController,
decoration: InputDecoration(
labelText: 'Name your creation',
),
onChanged: (value) {
creationName = value;
},
),
),
],
),
),
actions: <Widget>[
if (isLoading)
CircularProgressIndicator()
else
TextButton(
child: const Text('Clear'),
onPressed: () {
setState(() {
points.clear();
});
},
),
TextButton(
child: const Text('Clear'),
onPressed: () {
setState(() {
points.clear();
});
},
child: const Text('Build'),
onPressed:
callOpenAI, // Here we call the method to process the drawing
),
TextButton(
child: const Text('Close'),
Expand Down

0 comments on commit b598ae7

Please sign in to comment.