@@ -5,10 +5,11 @@ import 'package:brain_fusion/brain_fusion.dart';
5
5
import 'package:flutter/foundation.dart' ;
6
6
import 'package:flutter/material.dart' ;
7
7
import 'package:fluttertoast/fluttertoast.dart' ;
8
+ import 'package:iconsax/iconsax.dart' ;
8
9
import 'package:image_gallery_saver/image_gallery_saver.dart' ;
9
10
import 'package:lottie/lottie.dart' ;
10
11
import 'package:text_to_image_gen/Pages/about_page.dart' ;
11
- import 'package:url_launcher/url_launcher .dart' ;
12
+ import 'package:text_to_image_gen/widgets/custom_drawer .dart' ;
12
13
import 'package:flutter/rendering.dart' ;
13
14
14
15
class HomePage extends StatefulWidget {
@@ -22,6 +23,7 @@ class _HomePageState extends State<HomePage> {
22
23
final TextEditingController _queryController = TextEditingController ();
23
24
24
25
final AI _ai = AI ();
26
+ Uint8List ? _generatedImage;
25
27
26
28
Future <Uint8List > _generate (String query) async {
27
29
Uint8List image = await _ai.runAI (query, AIStyle .render3D);
@@ -42,133 +44,55 @@ class _HomePageState extends State<HomePage> {
42
44
}
43
45
44
46
var scaffoldKey = GlobalKey <ScaffoldState >();
47
+
45
48
@override
46
49
Widget build (BuildContext context) {
47
50
return Scaffold (
48
51
key: scaffoldKey,
49
- backgroundColor: Colors .deepPurple.shade50,
50
52
appBar: AppBar (
51
- iconTheme: IconThemeData (color: Colors .deepPurple.shade400),
53
+ iconTheme:
54
+ IconThemeData (color: Theme .of (context).colorScheme.secondary),
52
55
backgroundColor: Colors .transparent,
53
56
title: RichText (
54
57
text: TextSpan (
55
- text: 'Tex' ,
56
- style: TextStyle (color: Colors .amber.shade900, fontWeight: FontWeight .w500, fontSize: 18 ),
57
- children: [
58
- TextSpan (
59
- text: 'Fusion' ,
60
- style: TextStyle (color: Colors .deepPurple.shade500, fontWeight: FontWeight .w500, fontSize: 18 ),
61
- )
62
- ]
58
+ text: 'Tex' ,
59
+ style: TextStyle (
60
+ color: Colors .amber.shade900,
61
+ fontWeight: FontWeight .bold,
62
+ fontSize: 18 ,
63
+ fontFamily: 'Aesthetic' ),
64
+ children: [
65
+ TextSpan (
66
+ text: 'Fusion' ,
67
+ style: TextStyle (
68
+ color: Theme .of (context).colorScheme.secondary,
69
+ fontWeight: FontWeight .bold,
70
+ fontSize: 18 ,
71
+ fontFamily: 'Aesthetic' ),
72
+ )
73
+ ],
63
74
),
64
75
),
65
76
elevation: 0 ,
66
77
centerTitle: true ,
67
78
leading: InkWell (
68
- onTap: (){
79
+ onTap: () {
69
80
scaffoldKey.currentState? .openDrawer ();
70
81
},
71
- child: Padding (
72
- padding: const EdgeInsets .all (8.0 ),
73
- child: Lottie .asset (
74
- 'assets/animations/me.json' ,
75
- repeat: true ,
76
- reverse: true ,
77
- animate: true ,
78
- ),
79
- ),
82
+ child: const Icon (Iconsax .element_plus),
80
83
),
81
84
actions: [
82
85
InkWell (
83
- onTap: (){
84
- Navigator .push (context, MaterialPageRoute (builder: (context) => const AboutPage ()));
86
+ onTap: () {
87
+ Navigator .push (context,
88
+ MaterialPageRoute (builder: (context) => const AboutPage ()));
85
89
},
86
- child: Padding (
87
- padding: const EdgeInsets .all (12 ),
88
- child: Lottie .asset (
89
- 'assets/animations/set.json' ,
90
- repeat: true ,
91
- reverse: true ,
92
- animate: true ,
93
- ),
94
- ),
90
+ child: const Padding (
91
+ padding: EdgeInsets .all (12 ), child: Icon (Iconsax .setting_2)),
95
92
),
96
93
],
97
94
),
98
- drawer: Drawer (
99
- child: Container (
100
- color: Colors .deepPurple.shade50,
101
- child: Column (
102
- children: [
103
- Container (
104
- color: Colors .deepPurple.shade50,
105
- child: DrawerHeader (
106
- child: Center (
107
- child: Text (
108
- "TexFusion AI App" ,
109
- style: TextStyle (
110
- fontSize: 18 , color: Colors .deepPurple.shade400),
111
- ),
112
- ),
113
- ),
114
- ),
115
- ListTile (
116
- leading: const Icon (
117
- Icons .source_rounded,
118
- color: Colors .black54,
119
- ),
120
- title: Text (
121
- "Source Code" ,
122
- style: TextStyle (
123
- fontSize: 16 , color: Colors .deepPurple.shade400),
124
- ),
125
- onTap: () async {
126
- final Uri url = Uri .parse (
127
- 'https://github.com/VikramadityaDev/text_to_image_gen/' );
128
- if (! await launchUrl (url,
129
- mode: LaunchMode .externalApplication)) {
130
- throw Exception ('Could not launch $url ' );
131
- }
132
- },
133
- ),
134
- ListTile (
135
- leading: const Icon (
136
- Icons .update,
137
- color: Colors .black54,
138
- ),
139
- title: Text (
140
- "Check for update" ,
141
- style: TextStyle (
142
- fontSize: 16 , color: Colors .deepPurple.shade400),
143
- ),
144
- onTap: () async {
145
- final Uri url =
146
- Uri .parse ('https://telegram.me/vikimediaofficial/' );
147
- if (! await launchUrl (url,
148
- mode: LaunchMode .externalApplication)) {
149
- throw Exception ('Could not launch $url ' );
150
- }
151
- },
152
- ),
153
- Expanded (
154
- child: Padding (
155
- padding: const EdgeInsets .all (10 ),
156
- child: Align (
157
- alignment: Alignment .bottomCenter,
158
- child: Text (
159
- 'v1.0.2' ,
160
- style: TextStyle (
161
- fontSize: 16 ,
162
- color: Colors .deepPurple.shade400,
163
- fontWeight: FontWeight .w500),
164
- ),
165
- ),
166
- ),
167
- ),
168
- ],
169
- ),
170
- ),
171
- ),
95
+ drawer: const CustomDrawer (),
172
96
body: SingleChildScrollView (
173
97
physics: const BouncingScrollPhysics (),
174
98
child: Column (
@@ -181,6 +105,10 @@ class _HomePageState extends State<HomePage> {
181
105
Padding (
182
106
padding: const EdgeInsets .all (6.0 ),
183
107
child: TextField (
108
+ style: TextStyle (
109
+ fontSize: 16 ,
110
+ color: Theme .of (context).colorScheme.secondary,
111
+ ),
184
112
keyboardType: TextInputType .multiline,
185
113
minLines: 1 ,
186
114
maxLines: 10 ,
@@ -191,14 +119,14 @@ class _HomePageState extends State<HomePage> {
191
119
borderRadius: BorderRadius .circular (8 ),
192
120
borderSide: BorderSide (
193
121
width: 1.5 ,
194
- color: Colors .deepPurple.shade400 ,
122
+ color: Theme . of (context).colorScheme.secondary ,
195
123
),
196
124
),
197
125
focusedBorder: OutlineInputBorder (
198
126
borderRadius: BorderRadius .circular (8 ),
199
127
borderSide: BorderSide (
200
128
width: 1.5 ,
201
- color: Colors .deepPurple.shade400 ,
129
+ color: Theme . of (context).colorScheme.secondary ,
202
130
),
203
131
),
204
132
),
@@ -211,49 +139,55 @@ class _HomePageState extends State<HomePage> {
211
139
width: MediaQuery .of (context).size.width,
212
140
child: run
213
141
? FutureBuilder <Uint8List >(
214
- future: _generate (_queryController.text),
215
- builder: (context, snapshot) {
216
- if (snapshot.connectionState ==
217
- ConnectionState .waiting) {
218
- return Padding (
219
- padding: const EdgeInsets .all (120.0 ),
220
- child: Lottie .asset (
221
- 'assets/animations/loading.json' ,
222
- repeat: true ,
223
- reverse: true ,
224
- animate: true ,
225
- ),
226
- );
227
- } else if (snapshot.hasError) {
228
- return const Center (
142
+ future: _generatedImage != null ? Future .value (_generatedImage) : _generate (_queryController.text),
143
+ builder: (context, snapshot) {
144
+ if (snapshot.connectionState ==
145
+ ConnectionState .waiting) {
146
+ return Padding (
147
+ padding: const EdgeInsets .all (120.0 ),
148
+ child: Lottie .asset (
149
+ 'assets/animations/loading.json' ,
150
+ repeat: true ,
151
+ reverse: true ,
152
+ animate: true ,
153
+ ),
154
+ );
155
+ } else if (snapshot.hasError) {
156
+ return Center (
157
+ child: Text (
158
+ 'Something went wrong. Please Re-generate.' ,
159
+ style: TextStyle (
160
+ fontSize: 14 ,
161
+ color: Colors .red.shade400,
162
+ fontFamily: 'Nexa' ),
163
+ ),
164
+ );
165
+ } else if (snapshot.hasData) {
166
+ // If the image was just generated, store it in the _generatedImage variable
167
+ _generatedImage ?? = snapshot.data;
168
+ return RepaintBoundary (
169
+ key: _globalKey,
170
+ child: InkWell (
171
+ onTap: () {
172
+ _saveScreen ();
173
+ },
174
+ child: Image .memory (snapshot.data! ),
175
+ ),
176
+ );
177
+ } else {
178
+ return Container ();
179
+ }
180
+ },
181
+ )
182
+ : Center (
229
183
child: Text (
230
- 'Something went wrong. Please Re-generate.' ,
184
+ 'See Magic Here 🪄' ,
185
+ style: TextStyle (
186
+ fontSize: 16 ,
187
+ color: Theme .of (context).colorScheme.secondary,
188
+ fontFamily: 'Nexa' ),
231
189
),
232
- );
233
- } else if (snapshot.hasData) {
234
- return RepaintBoundary (
235
- key: _globalKey,
236
- child: InkWell (
237
- onTap: () {
238
- _saveScreen ();
239
- },
240
- child: Image .memory (snapshot.data! ),
241
- ),
242
- );
243
- } else {
244
- return Container ();
245
- }
246
- },
247
- )
248
- : const Center (
249
- child: Text (
250
- 'See Magic Here 🪄' ,
251
- style: TextStyle (
252
- fontWeight: FontWeight .w500,
253
- fontSize: 16 ,
254
- ),
255
- ),
256
- ),
190
+ ),
257
191
),
258
192
),
259
193
SizedBox (
@@ -262,10 +196,10 @@ class _HomePageState extends State<HomePage> {
262
196
const Text (
263
197
'Click the image to save in Gallery.' ,
264
198
softWrap: true ,
265
- style: TextStyle (fontSize : 15 , fontWeight : FontWeight .w500),
266
- ) ,
267
- const SizedBox (
268
- height : 5 ,
199
+ style: TextStyle (
200
+ fontSize : 14 ,
201
+ fontWeight : FontWeight .bold,
202
+ fontFamily : 'Nexa' ) ,
269
203
),
270
204
const SizedBox (
271
205
height: 15 ,
@@ -278,6 +212,7 @@ class _HomePageState extends State<HomePage> {
278
212
if (newQuery.isNotEmpty) {
279
213
setState (() {
280
214
query = newQuery;
215
+ _generatedImage = null ; // Clear the cached image
281
216
run = true ;
282
217
});
283
218
} else {
@@ -323,7 +258,11 @@ class _HomePageState extends State<HomePage> {
323
258
child: const Text (
324
259
'Generate' ,
325
260
textAlign: TextAlign .center,
326
- style: TextStyle (fontSize: 18 ),
261
+ style: TextStyle (
262
+ fontSize: 18 ,
263
+ fontFamily: 'Nexa' ,
264
+ color: Colors .white,
265
+ ),
327
266
),
328
267
),
329
268
),
@@ -332,16 +271,22 @@ class _HomePageState extends State<HomePage> {
332
271
],
333
272
),
334
273
),
335
- bottomNavigationBar: const Padding (
336
- padding: EdgeInsets .only (bottom: 8 ),
274
+ bottomNavigationBar: Padding (
275
+ padding: const EdgeInsets .only (bottom: 7 ),
337
276
child: Text (
338
277
"Made With Love ❤️ VikiMedia" ,
339
278
textAlign: TextAlign .center,
340
- style: TextStyle (fontSize: 12 ),
279
+ style: TextStyle (
280
+ fontSize: 11 ,
281
+ fontWeight: FontWeight .bold,
282
+ fontFamily: 'NexaLight' ,
283
+ color: Theme .of (context).colorScheme.secondary,
284
+ ),
341
285
),
342
286
),
343
287
);
344
288
}
289
+
345
290
_saveScreen () async {
346
291
if (_isDownloading) {
347
292
// Do nothing if a download is already in progress.
@@ -364,9 +309,10 @@ class _HomePageState extends State<HomePage> {
364
309
);
365
310
_isDownloading = true ;
366
311
RenderRepaintBoundary boundary =
367
- _globalKey.currentContext! .findRenderObject () as RenderRepaintBoundary ;
312
+ _globalKey.currentContext! .findRenderObject () as RenderRepaintBoundary ;
368
313
ui.Image image = await boundary.toImage (pixelRatio: 12 );
369
- ByteData ? byteData = await (image.toByteData (format: ui.ImageByteFormat .png));
314
+ ByteData ? byteData =
315
+ await (image.toByteData (format: ui.ImageByteFormat .png));
370
316
if (byteData != null ) {
371
317
final result = await ImageGallerySaver .saveImage (
372
318
byteData.buffer.asUint8List (),
@@ -383,4 +329,4 @@ class _HomePageState extends State<HomePage> {
383
329
_isDownloadInitiated = false ;
384
330
_isDownloading = false ;
385
331
}
386
- }
332
+ }
0 commit comments