Created
December 2, 2019 07:43
-
-
Save inan-mahmud/fd30a23e2a1c201f72a8bb693bd5cb68 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
const kbottomContainerColor = Color(0xFFF05556); | |
const kBackgroundColor = Color(0xF5F5F5F5); | |
const FOODIE = "foodie"; | |
const VENDOR = "vendor"; | |
const String BASE_URL = "http://unitor.us/hubfoodpark/api/"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Events { | |
String id; | |
String uId; | |
String title; | |
String date; | |
String startTime; | |
String endTime; | |
String details; | |
String image; | |
Events( | |
{this.id, | |
this.uId, | |
this.title, | |
this.date, | |
this.startTime, | |
this.endTime, | |
this.details, | |
this.image}); | |
Events.fromJson(Map<String, dynamic> json) { | |
id = json['id']; | |
uId = json['u_id']; | |
title = json['title']; | |
date = json['date']; | |
startTime = json['start_time']; | |
endTime = json['end_time']; | |
details = json['details']; | |
image = json['image']; | |
} | |
Map<String, dynamic> toJson() { | |
final Map<String, dynamic> data = new Map<String, dynamic>(); | |
data['id'] = this.id; | |
data['u_id'] = this.uId; | |
data['title'] = this.title; | |
data['date'] = this.date; | |
data['start_time'] = this.startTime; | |
data['end_time'] = this.endTime; | |
data['details'] = this.details; | |
data['image'] = this.image; | |
return data; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'event_item.dart'; | |
class EventResult { | |
List<Events> events; | |
bool status; | |
String message; | |
EventResult({this.events}); | |
EventResult.fromJson(Map<String, dynamic> json) { | |
if (json['events'] != null) { | |
events = new List<Events>(); | |
json['events'].forEach((v) { | |
events.add(new Events.fromJson(v)); | |
}); | |
} | |
} | |
Map<String, dynamic> toJson() { | |
final Map<String, dynamic> data = new Map<String, dynamic>(); | |
if (this.events != null) { | |
data['events'] = this.events.map((v) => v.toJson()).toList(); | |
} | |
return data; | |
} | |
EventResult.fromEmptyJson(Map<String, dynamic> json) { | |
if (json['status'] != null) { | |
status = json['status']; | |
message = json['message']; | |
} | |
} | |
Map<String, dynamic> toEmptyJson() { | |
final Map<String, dynamic> data = new Map<String, dynamic>(); | |
data['status'] = this.status; | |
data['message'] = this.message; | |
return data; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:convert'; | |
import 'package:http/http.dart' as http; | |
import 'package:hub_food_park/pojos/event/event_result.dart'; | |
import 'package:hub_food_park/pojos/update/update_profile_response.dart'; | |
import 'package:hub_food_park/pojos/user/response.dart'; | |
import 'package:hub_food_park/utils/constants.dart'; | |
class NetworkHelper { | |
String url; | |
NetworkHelper(this.url); | |
void setUrl(String url) { | |
this.url = url; | |
} | |
Future<UserResponse> registerUser(Map body) async { | |
String mUrl = BASE_URL + this.url; | |
print(body.toString()); | |
try { | |
http.Response response = await http.post(mUrl, body: body); | |
print(response.statusCode); | |
Map data = jsonDecode(response.body); | |
return UserResponse.fromJson(data); | |
} catch (e) { | |
print(e); | |
} | |
return null; | |
} | |
Future<UserResponse> login(Map body) async { | |
String mUrl = BASE_URL + this.url; | |
try { | |
http.Response response = await http.post(mUrl, body: body); | |
print(response.statusCode); | |
Map data = jsonDecode(response.body); | |
return UserResponse.fromJson(data); | |
} catch (e) { | |
print(e); | |
} | |
return null; | |
} | |
Future<UpdateProfileResponse> updateProfile(Map body) async { | |
String mUrl = BASE_URL + this.url; | |
try { | |
http.Response response = await http.post(mUrl, body: body); | |
print(response.statusCode); | |
Map data = jsonDecode(response.body); | |
return UpdateProfileResponse.fromJson(data); | |
} catch (e) { | |
print(e); | |
} | |
return null; | |
} | |
Future<UpdateProfileResponse> updatePassword(Map body) async { | |
String mUrl = BASE_URL + this.url; | |
try { | |
http.Response response = await http.post(mUrl, body: body); | |
print(response.statusCode); | |
Map data = jsonDecode(response.body); | |
return UpdateProfileResponse.fromJson(data); | |
} catch (e) { | |
print(e); | |
} | |
return null; | |
} | |
Future<EventResult> getEventList(String date, int pageNo) async { | |
String mUrl = BASE_URL + this.url + '?date=$date&page=$pageNo'; | |
print(mUrl); | |
try { | |
http.Response response = await http.get(mUrl); | |
print(response.statusCode); | |
Map data = jsonDecode(response.body); | |
if (data.containsKey('status')) { | |
return EventResult.fromEmptyJson(data); | |
} else { | |
return EventResult.fromJson(data); | |
} | |
} catch (e) { | |
print(e); | |
} | |
return null; | |
} | |
Future<EventResult> getMonthlyEventList( | |
int month, int year, int pageNo) async { | |
String mUrl = BASE_URL + this.url + '?month=$month&year=$year&page=$pageNo'; | |
print(mUrl); | |
try { | |
http.Response response = await http.get(mUrl); | |
print(response.statusCode); | |
Map data = jsonDecode(response.body); | |
if (data.containsKey('status')) { | |
return EventResult.fromEmptyJson(data); | |
} else { | |
return EventResult.fromJson(data); | |
} | |
} catch (e) { | |
print(e); | |
} | |
return null; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment