Fakultas Ilmu Komputer UI

Commit b3d3c5f7 authored by Fakhira Devina's avatar Fakhira Devina
Browse files

Merge remote-tracking branch 'origin/PBI-2-pencarian_lokasi' into PBI-2-pencarian_lokasi

parents e1518b78 ec543061
Pipeline #37260 passed with stages
in 5 minutes and 15 seconds
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"google_maps_flutter","path":"D:\\\\Flutter\\\\flutter_windows_v1.9.1+hotfix.2-stable\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\google_maps_flutter-0.5.24+1\\\\","dependencies":[]},{"name":"location","path":"D:\\\\Flutter\\\\flutter_windows_v1.9.1+hotfix.2-stable\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\location-2.5.3\\\\","dependencies":[]},{"name":"path_provider","path":"D:\\\\Flutter\\\\flutter_windows_v1.9.1+hotfix.2-stable\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\path_provider-0.4.1\\\\","dependencies":[]}],"android":[{"name":"flutter_plugin_android_lifecycle","path":"D:\\\\Flutter\\\\flutter_windows_v1.9.1+hotfix.2-stable\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\flutter_plugin_android_lifecycle-1.0.6\\\\","dependencies":[]},{"name":"google_maps_flutter","path":"D:\\\\Flutter\\\\flutter_windows_v1.9.1+hotfix.2-stable\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\google_maps_flutter-0.5.24+1\\\\","dependencies":["flutter_plugin_android_lifecycle"]},{"name":"location","path":"D:\\\\Flutter\\\\flutter_windows_v1.9.1+hotfix.2-stable\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\location-2.5.3\\\\","dependencies":[]},{"name":"path_provider","path":"D:\\\\Flutter\\\\flutter_windows_v1.9.1+hotfix.2-stable\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\path_provider-0.4.1\\\\","dependencies":[]}],"macos":[],"linux":[],"windows":[],"web":[]},"dependencyGraph":[{"name":"flutter_plugin_android_lifecycle","dependencies":[]},{"name":"google_maps_flutter","dependencies":["flutter_plugin_android_lifecycle"]},{"name":"location","dependencies":[]},{"name":"path_provider","dependencies":[]}],"date_created":"2020-03-25 13:27:40.693904","version":"1.15.17"}
\ No newline at end of file
{"_info":"// This is a generated file; do not edit or check into version control.","dependencyGraph":[{"name":"flutter_plugin_android_lifecycle","dependencies":[]},{"name":"google_maps_flutter","dependencies":["flutter_plugin_android_lifecycle"]},{"name":"location","dependencies":[]},{"name":"path_provider","dependencies":["path_provider_macos"]},{"name":"path_provider_macos","dependencies":[]}]}
\ No newline at end of file
......@@ -5,12 +5,12 @@ final String devBaseURL = "poipole.herokuapp.com";
final String baseURL = "poipole.herokuapp.com";
String key = "";
String csrf = "";
String sessionID = "";
String sessionId = "";
setKey(String key) {
key = key;
setKey(String newKey) {
key = newKey;
}
setSessionId(String sessionId) {
sessionID = sessionId;
setSessionId(String newSessionId) {
sessionId = newSessionId;
}
\ No newline at end of file
import 'dart:convert';
import 'dart:io';
import 'package:path_provider/path_provider.dart';
import 'package:ppl_disabilitas/config/strings.dart';
class CookiesInterface {
Future<bool> checkCookieFileAvailability({String fileName}) async {
Directory dir;
await getApplicationDocumentsDirectory().then((Directory directory) {
dir = directory;
});
File cookieFile = File("${dir.path}/$fileName");
bool cookiesExist = cookieFile.existsSync();
return cookiesExist;
}
Future<File> createSignInCookie({
Map<String, dynamic> responseHeaders}) async {
try {
String setCookie;
String csrfToken;
String sessionId;
String userKey;
List<String> cookiesList;
Directory dir;
await getApplicationDocumentsDirectory().then((Directory directory) {
dir = directory;
});
File cookieFile = new File("${dir.path}/usercookies.json");
cookieFile.createSync();
setCookie = responseHeaders["set-cookie"];
if (setCookie != null) {
csrfToken = setCookie.split(";")[0].split("=")[1];
sessionId = setCookie.split(";")[4].split(",")[1].split("=")[1];
userKey = key;
}
cookiesList = <String>[
csrfToken,
sessionId,
userKey,
];
cookieFile.writeAsStringSync(json.encode(cookiesList));
return cookieFile;
} on Exception catch (e) {
print(e.toString());
throw e;
}
}
Future<File> createSearchHistoryCookie({
Map<String, dynamic> recentSearch}) async {
Directory dir;
try {
await getApplicationDocumentsDirectory().then((Directory directory) {
dir = directory;
});
File cookieFile = new File(dir.path + "/searchhistory.json");
cookieFile.createSync();
List currentSearchHistory = await getCookieFile(fileName: "searchhistory.json");
if (currentSearchHistory.length == 0) {
currentSearchHistory = [];
}
currentSearchHistory.add(recentSearch);
cookieFile.writeAsString(json.encode(currentSearchHistory));
return cookieFile;
} on Exception catch (e) {
print(e.toString());
throw e;
}
}
Future<List<dynamic>> getCookieFile({String fileName}) async {
Directory dir;
await getApplicationDocumentsDirectory().then((Directory directory) {
dir = directory;
});
File file = File("${dir.path}/fileName");
dynamic res = file.readAsStringSync();
return json.decode(res);
}
}
class NetworkModel {
var response;
int statusCode;
String errorMessage;
NetworkModel({
this.response,
this.statusCode,
this.errorMessage,
});
}
\ No newline at end of file
import 'dart:convert';
import 'package:ppl_disabilitas/network/data/network_model.dart';
import 'package:http/http.dart' as http;
class NetworkInterface {
//String key = KEY;
// POST request
Future<NetworkModel> post({
String url, //url nya apa
dynamic bodyParams, //data apa yang mau dikasih
bool isLogin, //dia login apa ngga
}) async {
Map<String, String> headersJson = await _buildRequestHeader(isLogin); //butuh header apa ngga
NetworkModel model;
try {
model = await http.post(
"$url",
body: json.encode(bodyParams),
headers: headersJson,
).then((response) async {
Map<String, dynamic> responseBody = json.decode(response.body);
print(responseBody.toString());
//if (!isLogin) {
//if (responseBody.containsKey("key")) {
//setKey(responseBody["key"]);
//}
//await CookiesInterface.createCookieFile(response.headers);
//}
print(responseBody);
return NetworkModel(statusCode: response.statusCode,
response: responseBody,
);
});
if (model.statusCode >= 400) {
throw Exception();
}
} on Exception catch (e) {
print("status code --> ${model.statusCode}");
NetworkModel errorModel = NetworkModel(
statusCode: model.statusCode,
errorMessage: e.toString(),
response: model.response);
model = errorModel;
}
return model;
}
// GET request
Future<NetworkModel> get({
String url,
bool isLogin,
}) async {
Map<String, dynamic> headersJson = await _buildRequestHeader(isLogin);
NetworkModel model;
try {
model = await http
.get(
"$url",
headers: headersJson,
)
.then((response) {
print("masuk sini");
dynamic responseBody = json.decode(response.body);
print(responseBody);
return NetworkModel(
statusCode: response.statusCode,
response: responseBody,
);
});
if (model.statusCode >= 400) {
print("gamasuk sini");
throw Exception();
}
} on Exception catch (e) {
NetworkModel errorModel = NetworkModel(
statusCode: model.statusCode,
errorMessage: e.toString(),
response: model.response);
model = errorModel;
}
return model;
}
// buildRequestHeader: untuk nentuin pake header apa aja berdasarkan login apa ngga
Future<Map<String, dynamic>> _buildRequestHeader(bool isLogin) async {
Map<String, String> headers = Map<String, String>();
headers.putIfAbsent("Content-Type", () => "application/json");
//if (isLogin) {
//List<dynamic> cookieFile = await CookiesInterface.getCookieFile(); //ngambil data dari yg udh disimpen di cookie
//print("cookieFile list --> ${cookieFile.toString()}");
//print("check key here >>> $key");
//setKey(cookieFile[2]);
//key = cookieFile[2];
//headers.putIfAbsent("Authorization", () => 'Token $key'); //ini kalau authorization nya ngga ada baru taro token nya
//headers.putIfAbsent("X-CSRFToken", () => cookieFile[0]); //csrf token
//headers.putIfAbsent("Cookie",
//() => "csrftoken=${cookieFile[0]};sessionid=${cookieFile[1]}"); //cookie file
//print("headers --> ${headers}");
//}
return headers;
}
}
\ No newline at end of file
import 'package:flutter/material.dart';
import 'package:ppl_disabilitas/config/styles.dart';
import 'package:ppl_disabilitas/network/data/network_model.dart';
import 'package:ppl_disabilitas/network/network_interface.dart';
class Pencarian extends StatefulWidget {
@override
......@@ -9,6 +11,15 @@ class Pencarian extends StatefulWidget {
class PencarianState extends State<Pencarian> {
Icon searchIcon = Icon(Icons.search);
Widget appBarText = Text("Pencarian Lokasi");
NetworkInterface networkInterface = NetworkInterface();
Future<NetworkModel> data;
@override
void initState() {
data = networkInterface.get(
url: 'https://my.api.mockaroo.com/mall.json?key=dbcde960');
super.initState();
print("aku");
}
@override
Widget build(BuildContext context) {
......@@ -53,118 +64,191 @@ class PencarianState extends State<Pencarian> {
),
),
),
body: ListView(
padding: const EdgeInsets.all(8),
children: <Widget>[
Padding(
padding: EdgeInsets.only(left: doubleSpace, top: 10),
child: Text(
'Hasil Pencarian',
style: TextStyle(
fontSize: 15,
color: Colors.black,
fontFamily: 'Muli',
),
),
),
Container(
height: 90,
color: Colors.transparent,
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
CircleAvatar(
backgroundColor: greenPrimary,
child: Text('Test'),
),
Padding(
padding: EdgeInsets.all(doubleSpace),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'Margo City',
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.w800,
color: Colors.black,
fontFamily: 'Muli',
body: FutureBuilder<NetworkModel>(
future: data,
builder: (context, snapshot) {
if (snapshot.hasData) {
print("snapshot data");
List places = snapshot.data.response;
return ListView.builder(
itemCount: places.length,
itemBuilder: (context, index) {
return Container(
decoration: BoxDecoration(
color: Colors.transparent,
border: Border(
bottom: BorderSide(color: Colors.grey[400]))),
margin:
EdgeInsets.only(left: doubleSpace, right: doubleSpace),
height: 90,
child: Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Row(
children: <Widget>[
CircleAvatar(
backgroundColor: greenPrimary,
child: Text('Test'),
),
Container(
padding: EdgeInsets.all(doubleSpace),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
places[index]['nama'],
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.w800,
color: Colors.black,
fontFamily: 'Muli',
),
),
Text(
places[index]['alamat'],
style: TextStyle(
fontSize: 15,
color: Colors.black,
fontFamily: 'Muli',
),
),
],
),
),
],
),
),
Text(
'Jl. Margonda Raya No.358, Kemir...',
style: TextStyle(
fontSize: 15,
color: Colors.black,
fontFamily: 'Muli',
),
),
],
Icon(
Icons.arrow_forward_ios,
color: Colors.grey[400],
size: 20,
)
],
),
);
});
} else if (snapshot.hasError) {
return Text("${snapshot.error}");
}
// By default, show a loading spinner.
return CircularProgressIndicator();
},
),
);
}
ListView temp = ListView(
padding: const EdgeInsets.all(8),
children: <Widget>[
Padding(
padding: EdgeInsets.only(left: doubleSpace, top: 10),
child: Text(
'Hasil Pencarian',
style: TextStyle(
fontSize: 15,
color: Colors.black,
fontFamily: 'Muli',
),
),
),
Container(
height: 90,
color: Colors.transparent,
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
CircleAvatar(
backgroundColor: greenPrimary,
child: Text('Test'),
),
Padding(
padding: EdgeInsets.all(doubleSpace),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'Margo City',
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.w800,
color: Colors.black,
fontFamily: 'Muli',
),
),
),
Icon(
Icons.arrow_forward_ios,
color: Colors.grey[400],
size: 20,
)
],
Text(
'Jl. Margonda Raya No.358, Kemir...',
style: TextStyle(
fontSize: 15,
color: Colors.black,
fontFamily: 'Muli',
),
),
],
),
),
),
Container(
decoration: BoxDecoration(
border: Border(top: BorderSide(color: Colors.grey[400]))),
),
Container(
height: 90,
color: Colors.transparent,
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
CircleAvatar(
backgroundColor: greenPrimary,
child: Text('Test'),
),
Padding(
padding: EdgeInsets.all(doubleSpace),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'Margo City',
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.w800,
color: Colors.black,
fontFamily: 'Muli',
),
),
Text(
'Jl. Margonda Raya No.358, Kemir...',
style: TextStyle(
fontSize: 15,
color: Colors.black,
fontFamily: 'Muli',
),
),
],
Icon(
Icons.arrow_forward_ios,
color: Colors.grey[400],
size: 20,
)
],
),
),
Container(
decoration: BoxDecoration(
border: Border(top: BorderSide(color: Colors.grey[400]))),
),
Container(
height: 90,
color: Colors.transparent,
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
CircleAvatar(
backgroundColor: greenPrimary,
child: Text('Test'),
),
Padding(
padding: EdgeInsets.all(doubleSpace),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'Margo City',
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.w800,
color: Colors.black,
fontFamily: 'Muli',
),
),
),
Icon(
Icons.arrow_forward_ios,
color: Colors.grey[400],
size: 20,
)
],
Text(
'Jl. Margonda Raya No.358, Kemir...',
style: TextStyle(
fontSize: 15,
color: Colors.black,
fontFamily: 'Muli',
),
),
],
),
),
),
Container(
decoration: BoxDecoration(
border: Border(top: BorderSide(color: Colors.grey[400]))),
),
],
Icon(
Icons.arrow_forward_ios,
color: Colors.grey[400],
size: 20,
)
],
),
),
);
}
Container(
decoration: BoxDecoration(
border: Border(top: BorderSide(color: Colors.grey[400]))),
),
],
);
}
......@@ -25,8 +25,7 @@ dependencies:
location: ^2.5.3
flutter_plugin_android_lifecycle: ^1.0.6
flutter_polyline_points: ^0.1.0
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
path_provider: ^1.6.5
cupertino_icons: ^0.1.2
google_maps_flutter: ^0.5.24+1
flutter_dotenv: ^2.1.0
......
import 'dart:io';
import 'package:flutter/services.dart';
import 'package:mockito/mockito.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:ppl_disabilitas/network/cookies_interface.dart';
class MockCookiesInterface extends Mock implements CookiesInterface {}
void main() {
TestWidgetsFlutterBinding.ensureInitialized();
MethodChannel channel =
const MethodChannel('plugins.flutter.io/path_provider');
setUpAll(() async {
// Create a temporary directory.
final directory = await Directory.systemTemp.createTemp();
// Mock out the MethodChannel for the path_provider plugin.
channel.setMockMethodCallHandler((MethodCall methodCall) async {
// If you're getting the apps documents directory, return the path to the
// temp directory on the test environment instead.
if (methodCall.method == 'getApplicationDocumentsDirectory') {
return directory.path;
}
return null;
});
});
CookiesInterface mockHttpClient;
test('Creates cookie file for sign in session', () async {
final responseHeaderFromSignIn = {
"set-cookie":
"csrftoken=v4E6UNpTMUMAoDxMoSZUBVPuAh7mkIb96DfRcakdivghb0d57yvCZxbbya7L3kFv; expires=Fri, 05 Mar 2021 03:33:39 GMT; Max-Age=31449600; Path=/; SameSite=Lax;sessionid=vrarp9pga02bwr97duemf6ym94gjgepn; expires=Fri, 20 Mar 2020 03:33:39 GMT; HttpOnly; Max-Age=1209600; Path=/; SameSite=Lax",
};
mockHttpClient = MockCookiesInterface();
String rootDir =
await channel.invokeMethod('getApplicationDocumentsDirectory');
<