-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathspeaker_repository.dart
212 lines (204 loc) · 10.9 KB
/
speaker_repository.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
import 'dart:convert';
import 'dart:math';
import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;
import 'package:ecellapp/core/res/errors.dart';
import 'package:ecellapp/core/res/strings.dart';
import 'package:ecellapp/core/utils/injection.dart';
import 'package:ecellapp/core/utils/logger.dart';
import 'package:ecellapp/models/speaker.dart';
@immutable
abstract class SpeakerRepository {
/// All subfunctions are final No arguments required returns json
Future<List<Speaker>> getAllSpeakers();
}
class FakeSpeakerRepository extends SpeakerRepository {
@override
Future<List<Speaker>> getAllSpeakers() async {
//Network delay here
await Future.delayed(Duration(seconds: 1));
//Fake Response and Network Delay
if (false) {
throw NetworkException();
} else {
var response = {
"data": [
{
"company": "The Logical Indian",
"contact": "",
"created_at": "2021-01-13T11:33:00.689210Z",
"description":
"The most difficult part of being a journalist is printing something which someone else doesn't want to be printed. In this day where all the media houses run for TRP, Shwetha Kothari is one of those few journalists who stand for nothing else but the absolute truth. Currently the Managing Editor at The Logical Indian, she's extremely vocal on her views on various issues like unsettled public issues, feminism, exploiting India's entrepreneurial potential. With tons of experience on her shoulder, her session can help you find the right direction in life.",
"email": "[email protected]",
"experience": 2,
"flag": true,
"id": 16,
"modified_at": "2021-01-13T11:43:16.131751Z",
"name": "Shweta Kothari",
"profile_pic":
"https://ichef.bbci.co.uk/news/976/cpsprodpb/7727/production/_103330503_musk3.jpg",
"social_media":
"https://www.linkedin.com/in/shweta-kothari-b57a8453",
"year": 2019
},
{
"company": "The Logical Indian",
"contact": "",
"created_at": "2021-01-13T11:33:00.689210Z",
"description":
"The most difficult part of being a journalist is printing something which someone else doesn't want to be printed. In this day where all the media houses run for TRP, Shwetha Kothari is one of those few journalists who stand for nothing else but the absolute truth. Currently the Managing Editor at The Logical Indian, she's extremely vocal on her views on various issues like unsettled public issues, feminism, exploiting India's entrepreneurial potential. With tons of experience on her shoulder, her session can help you find the right direction in life.",
"email": "[email protected]",
"experience": 2,
"flag": true,
"id": 16,
"modified_at": "2021-01-13T11:43:16.131751Z",
"name": "Shweta Kothari",
"profile_pic":
"https://ichef.bbci.co.uk/news/976/cpsprodpb/7727/production/_103330503_musk3.jpg",
"social_media":
"https://www.linkedin.com/in/shweta-kothari-b57a8453",
"year": 2019
},
{
"company": "The Logical Indian",
"contact": "",
"created_at": "2021-01-13T11:33:00.689210Z",
"description":
"The most difficult part of being a journalist is printing something which someone else doesn't want to be printed. In this day where all the media houses run for TRP, Shwetha Kothari is one of those few journalists who stand for nothing else but the absolute truth. Currently the Managing Editor at The Logical Indian, she's extremely vocal on her views on various issues like unsettled public issues, feminism, exploiting India's entrepreneurial potential. With tons of experience on her shoulder, her session can help you find the right direction in life.",
"email": "[email protected]",
"experience": 2,
"flag": true,
"id": 16,
"modified_at": "2021-01-13T11:43:16.131751Z",
"name": "Shweta Kothari",
"profile_pic":
"https://ichef.bbci.co.uk/news/976/cpsprodpb/7727/production/_103330503_musk3.jpg",
"social_media":
"https://www.linkedin.com/in/shweta-kothari-b57a8453",
"year": 2019
},
{
"company": "The Logical Indian",
"contact": "",
"created_at": "2021-01-13T11:33:00.689210Z",
"description":
"The most difficult part of being a journalist is printing something which someone else doesn't want to be printed. In this day where all the media houses run for TRP, Shwetha Kothari is one of those few journalists who stand for nothing else but the absolute truth. Currently the Managing Editor at The Logical Indian, she's extremely vocal on her views on various issues like unsettled public issues, feminism, exploiting India's entrepreneurial potential. With tons of experience on her shoulder, her session can help you find the right direction in life.",
"email": "[email protected]",
"experience": 2,
"flag": true,
"id": 16,
"modified_at": "2021-01-13T11:43:16.131751Z",
"name": "Shweta Kothari",
"profile_pic":
"https://ichef.bbci.co.uk/news/976/cpsprodpb/7727/production/_103330503_musk3.jpg",
"social_media":
"https://www.linkedin.com/in/shweta-kothari-b57a8453",
"year": 2019
},
{
"company": "The Logical Indian",
"contact": "",
"created_at": "2021-01-13T11:33:00.689210Z",
"description":
"The most difficult part of being a journalist is printing something which someone else doesn't want to be printed. In this day where all the media houses run for TRP, Shwetha Kothari is one of those few journalists who stand for nothing else but the absolute truth. Currently the Managing Editor at The Logical Indian, she's extremely vocal on her views on various issues like unsettled public issues, feminism, exploiting India's entrepreneurial potential. With tons of experience on her shoulder, her session can help you find the right direction in life.",
"email": "[email protected]",
"experience": 2,
"flag": true,
"id": 16,
"modified_at": "2021-01-13T11:43:16.131751Z",
"name": "Shweta Kothari",
"profile_pic":
"https://ichef.bbci.co.uk/news/976/cpsprodpb/7727/production/_103330503_musk3.jpg",
"social_media":
"https://www.linkedin.com/in/shweta-kothari-b57a8453",
"year": 2019
},
{
"company": "msdnms",
"contact": "",
"created_at": "2021-01-13T11:33:00.689210Z",
"description": "none",
"email": "[email protected]",
"experience": 2,
"flag": true,
"id": 1,
"modified_at": "2021-01-13T11:43:16.131751Z",
"name": "absan",
"profile_pic":
"https://ichef.bbci.co.uk/news/976/cpsprodpb/7727/production/_103330503_musk3.jpg",
"social_media": "blank",
"year": 2019
},
{
"company": "The Logical Indian",
"contact": "",
"created_at": "2021-01-13T11:33:00.689210Z",
"description":
"The most difficult part of being a journalist is printing something which someone else doesn't want to be printed. In this day where all the media houses run for TRP, Shwetha Kothari is one of those few journalists who stand for nothing else but the absolute truth. Currently the Managing Editor at The Logical Indian, she's extremely vocal on her views on various issues like unsettled public issues, feminism, exploiting India's entrepreneurial potential. With tons of experience on her shoulder, her session can help you find the right direction in life.",
"email": "[email protected]",
"experience": 2,
"flag": true,
"id": 16,
"modified_at": "2021-01-13T11:43:16.131751Z",
"name": "Shweta Kothari",
"profile_pic":
"https://ichef.bbci.co.uk/news/976/cpsprodpb/7727/production/_103330503_musk3.jpg",
"social_media":
"https://www.linkedin.com/in/shweta-kothari-b57a8453",
"year": 2019
},
{
"company": "The Logical Indian",
"contact": "",
"created_at": "2021-01-13T11:33:00.689210Z",
"description":
"The most difficult part of being a journalist is printing something which someone else doesn't want to be printed. In this day where all the media houses run for TRP, Shwetha Kothari is one of those few journalists who stand for nothing else but the absolute truth. Currently the Managing Editor at The Logical Indian, she's extremely vocal on her views on various issues like unsettled public issues, feminism, exploiting India's entrepreneurial potential. With tons of experience on her shoulder, her session can help you find the right direction in life.",
"email": "[email protected]",
"experience": 2,
"flag": true,
"id": 16,
"modified_at": "2021-01-13T11:43:16.131751Z",
"name": "Shweta Kothari",
"profile_pic":
"https://ichef.bbci.co.uk/news/976/cpsprodpb/7727/production/_103330503_musk3.jpg",
"social_media":
"https://www.linkedin.com/in/shweta-kothari-b57a8453",
"year": 2019
}
],
"message": "Speakers Fetched Successfully"
};
return (response["data"] as List)
.map((e) => Speaker.fromJson(e))
.toList();
}
}
}
class APISpeakerRepository extends SpeakerRepository {
final String classTag = "APIgetSpeakerRepository";
@override
Future<List<Speaker>> getAllSpeakers() async {
final String tag = classTag + "getAllSpeakers()";
http.Response response;
try {
response = await sl.get<http.Client>().get(Uri.parse(S.getSpeakerUrl));
} catch (e) {
throw NetworkException();
}
if (response.statusCode == 200) {
var speakerResponse = jsonDecode(response.body);
return (speakerResponse["data"] as List)
.map((e) => Speaker.fromJson(e))
.toList();
} else if (response.statusCode == 404) {
throw ValidationException(response.body);
} else {
Log.s(
tag: tag,
message:
"Unknown response code -> ${response.statusCode}, message ->" +
response.body);
throw UnknownException();
}
}
}