11import 'package:flutter/material.dart' ;
2+ import 'package:http/http.dart' as http;
3+ import 'dart:convert' ;
4+ import 'package:flutter/services.dart' ;
5+
26
37void main () {
48 runApp (const MyApp ());
@@ -7,119 +11,269 @@ void main() {
711class MyApp extends StatelessWidget {
812 const MyApp ({super .key});
913
10- // This widget is the root of your application.
1114 @override
1215 Widget build (BuildContext context) {
1316 return MaterialApp (
14- title: 'Flutter Demo' ,
1517 theme: ThemeData (
16- // This is the theme of your application.
17- //
18- // TRY THIS: Try running your application with "flutter run". You'll see
19- // the application has a purple toolbar. Then, without quitting the app,
20- // try changing the seedColor in the colorScheme below to Colors.green
21- // and then invoke "hot reload" (save your changes or press the "hot
22- // reload" button in a Flutter-supported IDE, or press "r" if you used
23- // the command line to start the app).
24- //
25- // Notice that the counter didn't reset back to zero; the application
26- // state is not lost during the reload. To reset the state, use hot
27- // restart instead.
28- //
29- // This works for code too, not just values: Most code changes can be
30- // tested with just a hot reload.
31- colorScheme: ColorScheme .fromSeed (seedColor: Colors .deepPurple),
3218 useMaterial3: true ,
3319 ),
34- home: const MyHomePage (title: 'Flutter Demo Home Page' ),
20+ debugShowCheckedModeBanner: false ,
21+ home: const MyHomePage (),
3522 );
3623 }
3724}
3825
3926class MyHomePage extends StatefulWidget {
40- const MyHomePage ({super .key, required this .title});
41-
42- // This widget is the home page of your application. It is stateful, meaning
43- // that it has a State object (defined below) that contains fields that affect
44- // how it looks.
45-
46- // This class is the configuration for the state. It holds the values (in this
47- // case the title) provided by the parent (in this case the App widget) and
48- // used by the build method of the State. Fields in a Widget subclass are
49- // always marked "final".
50-
51- final String title;
27+ const MyHomePage ({super .key});
5228
5329 @override
54- State < MyHomePage > createState () => _MyHomePageState ();
30+ _MyHomePageState createState () => _MyHomePageState ();
5531}
5632
5733class _MyHomePageState extends State <MyHomePage > {
58- int _counter = 0 ;
34+ String email = '' ;
35+ String message = '' ;
36+ String token = '' ;
37+ String toEmail = '' ;
38+
39+
40+ Future <void > fetchData () async {
41+ const url = "https://free-tempmail-api.p.rapidapi.com/newmail" ;
42+
43+ final headers = {
44+ "X-RapidAPI-Key" : "YOUR_API_KEY" ,
45+ "X-RapidAPI-Host" : "free-tempmail-api.p.rapidapi.com"
46+ };
47+
48+ final response = await http.get (Uri .parse (url), headers: headers);
49+ final info = jsonDecode (response.body);
50+ final email = info["newmail" ]["email" ].toString ();
51+ final token = info["newmail" ]["token" ].toString ();
52+
53+ const mailsUrl = "https://free-tempmail-api.p.rapidapi.com/mails" ;
54+ final mailsHeaders = {
55+ "mailtoken" : token,
56+ "X-RapidAPI-Key" : "YOUR_API_KEY" ,
57+ "X-RapidAPI-Host" : "free-tempmail-api.p.rapidapi.com"
58+ };
59+
60+ final mailsResponse = await http.get (Uri .parse (mailsUrl), headers: mailsHeaders);
61+ final mailsInfo = jsonDecode (mailsResponse.body);
62+ final message = mailsInfo["message" ].toString ();
5963
60- void _incrementCounter () {
6164 setState (() {
62- // This call to setState tells the Flutter framework that something has
63- // changed in this State, which causes it to rerun the build method below
64- // so that the display can reflect the updated values. If we changed
65- // _counter without calling setState(), then the build method would not be
66- // called again, and so nothing would appear to happen.
67- _counter++ ;
65+ this .email = email;
66+ this .token = token;
67+ this .message = message;
68+ });
69+ }
70+
71+ Future <void > updateMessage () async {
72+ const mailsUrl = "https://free-tempmail-api.p.rapidapi.com/mails" ;
73+ final mailsHeaders = {
74+ "mailtoken" : token,
75+ "X-RapidAPI-Key" : "YOUR_API_KEY" ,
76+ "X-RapidAPI-Host" : "free-tempmail-api.p.rapidapi.com"
77+ };
78+
79+ final mailsResponse = await http.get (Uri .parse (mailsUrl), headers: mailsHeaders);
80+ final mailsInfo = jsonDecode (mailsResponse.body);
81+ final updatedMessage = mailsInfo["mails" ][0 ]["intro" ].toString ();
82+ final toEmail = mailsInfo["mails" ][0 ]["from" ]["address" ].toString ();
83+ debugPrint (mailsInfo);
84+ setState (() {
85+ message = updatedMessage;
86+ this .toEmail = toEmail;
6887 });
6988 }
7089
7190 @override
7291 Widget build (BuildContext context) {
73- // This method is rerun every time setState is called, for instance as done
74- // by the _incrementCounter method above.
75- //
76- // The Flutter framework has been optimized to make rerunning build methods
77- // fast, so that you can just rebuild anything that needs updating rather
78- // than having to individually change instances of widgets.
7992 return Scaffold (
8093 appBar: AppBar (
81- // TRY THIS: Try changing the color here to a specific color (to
82- // Colors.amber, perhaps?) and trigger a hot reload to see the AppBar
83- // change color while the other colors stay the same.
84- backgroundColor: Theme .of (context).colorScheme.inversePrimary,
85- // Here we take the value from the MyHomePage object that was created by
86- // the App.build method, and use it to set our appbar title.
87- title: Text (widget.title),
94+ title: const Text ('FukEmail' ,
95+ style: TextStyle (
96+ color: Colors .black,
97+ fontWeight: FontWeight .w500,
98+ ),),
8899 ),
89- body: Center (
90- // Center is a layout widget. It takes a single child and positions it
91- // in the middle of the parent.
100+ body: SingleChildScrollView (
92101 child: Column (
93- // Column is also a layout widget. It takes a list of children and
94- // arranges them vertically. By default, it sizes itself to fit its
95- // children horizontally, and tries to be as tall as its parent.
96- //
97- // Column has various properties to control how it sizes itself and
98- // how it positions its children. Here we use mainAxisAlignment to
99- // center the children vertically; the main axis here is the vertical
100- // axis because Columns are vertical (the cross axis would be
101- // horizontal).
102- //
103- // TRY THIS: Invoke "debug painting" (choose the "Toggle Debug Paint"
104- // action in the IDE, or press "p" in the console), to see the
105- // wireframe for each widget.
106102 mainAxisAlignment: MainAxisAlignment .center,
107103 children: < Widget > [
108- const Text (
109- 'You have pushed the button this many times:' ,
104+ Padding (
105+ padding: const EdgeInsets .symmetric (horizontal: 0.0 ,vertical: 10 ),
106+ child: Column (
107+ children: [
108+ SizedBox (
109+ height: 200 ,
110+ child: Image .asset ("assets/mail.png" ),
111+ ),
112+ const Center (
113+ child: Text ("The temporary mail service allows you to obtain temporary or disposable emails for use as you wish." ,
114+ textAlign: TextAlign .center,
115+ softWrap: true ,
116+ style: TextStyle (
117+ color: Colors .black,
118+ fontSize: 12 ,
119+ fontWeight: FontWeight .w400,
120+ ),
121+ ),
122+ ),
123+ const SizedBox (
124+ height: 10 ,
125+ ),
126+ ],
127+ ),
128+ ),
129+
130+ Row (
131+ mainAxisAlignment: MainAxisAlignment .center,
132+ children: < Widget > [
133+ ElevatedButton (
134+ style: ButtonStyle (
135+ backgroundColor: MaterialStateProperty .all <Color >(Colors .purple),
136+ foregroundColor: MaterialStateProperty .all <Color >(Colors .white),
137+ ),
138+ onPressed: fetchData,
139+ child: const Text ('Generate Email' ),
140+ ),
141+ const SizedBox (width: 20 ),
142+ ElevatedButton (
143+ style: ButtonStyle (
144+ backgroundColor: MaterialStateProperty .all <Color >(Colors .green),
145+ foregroundColor: MaterialStateProperty .all <Color >(Colors .white),
146+ ),
147+ onPressed: updateMessage,
148+ child: const Text ('Refresh Message' ),
149+ ),
150+ ],
151+ ),
152+
153+ const SizedBox (height: 20 ),
154+ Container (
155+ width: MediaQuery .of (context).size.width * 0.95 ,
156+ decoration: BoxDecoration (
157+ color: Colors .white,
158+ borderRadius: BorderRadius .circular (10 ),
159+ boxShadow: [
160+ BoxShadow (
161+ color: Colors .grey.withOpacity (0.5 ),
162+ spreadRadius: 2 ,
163+ blurRadius: 3 ,
164+ ),
165+ ],
166+ ),
167+ padding: const EdgeInsets .all (10 ),
168+ child: Column (
169+ crossAxisAlignment: CrossAxisAlignment .start,
170+ children: [
171+ Row (
172+ mainAxisAlignment: MainAxisAlignment .spaceBetween,
173+ crossAxisAlignment: CrossAxisAlignment .center,
174+ children: [
175+ Text (
176+ 'Email: $email ' ,
177+ style: const TextStyle (fontSize: 13.5 ),
178+ ),
179+ IconButton (
180+ onPressed: () {
181+ Clipboard .setData (ClipboardData (text: email));
182+ final snackBar = SnackBar (
183+ content: const Text ('Copied' ),
184+ behavior: SnackBarBehavior .floating,
185+ shape : RoundedRectangleBorder (
186+ borderRadius: BorderRadius .circular (10 ),
187+ side: const BorderSide (color: Colors .purple, width: 2 ),
188+ ),
189+ );
190+ ScaffoldMessenger .of (context).showSnackBar (snackBar);
191+ },
192+ icon: const Icon (Icons .copy_all),
193+ color: Colors .purple,
194+
195+ ),
196+ ],
197+ ),
198+ ],
199+ ),
200+ ),
201+ const SizedBox (height: 20 ),
202+ Container (
203+ width: MediaQuery .of (context).size.width * 0.95 ,
204+ decoration: BoxDecoration (
205+ color: Colors .white,
206+ borderRadius: BorderRadius .circular (10 ),
207+ boxShadow: [
208+ BoxShadow (
209+ color: Colors .grey.withOpacity (0.5 ),
210+ spreadRadius: 2 ,
211+ blurRadius: 3 ,
212+ ),
213+ ],
214+ ),
215+ padding: const EdgeInsets .all (10 ),
216+ child: Column (
217+ mainAxisAlignment: MainAxisAlignment .start,
218+ crossAxisAlignment: CrossAxisAlignment .start,
219+ children: [
220+ const SizedBox (height: 10 ),
221+ Text (
222+ 'To : $toEmail ' ,
223+ ),
224+ const SizedBox (height: 10 ),
225+ Text (
226+ 'Message: $message ' ,
227+ ),
228+ const SizedBox (height: 10 ),
229+ Row (
230+ mainAxisAlignment: MainAxisAlignment .center,
231+ crossAxisAlignment: CrossAxisAlignment .center,
232+ children: [
233+ IconButton (
234+ onPressed: () {
235+ Clipboard .setData (ClipboardData (text: message));
236+ final snackBar = SnackBar (
237+ content: const Text ('Copied' ),
238+ behavior: SnackBarBehavior .floating,
239+ shape : RoundedRectangleBorder (
240+ borderRadius: BorderRadius .circular (10 ),
241+ side: const BorderSide (color: Colors .purple, width: 2 ),
242+ ),
243+ );
244+ ScaffoldMessenger .of (context).showSnackBar (snackBar);
245+ },
246+ icon: const Icon (Icons .copy_all),
247+ color: Colors .purple,
248+ ),
249+ ],
250+ ),
251+ ],
252+ ),
253+ ),
254+ const SizedBox (
255+ height: 50 ,
110256 ),
111- Text (
112- '$_counter ' ,
113- style: Theme .of (context).textTheme.headlineMedium,
257+ const Center (
258+ child: Text ("version 1.0.0" ,
259+ textAlign: TextAlign .center,
260+ style: TextStyle (
261+ color: Colors .white,
262+ fontSize: 12 ,
263+ fontWeight: FontWeight .w200,
264+ ),
265+ ),
266+ ),
267+ const SizedBox (
268+ height: 10 ,
114269 ),
115270 ],
116271 ),
117272 ),
118- floatingActionButton: FloatingActionButton (
119- onPressed: _incrementCounter,
120- tooltip: 'Increment' ,
121- child: const Icon (Icons .add),
122- ), // This trailing comma makes auto-formatting nicer for build methods.
273+ bottomNavigationBar: const Padding (
274+ padding: EdgeInsets .all (5.0 ),
275+ child: Text ('Developed By Vikramaditya' , textAlign: TextAlign .center,),
276+ ),
123277 );
124278 }
125- }
279+ }
0 commit comments