Skip to content

Commit d259292

Browse files
minor changes
1 parent bf82294 commit d259292

File tree

1 file changed

+106
-160
lines changed

1 file changed

+106
-160
lines changed

lib/Pages/home_page.dart

Lines changed: 106 additions & 160 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@ import 'package:brain_fusion/brain_fusion.dart';
55
import 'package:flutter/foundation.dart';
66
import 'package:flutter/material.dart';
77
import 'package:fluttertoast/fluttertoast.dart';
8+
import 'package:iconsax/iconsax.dart';
89
import 'package:image_gallery_saver/image_gallery_saver.dart';
910
import 'package:lottie/lottie.dart';
1011
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';
1213
import 'package:flutter/rendering.dart';
1314

1415
class HomePage extends StatefulWidget {
@@ -22,6 +23,7 @@ class _HomePageState extends State<HomePage> {
2223
final TextEditingController _queryController = TextEditingController();
2324

2425
final AI _ai = AI();
26+
Uint8List? _generatedImage;
2527

2628
Future<Uint8List> _generate(String query) async {
2729
Uint8List image = await _ai.runAI(query, AIStyle.render3D);
@@ -42,133 +44,55 @@ class _HomePageState extends State<HomePage> {
4244
}
4345

4446
var scaffoldKey = GlobalKey<ScaffoldState>();
47+
4548
@override
4649
Widget build(BuildContext context) {
4750
return Scaffold(
4851
key: scaffoldKey,
49-
backgroundColor: Colors.deepPurple.shade50,
5052
appBar: AppBar(
51-
iconTheme: IconThemeData(color: Colors.deepPurple.shade400),
53+
iconTheme:
54+
IconThemeData(color: Theme.of(context).colorScheme.secondary),
5255
backgroundColor: Colors.transparent,
5356
title: RichText(
5457
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+
],
6374
),
6475
),
6576
elevation: 0,
6677
centerTitle: true,
6778
leading: InkWell(
68-
onTap: (){
79+
onTap: () {
6980
scaffoldKey.currentState?.openDrawer();
7081
},
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),
8083
),
8184
actions: [
8285
InkWell(
83-
onTap: (){
84-
Navigator.push(context, MaterialPageRoute(builder: (context) => const AboutPage()));
86+
onTap: () {
87+
Navigator.push(context,
88+
MaterialPageRoute(builder: (context) => const AboutPage()));
8589
},
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)),
9592
),
9693
],
9794
),
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(),
17296
body: SingleChildScrollView(
17397
physics: const BouncingScrollPhysics(),
17498
child: Column(
@@ -181,6 +105,10 @@ class _HomePageState extends State<HomePage> {
181105
Padding(
182106
padding: const EdgeInsets.all(6.0),
183107
child: TextField(
108+
style: TextStyle(
109+
fontSize: 16,
110+
color: Theme.of(context).colorScheme.secondary,
111+
),
184112
keyboardType: TextInputType.multiline,
185113
minLines: 1,
186114
maxLines: 10,
@@ -191,14 +119,14 @@ class _HomePageState extends State<HomePage> {
191119
borderRadius: BorderRadius.circular(8),
192120
borderSide: BorderSide(
193121
width: 1.5,
194-
color: Colors.deepPurple.shade400,
122+
color: Theme.of(context).colorScheme.secondary,
195123
),
196124
),
197125
focusedBorder: OutlineInputBorder(
198126
borderRadius: BorderRadius.circular(8),
199127
borderSide: BorderSide(
200128
width: 1.5,
201-
color: Colors.deepPurple.shade400,
129+
color: Theme.of(context).colorScheme.secondary,
202130
),
203131
),
204132
),
@@ -211,49 +139,55 @@ class _HomePageState extends State<HomePage> {
211139
width: MediaQuery.of(context).size.width,
212140
child: run
213141
? 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(
229183
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'),
231189
),
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+
),
257191
),
258192
),
259193
SizedBox(
@@ -262,10 +196,10 @@ class _HomePageState extends State<HomePage> {
262196
const Text(
263197
'Click the image to save in Gallery.',
264198
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'),
269203
),
270204
const SizedBox(
271205
height: 15,
@@ -278,6 +212,7 @@ class _HomePageState extends State<HomePage> {
278212
if (newQuery.isNotEmpty) {
279213
setState(() {
280214
query = newQuery;
215+
_generatedImage = null; // Clear the cached image
281216
run = true;
282217
});
283218
} else {
@@ -323,7 +258,11 @@ class _HomePageState extends State<HomePage> {
323258
child: const Text(
324259
'Generate',
325260
textAlign: TextAlign.center,
326-
style: TextStyle(fontSize: 18),
261+
style: TextStyle(
262+
fontSize: 18,
263+
fontFamily: 'Nexa',
264+
color: Colors.white,
265+
),
327266
),
328267
),
329268
),
@@ -332,16 +271,22 @@ class _HomePageState extends State<HomePage> {
332271
],
333272
),
334273
),
335-
bottomNavigationBar: const Padding(
336-
padding: EdgeInsets.only(bottom: 8),
274+
bottomNavigationBar: Padding(
275+
padding: const EdgeInsets.only(bottom: 7),
337276
child: Text(
338277
"Made With Love ❤️ VikiMedia",
339278
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+
),
341285
),
342286
),
343287
);
344288
}
289+
345290
_saveScreen() async {
346291
if (_isDownloading) {
347292
// Do nothing if a download is already in progress.
@@ -364,9 +309,10 @@ class _HomePageState extends State<HomePage> {
364309
);
365310
_isDownloading = true;
366311
RenderRepaintBoundary boundary =
367-
_globalKey.currentContext!.findRenderObject() as RenderRepaintBoundary;
312+
_globalKey.currentContext!.findRenderObject() as RenderRepaintBoundary;
368313
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));
370316
if (byteData != null) {
371317
final result = await ImageGallerySaver.saveImage(
372318
byteData.buffer.asUint8List(),
@@ -383,4 +329,4 @@ class _HomePageState extends State<HomePage> {
383329
_isDownloadInitiated = false;
384330
_isDownloading = false;
385331
}
386-
}
332+
}

0 commit comments

Comments
 (0)