Skip to content

Commit 3744be7

Browse files
authored
Merge branch 'dev' into feat/edit-profile-screen
2 parents 7893866 + 2f3ddb4 commit 3744be7

33 files changed

+1103
-17
lines changed

.githooks/pre-push

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,9 @@ if [ $? -ne 0 ]; then
1010
printf "\e[31;1m%s\e[0m\n" 'Flutter analyzer error'
1111
exit 1
1212
fi
13+
flutter test
14+
if [ $? -ne 0 ]; then
15+
printf "\e[31;1m%s\e[0m\n" 'Flutter test error'
16+
exit 1
17+
fi
1318
printf "\e[33;1m%s\e[0m\n" 'Finished running the Flutter analyzer'

lib/core/app/application.dart

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,32 @@
1+
import 'package:streamskit_mobile/core/app/config/base_local_data.dart';
2+
import 'package:streamskit_mobile/core/injection/injection_container.dart'
3+
as di;
4+
import 'package:flutter/material.dart';
5+
import 'package:streamskit_mobile/core/util/path_helper.dart';
16

7+
class Application {
8+
/// [Production - Dev]
9+
static Future<void> initialAppLication() async {
10+
try {
11+
// Prepare path cache
12+
await PathHelper.createDirStreamOS();
13+
14+
// Init Hive
15+
await BaseLocalData.initialBox();
16+
17+
// Init dependency injection
18+
await di.init();
19+
} catch (error) {
20+
debugPrint(error.toString());
21+
}
22+
}
23+
24+
///Singleton factory
25+
static final Application _instance = Application._internal();
26+
27+
factory Application() {
28+
return _instance;
29+
}
30+
31+
Application._internal();
32+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import 'package:hive/hive.dart';
2+
import 'package:streamskit_mobile/core/app/constant/storage_keys.dart';
3+
import 'package:streamskit_mobile/core/util/path_helper.dart';
4+
5+
class BaseLocalData {
6+
static Future<void> initialBox() async {
7+
String path = await PathHelper.localStoreDirStreamOS;
8+
Hive.init(path);
9+
await Hive.openBox(StorageKeys.boxSystem);
10+
}
11+
12+
static Future<void> openBoxApp() async {
13+
await Hive.openBox(StorageKeys.boxUser);
14+
await Hive.openBox(StorageKeys.boxLiveStreams);
15+
}
16+
}
Lines changed: 282 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,282 @@
1+
import 'dart:async';
2+
import 'dart:convert' as convert;
3+
import 'package:dio/dio.dart' as diox;
4+
import 'package:flutter/foundation.dart';
5+
import 'package:streamskit_mobile/core/app/constant/constants.dart';
6+
import 'package:streamskit_mobile/core/types/http_status_code.dart';
7+
import 'package:streamskit_mobile/core/types/service_method.dart';
8+
import 'package:streamskit_mobile/core/util/logger.dart';
9+
import 'package:streamskit_mobile/core/util/stop_watch_api.dart';
10+
11+
class BaseRemoteData {
12+
var dio = diox.Dio(diox.BaseOptions(
13+
baseUrl: serviceBaseEndpoint,
14+
connectTimeout: connectTimeOut,
15+
receiveTimeout: receiveTimeOut,
16+
sendTimeout: receiveTimeOut,
17+
)); // with default Options
18+
19+
Future<diox.Response<dynamic>> downloadFile(
20+
String url, String path, Function onReceive) async {
21+
var response = await dio.download(
22+
url,
23+
path,
24+
options: getOptions(),
25+
onReceiveProgress: (received, total) {
26+
onReceive(received, total);
27+
},
28+
);
29+
return response;
30+
}
31+
32+
Future<diox.Response<dynamic>> postFormData(
33+
String gateway,
34+
diox.FormData formData,
35+
) async {
36+
try {
37+
var response = await dio.post(
38+
gateway,
39+
data: formData,
40+
options: getOptions(),
41+
onSendProgress: (send, total) {},
42+
onReceiveProgress: (received, total) {},
43+
);
44+
45+
return response;
46+
} on diox.DioError catch (exception) {
47+
return catchDioError(exception: exception, gateway: gateway);
48+
}
49+
}
50+
51+
Future<diox.Response<dynamic>> putFormData(
52+
String gateway,
53+
diox.FormData formData,
54+
) async {
55+
try {
56+
var response = await dio.put(
57+
gateway,
58+
data: formData,
59+
options: getOptions(),
60+
onSendProgress: (send, total) {},
61+
onReceiveProgress: (received, total) {},
62+
);
63+
return response;
64+
} on diox.DioError catch (exception) {
65+
return catchDioError(exception: exception, gateway: gateway);
66+
}
67+
}
68+
69+
Future<diox.Response<dynamic>> postRoute(
70+
String gateway, Map<String, dynamic> body,
71+
{String? query}) async {
72+
try {
73+
Map<String, String> paramsObject = {};
74+
if (query != null) {
75+
query.split('&').forEach((element) {
76+
paramsObject[element.split('=')[0].toString()] =
77+
element.split('=')[1].toString();
78+
});
79+
}
80+
var response = kDebugMode
81+
? await StopWatch.stopWatchApi(
82+
() => dio.post(
83+
gateway,
84+
data: convert.jsonEncode(body),
85+
options: getOptions(),
86+
queryParameters: query == null ? null : paramsObject,
87+
),
88+
ServiceMethod.post.methodName,
89+
gateway)
90+
: await dio.post(
91+
gateway,
92+
data: convert.jsonEncode(body),
93+
options: getOptions(),
94+
queryParameters: query == null ? null : paramsObject,
95+
);
96+
return response;
97+
} on diox.DioError catch (exception) {
98+
return catchDioError(exception: exception, gateway: gateway);
99+
}
100+
}
101+
102+
Future<diox.Response<dynamic>> putRoute(
103+
String gateway,
104+
Map<String, dynamic> body,
105+
) async {
106+
try {
107+
var response = kDebugMode
108+
? await StopWatch.stopWatchApi(
109+
() => dio.put(
110+
gateway,
111+
data: convert.jsonEncode(body),
112+
options: getOptions(),
113+
),
114+
ServiceMethod.put.methodName,
115+
gateway)
116+
: await dio.put(
117+
gateway,
118+
data: convert.jsonEncode(body),
119+
options: getOptions(),
120+
);
121+
return response;
122+
} on diox.DioError catch (exception) {
123+
return catchDioError(exception: exception, gateway: gateway);
124+
}
125+
}
126+
127+
Future<diox.Response<dynamic>> patchRoute(
128+
String gateway, {
129+
String? query,
130+
Map<String, dynamic>? body,
131+
}) async {
132+
try {
133+
Map<String, String> paramsObject = {};
134+
if (query != null) {
135+
query.split('&').forEach((element) {
136+
paramsObject[element.split('=')[0].toString()] =
137+
element.split('=')[1].toString();
138+
});
139+
}
140+
141+
var response = kDebugMode
142+
? await StopWatch.stopWatchApi(
143+
() => dio.patch(
144+
gateway,
145+
data: body == null ? null : convert.jsonEncode(body),
146+
options: getOptions(),
147+
queryParameters: query == null ? null : paramsObject,
148+
),
149+
ServiceMethod.patch.methodName,
150+
gateway)
151+
: await dio.patch(
152+
gateway,
153+
data: body == null ? null : convert.jsonEncode(body),
154+
options: getOptions(),
155+
queryParameters: query == null ? null : paramsObject,
156+
);
157+
return response;
158+
} on diox.DioError catch (exception) {
159+
return catchDioError(exception: exception, gateway: gateway);
160+
}
161+
}
162+
163+
Future<diox.Response<dynamic>> getRoute(
164+
String gateway, {
165+
String? params,
166+
String? query,
167+
}) async {
168+
try {
169+
Map<String, String> paramsObject = {};
170+
if (query != null) {
171+
query.split('&').forEach((element) {
172+
paramsObject[element.split('=')[0].toString()] =
173+
element.split('=')[1].toString();
174+
});
175+
}
176+
177+
var response = kDebugMode
178+
? await StopWatch.stopWatchApi(
179+
() => dio.get(
180+
gateway,
181+
options: getOptions(),
182+
queryParameters: query == null ? null : paramsObject,
183+
),
184+
ServiceMethod.get.methodName,
185+
gateway)
186+
: await dio.get(
187+
gateway,
188+
options: getOptions(),
189+
queryParameters: query == null ? null : paramsObject,
190+
);
191+
return response;
192+
} on diox.DioError catch (exception) {
193+
return catchDioError(exception: exception, gateway: gateway);
194+
}
195+
}
196+
197+
Future<diox.Response<dynamic>> deleteRoute(
198+
String gateway, {
199+
String? params,
200+
String? query,
201+
Map<String, dynamic>? body,
202+
diox.FormData? formData,
203+
}) async {
204+
try {
205+
Map<String, String> paramsObject = {};
206+
if (query != null) {
207+
query.split('&').forEach((element) {
208+
paramsObject[element.split('=')[0].toString()] =
209+
element.split('=')[1].toString();
210+
});
211+
}
212+
213+
var response = kDebugMode
214+
? await StopWatch.stopWatchApi(
215+
() => dio.delete(
216+
gateway,
217+
data: formData ??
218+
(body == null ? null : convert.jsonEncode(body)),
219+
options: getOptions(),
220+
queryParameters: query == null ? null : paramsObject,
221+
),
222+
ServiceMethod.delete.methodName,
223+
gateway)
224+
: await dio.delete(
225+
gateway,
226+
data:
227+
formData ?? (body == null ? null : convert.jsonEncode(body)),
228+
options: getOptions(),
229+
queryParameters: query == null ? null : paramsObject,
230+
);
231+
return response;
232+
} on diox.DioError catch (exception) {
233+
return catchDioError(exception: exception, gateway: gateway);
234+
}
235+
}
236+
237+
diox.Response catchDioError({
238+
required diox.DioError exception,
239+
required String gateway,
240+
}) {
241+
return diox.Response(
242+
requestOptions: diox.RequestOptions(path: gateway),
243+
data: null,
244+
statusCode: StatusCode.badGateway,
245+
statusMessage: "CATCH EXCEPTION DIO",
246+
);
247+
}
248+
249+
diox.Options getOptions() {
250+
return diox.Options(
251+
validateStatus: (status) {
252+
// if (status == StatusCode.unauthorized &&
253+
// UserLocal().getAccessToken().isNotEmpty) {
254+
// UserLocal().clearAccessToken();
255+
// showDialogLoading();
256+
// AppBloc.authBloc.add(LogOutEvent());
257+
// }
258+
return true;
259+
},
260+
headers: getHeaders(),
261+
);
262+
}
263+
264+
getHeaders() {
265+
return {
266+
'Authorization': 'Bearer ',
267+
'Content-Type': 'application/json; charset=UTF-8',
268+
'Connection': 'keep-alive',
269+
'Accept': '*/*',
270+
'Accept-Encoding': 'gzip, deflate, br',
271+
};
272+
}
273+
274+
printEndpoint(String method, String endpoint) {
275+
UtilLogger.log('${method.toUpperCase()}: $endpoint');
276+
}
277+
278+
printResponse(diox.Response<dynamic> response) {
279+
UtilLogger.log('StatusCode: ${response.statusCode}');
280+
UtilLogger.log('Body: ${response.data.toString()}');
281+
}
282+
}

lib/core/app/constant/constants.dart

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Remote Data
2+
const String serviceBaseEndpoint = 'https://lambiengcode.tk';
3+
4+
// Utils
5+
const double inchToDP = 160;
6+
7+
// Delay times - miliseconds
8+
const int delay200ms = 200;
9+
const int delay500ms = 500;
10+
const int delayASecond = 1000;
11+
const int connectTimeOut = 5000;
12+
const int receiveTimeOut = 5000;
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
class StorageKeys {
2+
// Box Variables
3+
static const String boxSystem = 'boxSystem';
4+
static const String boxUser = 'boxUser';
5+
static const String boxLiveStreams = 'boxLiveStreams';
6+
7+
// Key in Box - Live Streams
8+
static const String liveStreamsKey = 'liveStreamsKey';
9+
}

lib/core/app/constants.dart

Lines changed: 0 additions & 6 deletions
This file was deleted.

lib/core/error/failure.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import 'package:equatable/equatable.dart';
2+
3+
abstract class Failure extends Equatable {
4+
@override
5+
List<Object> get props => [];
6+
}
7+
8+
// General failures
9+
class CannotFoundItem extends Failure {}

0 commit comments

Comments
 (0)