-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adapting to both android and iOS testing.
- Loading branch information
1 parent
c8f43a9
commit 9b3e20e
Showing
2 changed files
with
85 additions
and
42 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,43 @@ | ||
import 'dart:convert'; | ||
import 'dart:io'; | ||
// import 'dart:convert'; | ||
// import 'dart:io'; | ||
|
||
import 'package:flutter/cupertino.dart'; | ||
import 'package:http/http.dart' as http; | ||
import 'package:pal_finder/data/event.dart'; | ||
// import 'package:flutter/cupertino.dart'; | ||
// import 'package:http/http.dart' as http; | ||
// import 'package:pal_finder/data/event.dart'; | ||
|
||
class EventFetcher { | ||
EventFetcher({ | ||
@required this.lat, | ||
@required this.lng, | ||
@required this.dist, | ||
}) | ||
: nextUrl='http://10.0.2.2:8000/apis/events/nearby/?lng=${lng.toStringAsFixed(6)}&lat=${lat.toStringAsFixed(6)}&dist=${dist.toStringAsFixed(3)}'; | ||
// class EventFetcher { | ||
// EventFetcher({ | ||
// @required this.lat, | ||
// @required this.lng, | ||
// @required this.dist, | ||
// }) | ||
// : nextUrl='http://10.0.2.2:8000/apis/events/nearby/?lng=${lng.toStringAsFixed(6)}&lat=${lat.toStringAsFixed(6)}&dist=${dist.toStringAsFixed(3)}'; | ||
|
||
final double lat; | ||
final double lng; | ||
final double dist; | ||
String nextUrl; | ||
// final double lat; | ||
// final double lng; | ||
// final double dist; | ||
// String nextUrl; | ||
|
||
Future<List<EventData>> fetchNextPage() async { | ||
final eventList = <EventData>[]; | ||
if (nextUrl != null) { | ||
final response = await http.get( | ||
nextUrl, | ||
headers: { | ||
HttpHeaders.authorizationHeader: 'Token b0998f43d3cb06e03f9dce4dd4e7816bc12eaa74' | ||
}, | ||
); | ||
if (response.statusCode == 200) { | ||
final data = jsonDecode(response.body) as Map<String, dynamic>; | ||
final list = data['results'] as List; | ||
list.forEach((eventMap) { | ||
eventList.add(EventData.fromMap(eventMap)); | ||
}); | ||
nextUrl = data['next']; | ||
} else { | ||
throw Exception('Fail to load events.'); | ||
} | ||
} | ||
return eventList; | ||
} | ||
} | ||
// Future<List<EventData>> fetchNextPage() async { | ||
// final eventList = <EventData>[]; | ||
// if (nextUrl != null) { | ||
// final response = await http.get( | ||
// nextUrl, | ||
// headers: { | ||
// HttpHeaders.authorizationHeader: 'Token b0998f43d3cb06e03f9dce4dd4e7816bc12eaa74' | ||
// }, | ||
// ); | ||
// if (response.statusCode == 200) { | ||
// final data = jsonDecode(response.body) as Map<String, dynamic>; | ||
// final list = data['results'] as List; | ||
// list.forEach((eventMap) { | ||
// eventList.add(EventData.fromMap(eventMap)); | ||
// }); | ||
// nextUrl = data['next']; | ||
// } else { | ||
// throw Exception('Fail to load events.'); | ||
// } | ||
// } | ||
// return eventList; | ||
// } | ||
// } |
This file contains 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