· 5 years ago · Feb 05, 2021, 07:34 PM
1//Model
2class Shows {
3 final int id;
4 final String showTitle;
5 final String bannerImage;
6 final bool banner;
7
8 Shows({
9 this.id,
10 this.showTitle,
11 this.bannerImage,
12 this.banner,
13 });
14
15 factory Shows.fromJson(Map<String, dynamic> json) {
16 return Shows(
17 id: json['id'],
18 showTitle: json['ShowTitle'],
19 bannerImage: json['BannerImage'],
20 banner: json['Banner'],
21 );
22 }
23}
24
25
26
27//API Call
28import 'dart:convert';
29import 'package:anime_shows/models/shows.dart';
30import 'package:flutter/material.dart';
31import 'package:http/http.dart' as http;
32import 'package:anime_shows/constants/Api.dart';
33
34class ShowProvider with ChangeNotifier {
35 ShowProvider() {
36 this.fetchTask();
37 }
38
39 List<Shows> _shows = [];
40
41 List<Shows> get shows {
42 return [..._shows];
43 }
44
45 fetchTask() async {
46 final url = "http://10.0.2.2:8000/api/show";
47 final response = await http.get(
48 url,
49
50 // headers: {"Accept": "application/json"},
51 );
52 if (response.statusCode == 200) {
53 var data = json.decode(response.body) as List;
54 _shows = data.map<Shows>((json) => Shows.fromJson(json)).toList();
55 }
56 }
57}
58
59
60//main
61import 'package:anime_shows/ui/screens/HomeScreen.dart';
62import 'package:anime_shows/utils/serviecs/get_show.dart';
63import 'package:flutter/material.dart';
64import 'package:provider/provider.dart';
65
66void main() {
67 runApp(MyApp());
68}
69
70class MyApp extends StatelessWidget {
71 // This widget is the root of your application.
72 @override
73 Widget build(BuildContext context) {
74 return ChangeNotifierProvider(
75 create: (BuildContext context) => ShowProvider(),
76 child: MaterialApp(
77 title: 'Flutter Demo',
78 debugShowCheckedModeBanner: false,
79 theme: ThemeData(
80 primarySwatch: Colors.blue,
81 visualDensity: VisualDensity.adaptivePlatformDensity,
82 ),
83 home: HomeScreen(),
84 ),
85 );
86 }
87}
88
89
90//home
91import 'dart:ui';
92
93import 'package:anime_shows/ui/widgets/Banner.dart';
94import 'package:anime_shows/utils/properties/no_glow.dart';
95import 'package:anime_shows/utils/serviecs/get_show.dart';
96import 'package:carousel_slider/carousel_slider.dart';
97import 'package:flutter/material.dart';
98import 'package:provider/provider.dart';
99
100class HomeScreen extends StatelessWidget {
101 @override
102 Widget build(BuildContext context) {
103 final showp = Provider.of<ShowProvider>(context);
104 return SafeArea(
105 child: Scaffold(
106 backgroundColor: Color(0xff232020),
107 appBar: AppBar(
108 centerTitle: true,
109 backgroundColor: Colors.black,
110 title: Text('App Name'),
111 ),
112 body: Container(
113 child: ScrollConfiguration(
114 behavior: NoGlowBehavior(),
115 child: ListView(
116 scrollDirection: Axis.vertical,
117 shrinkWrap: true,
118 children: [
119 CarouselSlider.builder(
120 options: CarouselOptions(viewportFraction: .99, autoPlay: true),
121 // itemCount: showp.shows.length.compareTo(0),
122 itemCount: showp.shows.length,
123 itemBuilder: (BuildContext context, int index, int realIndex) {
124 return BannerWidget(
125 image: showp.shows[index].bannerImage,
126 title: showp.shows[index].showTitle,
127 );
128 },
129 )
130 ],
131 ),
132 ),
133 ),
134 ),
135 );
136 }
137}
138
139/*ListView.builder(
140 itemCount: newsP.news.length,
141 itemBuilder: (BuildContext context, int index) {
142 return ListTile(
143 title: Text((newsP.news[index].newsTitle).toString()),
144 subtitle: Text((newsP.news[index].newsShortDesc).toString()),
145 );
146 },
147 ) */
148
149/*CarouselSlider(
150 options: CarouselOptions(
151 viewportFraction: .99,
152 autoPlay: true,
153 ),
154 items: [
155 BannerWidget(),
156 ],
157 ), */
158
159
160//widget
161import 'package:flutter/cupertino.dart';
162import 'package:flutter/material.dart';
163
164class BannerWidget extends StatelessWidget {
165 const BannerWidget({
166 Key key,
167 String image,
168 String title,
169 // @required String image,
170 // @required String title,
171 }) : _image = image,
172 _title = title,
173 super(key: key);
174
175 final String _image;
176 final String _title;
177
178 @override
179 Widget build(BuildContext context) {
180 return Container(
181 width: double.infinity,
182 height: 200,
183 margin: EdgeInsets.symmetric(horizontal: 5, vertical: 3),
184 child: Stack(
185 children: [
186 Image.network(
187 // _image,
188 'https://i.ibb.co/zXVWKkk/V-Monster-Musume-no-Oishasan-full-3097933.png',
189 width: double.infinity,
190 fit: BoxFit.cover,
191 ),
192 Container(
193 alignment: Alignment.bottomLeft,
194 padding: EdgeInsets.all(15),
195 child: Text(
196 _title,
197 // 'Demo',
198 style: TextStyle(
199 fontSize: 22,
200 fontWeight: FontWeight.w900,
201 color: Colors.white,
202 ),
203 ),
204 )
205 ],
206 ),
207 );
208 }
209}
210
211
212//Raw Api Data
213[
214 {
215 "id": 1,
216 "ShowTitle": "One Punch Man",
217 "ShowImage": "https://i.ibb.co/zXVWKkk/V-Monster-Musume-no-Oishasan-full-3097933.png",
218 "BannerImage": "https://i.ibb.co/7X9Sw1V/533007.png",
219 "ShowTrailer": "https://www.youtube.com/watch?v=2JAElThbKrI",
220 "Banner": true,
221 "Popular": true,
222 "Complete": false,
223 "OnGoing": true,
224 "Audio": {
225 "language": "Hindi"
226 },
227 "Genre": [
228 {
229 "genres": "Action"
230 },
231 {
232 "genres": "Comedy"
233 },
234 {
235 "genres": "Crime"
236 }
237 ],
238 "SubTitle": {
239 "subTitle": "English"
240 },
241 "ShowDesc": "One Punch Man One Punch Man One Punch Man One Punch Man One Punch Man One Punch Man One Punch Man One Punch Man One Punch Man One Punch Man",
242 "season": [
243 {
244 "SeasonTitle": "Season 1",
245 "SeasonDesc": "One Punch Man One Punch Man",
246 "SeasonReleaseDate": "2021-02-03T15:35:23.212345Z",
247 "episode": [
248 {
249 "EpisodeTitle": "Episode-1",
250 "EpisodeDesc": "One Punch Man One Punch Man One Punch Man",
251 "EpisodeLink": "https://www.youtube.com/watch?v=awUKDn4qwko&list=PLwLSw1_eDZl3LmQOuDIveKBPJvUcapoq5&index=2",
252 "EpisodeReleaseDate": "2021-02-03T15:37:54.085367Z"
253 },
254 {
255 "EpisodeTitle": "Episode-2",
256 "EpisodeDesc": "One Punch Man One Punch Man",
257 "EpisodeLink": "https://www.youtube.com/watch?v=QMmoSstF9js&list=PLwLSw1_eDZl3LmQOuDIveKBPJvUcapoq5&index=1&t=16s",
258 "EpisodeReleaseDate": "2021-02-03T15:38:07.659723Z"
259 }
260 ]
261 },
262 {
263 "SeasonTitle": "Season 2",
264 "SeasonDesc": "One Punch Man One Punch Man",
265 "SeasonReleaseDate": "2021-02-03T15:35:31.170402Z",
266 "episode": [
267 {
268 "EpisodeTitle": "Episode-1",
269 "EpisodeDesc": "One Punch Man One Punch Man One Punch Man",
270 "EpisodeLink": "https://www.youtube.com/watch?v=QMmoSstF9js&list=PLwLSw1_eDZl3LmQOuDIveKBPJvUcapoq5&index=1&t=16s",
271 "EpisodeReleaseDate": "2021-02-03T15:38:17.460402Z"
272 }
273 ]
274 }
275 ]
276 },
277 {
278 "id": 2,
279 "ShowTitle": "Attack On Titne",
280 "ShowImage": "https://i.ibb.co/zXVWKkk/V-Monster-Musume-no-Oishasan-full-3097933.png",
281 "BannerImage": "https://i.ibb.co/7X9Sw1V/533007.png",
282 "ShowTrailer": "https://www.youtube.com/watch?v=2JAElThbKrI",
283 "Banner": true,
284 "Popular": false,
285 "Complete": false,
286 "OnGoing": true,
287 "Audio": {
288 "language": "English"
289 },
290 "Genre": [
291 {
292 "genres": "Action"
293 },
294 {
295 "genres": "Comedy"
296 },
297 {
298 "genres": "Slice of Life"
299 },
300 {
301 "genres": "Drama"
302 }
303 ],
304 "SubTitle": {
305 "subTitle": "Hindi"
306 },
307 "ShowDesc": "One Punch Man One Punch Man One Punch Man One Punch Man One Punch Man One Punch Man",
308 "season": [
309 {
310 "SeasonTitle": "Season 1",
311 "SeasonDesc": "Attack on Titan Attack on Titan",
312 "SeasonReleaseDate": "2021-02-03T15:35:50.874510Z",
313 "episode": [
314 {
315 "EpisodeTitle": "Episode-1",
316 "EpisodeDesc": "Attack on Titan Attack on Titan",
317 "EpisodeLink": "https://www.youtube.com/watch?v=QMmoSstF9js&list=PLwLSw1_eDZl3LmQOuDIveKBPJvUcapoq5&index=1&t=16s",
318 "EpisodeReleaseDate": "2021-02-03T15:36:16.907832Z"
319 },
320 {
321 "EpisodeTitle": "Episode-2",
322 "EpisodeDesc": "Attack on Titan Attack on Titan Attack on Titan",
323 "EpisodeLink": "https://www.youtube.com/watch?v=QMmoSstF9js&list=PLwLSw1_eDZl3LmQOuDIveKBPJvUcapoq5&index=1&t=16s",
324 "EpisodeReleaseDate": "2021-02-03T15:36:26.869164Z"
325 },
326 {
327 "EpisodeTitle": "Episode-3",
328 "EpisodeDesc": "Attack on Titan Attack on Titan Attack on Titan Attack on Titan",
329 "EpisodeLink": "https://www.youtube.com/watch?v=QMmoSstF9js&list=PLwLSw1_eDZl3LmQOuDIveKBPJvUcapoq5&index=1&t=16s",
330 "EpisodeReleaseDate": "2021-02-03T15:36:37.781293Z"
331 },
332 {
333 "EpisodeTitle": "Episode-4",
334 "EpisodeDesc": "Attack on Titan Attack on Titan Attack on Titan Attack on Titan",
335 "EpisodeLink": "https://www.youtube.com/watch?v=QMmoSstF9js&list=PLwLSw1_eDZl3LmQOuDIveKBPJvUcapoq5&index=1&t=16s",
336 "EpisodeReleaseDate": "2021-02-03T15:37:06.822465Z"
337 }
338 ]
339 }
340 ]
341 },
342 {
343 "id": 3,
344 "ShowTitle": "Death Note",
345 "ShowImage": "https://i.ibb.co/zXVWKkk/V-Monster-Musume-no-Oishasan-full-3097933.png",
346 "BannerImage": "https://i.ibb.co/gwR1dtS/H-monster-musume-no-oisha-san.jpg",
347 "ShowTrailer": "https://www.youtube.com/watch?v=2JAElThbKrI",
348 "Banner": false,
349 "Popular": true,
350 "Complete": true,
351 "OnGoing": false,
352 "Audio": {
353 "language": "Hindi"
354 },
355 "Genre": [
356 {
357 "genres": "Action"
358 },
359 {
360 "genres": "Supernatural"
361 }
362 ],
363 "SubTitle": {
364 "subTitle": "Hindi"
365 },
366 "ShowDesc": "Death Note Death Note Death Note Death Note Death Note Death Note",
367 "season": []
368 },
369 {
370 "id": 4,
371 "ShowTitle": "One Punch Man 2",
372 "ShowImage": "https://i.ibb.co/fxJcmQ6/Vertical.jpg",
373 "BannerImage": "https://i.ibb.co/7X9Sw1V/533007.png",
374 "ShowTrailer": "https://www.youtube.com/watch?v=2JAElThbKrI",
375 "Banner": true,
376 "Popular": false,
377 "Complete": false,
378 "OnGoing": true,
379 "Audio": {
380 "language": "English"
381 },
382 "Genre": [
383 {
384 "genres": "Action"
385 }
386 ],
387 "SubTitle": {
388 "subTitle": "English"
389 },
390 "ShowDesc": "One Punch Man 2",
391 "season": []
392 }
393]