Fakultas Ilmu Komputer UI

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

Merge branch 'dev-hira' into PBI-2-pencarian_lokasi

parents 922f9ab5 a8bf57d6
Pipeline #38332 passed with stages
in 5 minutes and 12 seconds
{"_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
{"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-1.6.5\\\\","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-1.6.5\\\\","dependencies":[]}],"macos":[{"name":"path_provider_macos","path":"D:\\\\Flutter\\\\flutter_windows_v1.9.1+hotfix.2-stable\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\path_provider_macos-0.0.4\\\\","dependencies":[]}],"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":["path_provider_macos"]},{"name":"path_provider_macos","dependencies":[]}],"date_created":"2020-04-06 14:33:59.474358","version":"1.15.17"}
\ No newline at end of file
......@@ -33,11 +33,9 @@ class LokasiResponseBloc {
try {
LokasiListResponse lokasiListResponse =
await _lokasiRepository.fetchLokasi();
print("lokasi list response: $lokasiListResponse");
lokasiListSink.add(NetworkModel.completed(lokasiListResponse));
} catch (e) {
lokasiListSink.add(NetworkModel.error(e.toString()));
print("$e");
}
}
......@@ -45,11 +43,9 @@ class LokasiResponseBloc {
recentSearchSink.add(NetworkModel.loading('Getting Recent Search'));
try {
LokasiListResponse recentSearchData = await _lokasiRepository.fetchRecentSearch();
print("recentSearchData ${recentSearchData.listLokasi}");
recentSearchSink.add(NetworkModel.completed(recentSearchData));
} catch (e) {
recentSearchSink.add(NetworkModel.error(e.toString()));
print("line 53 ${e.toString()}");
}
}
......
......@@ -72,7 +72,7 @@ class CookiesInterface {
} else {
currentSearchHistory = json.decode(cookie);
}
currentSearchHistory.add(recentSearch);
currentSearchHistory.insert(0, recentSearch);
});
} else {
currentSearchHistory = [];
......
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:ppl_disabilitas/bloc/LokasiResponseBloc.dart';
import 'package:ppl_disabilitas/config/styles.dart';
import 'package:ppl_disabilitas/model/lokasi.dart';
import 'package:ppl_disabilitas/network/data/network_model.dart';
import 'package:ppl_disabilitas/network/network_interface.dart';
/// Create Pencarian page widget with a state
class Pencarian extends StatefulWidget {
......@@ -21,38 +22,35 @@ class PencarianState extends State<Pencarian> {
/// Text for appbar
Widget appBarText = Text('Pencarian Lokasi');
/// To get API of places
NetworkInterface networkInterface = NetworkInterface();
/// List of places currently searched on the textFormField
List<Lokasi> currentSearch = [];
/// List for places from API
List places = [];
/// List of places currently searched on the textFormField
List currentSearch = [];
List<Lokasi> places = [];
/// Data from API
Future<NetworkModel> data;
/// BLoC for pencarian
LokasiResponseBloc _bloc = LokasiResponseBloc();
@override
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties);
properties..add(DiagnosticsProperty<List>('places', places))
..add(DiagnosticsProperty<List>('currentSearch', currentSearch))
..add(DiagnosticsProperty<NetworkInterface>('networkInterface', networkInterface));
properties
..add(DiagnosticsProperty<List>('places', places))
..add(DiagnosticsProperty<List>('currentSearch', currentSearch));
}
@override
void initState() {
data = networkInterface.get(
url: 'https://my.api.mockaroo.com/mall.json?key=dbcde960');
myController.addListener(() {
List tempList = [];
List<Lokasi> tempList = [];
for (int i = 0; i < places.length; i++) {
if (places[i]['nama']
.toLowerCase()
.contains(myController.text.toLowerCase())) {
tempList.add(places[i]);
if (myController.text.isNotEmpty) {
if (places[i]
.nama
.toLowerCase()
.contains(myController.text.toLowerCase())) {
tempList.add(places[i]);
}
}
}
setState(() {
......@@ -65,121 +63,202 @@ class PencarianState extends State<Pencarian> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: greenPrimary,
leading: IconButton(
icon: Icon(Icons.arrow_back_ios, size: 25),
key: Key('Back Icon Key'),
onPressed: () => Navigator.pop(context, 'Take me back')),
title: Container(
margin: EdgeInsets.only(top: doubleSpace, bottom: doubleSpace),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: doubleBorderRadius,
boxShadow: regularShadow),
child: TextFormField(
controller: myController,
key: Key('Text Field Mau Kemana'),
decoration: InputDecoration(
contentPadding: EdgeInsets.all(0),
isDense: false,
prefixIcon: Icon(
Icons.search,
appBar: AppBar(
backgroundColor: greenPrimary,
leading: IconButton(
icon: Icon(Icons.arrow_back_ios, size: 25),
key: Key('Back Icon Key'),
onPressed: () => Navigator.pop(context, 'Take me back')),
title: Container(
margin: EdgeInsets.only(top: doubleSpace, bottom: doubleSpace),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: doubleBorderRadius,
boxShadow: regularShadow),
child: TextFormField(
controller: myController,
key: Key('Text Field Mau Kemana'),
decoration: InputDecoration(
contentPadding: EdgeInsets.all(0),
isDense: false,
prefixIcon: Icon(
Icons.search,
color: greenPrimary,
size: 25,
),
border: InputBorder.none,
fillColor: Colors.white,
labelText: 'Kamu mau kemana?',
labelStyle: TextStyle(
color: greenPrimary,
fontSize: 18,
fontFamily: 'Muli',
fontWeight: FontWeight.w700),
suffixIcon: IconButton(
icon: Icon(
Icons.mic,
color: greenPrimary,
size: 25,
),
border: InputBorder.none,
fillColor: Colors.white,
labelText: 'Kamu mau kemana?',
labelStyle: TextStyle(
color: greenPrimary,
fontSize: 18,
fontFamily: 'Muli',
fontWeight: FontWeight.w700),
suffixIcon: IconButton(
icon: Icon(
Icons.mic,
color: greenPrimary,
size: 25,
), onPressed: () {},
)),
),
onPressed: () {},
)),
),
),
body: Stack(children: [
FutureBuilder<NetworkModel>(
future: data,
),
body: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
StreamBuilder<NetworkModel<LokasiListResponse>>(
stream: _bloc.recentSearchStream,
builder: (context, snapshot) {
if (snapshot.hasData) {
//places = snapshot.data.response;
return Container();
} else if (snapshot.hasError) {
return Text('${snapshot.error}');
switch (snapshot.data.status) {
case Status.LOADING:
return Center(
child: CircularProgressIndicator(
valueColor: AlwaysStoppedAnimation<Color>(greenPrimary),
),
);
break;
case Status.COMPLETED:
final recentSearch = snapshot.data.data;
Widget displayWidget;
if (recentSearch.listLokasi.isEmpty) {
displayWidget = Center(
child: Text("Anda belum pernah melakukan pencarian"));
} else {
displayWidget = makeLokasiWidget(
"history", recentSearch.listLokasi.take(3).toList());
}
return Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Container(
margin: EdgeInsets.all(doubleSpace),
child: Text(
"Pencarian terdahulu",
style:
TextStyle(fontFamily: 'Muli', fontSize: 15),
)),
Flexible(child: displayWidget),
],
));
break;
case Status.ERROR:
return Center(
child: Text("${snapshot.data.status}"),
);
break;
}
}
// By default, show a loading spinner.
return CircularProgressIndicator();
return Container();
},
),
Container(
margin: EdgeInsets.only(
left: doubleSpace, top: regularSpace, bottom: smallSpace),
child: Text("Hasil Pencarian"),
),
StreamBuilder<NetworkModel<LokasiListResponse>>(
stream: _bloc.lokasiListStream,
builder: (context, snapshot) {
if (snapshot.hasData) {
switch (snapshot.data.status) {
case Status.LOADING:
return Center(
child: CircularProgressIndicator(
valueColor: AlwaysStoppedAnimation<Color>(greenPrimary),
),
);
break;
case Status.COMPLETED:
places = snapshot.data.data.listLokasi;
return Expanded(
flex: 2,
child: currentSearch.isEmpty
? Center(child: Text('Cari lokasi'))
: makeLokasiWidget("api", currentSearch));
break;
case Status.ERROR:
return Center(
child: Text(snapshot.data.data.toString()),
);
break;
}
}
return Container();
},
),
ListView.builder(
itemCount: currentSearch.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,
],
),
);
}
Widget makeLokasiWidget(String key, List<Lokasi> places) {
print('$key - $places');
return ListView.builder(
shrinkWrap: true,
itemCount: places.length,
itemBuilder: (context, index) {
return InkWell(
key: Key("$key-${places[index].nama}"),
onTap: () {
_bloc.saveRecentSearch(places[index]);
},
child: 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>[
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(
currentSearch[index]['nama'],
key: Key('Result text'),
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.w800,
color: Colors.black,
fontFamily: 'Muli',
),
),
Text(
currentSearch[index]['alamat'],
style: TextStyle(
fontSize: 15,
color: Colors.black,
fontFamily: 'Muli',
),
),
],
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',
),
),
),
],
],
),
),
Icon(
Icons.arrow_forward_ios,
color: Colors.grey[400],
size: 20,
)
],
),
);
})
]));
Icon(
Icons.arrow_forward_ios,
color: Colors.grey[400],
size: 20,
)
],
),
),
);
});
}
}
\ No newline at end of file
}
......@@ -22,7 +22,6 @@ class LokasiRepository {
} else {
await CookiesInterface().getCookieFile(fileName: "searchhistory").then((cookie) {
response = json.decode(cookie);
print("response type: ${response.runtimeType}");
});
}
});
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment