Fakultas Ilmu Komputer UI

Commit 8a3f399d authored by Fakhira Devina's avatar Fakhira Devina
Browse files

[CHORE] filter on fasilitas is functional

parent 0e6e9850
Pipeline #41561 passed with stages
in 13 minutes and 41 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":[]},{"name":"sqflite","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":[]},{"name":"sqflite","path":"D:\\\\Flutter\\\\flutter_windows_v1.9.1+hotfix.2-stable\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\sqflite-1.3.0\\\\","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":[]},{"name":"sqflite","path":"D:\\\\Flutter\\\\flutter_windows_v1.9.1+hotfix.2-stable\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\sqflite-1.3.0\\\\","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":[]},{"name":"sqflite","path":"D:\\\\Flutter\\\\flutter_windows_v1.9.1+hotfix.2-stable\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\sqflite-1.3.0\\\\","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":[]},{"name":"sqflite","dependencies":[]}],"date_created":"2020-04-19 20:06:55.891576","version":"1.15.17"}
\ No newline at end of file
......@@ -7,6 +7,7 @@ import 'package:ppl_disabilitas/repository/KomentarRepository.dart';
class KomentarBloc {
KomentarRepository _komentarRepository;
StreamController _komentarListController;
List<KomentarModel> allKomentarFromApi;
StreamSink<NetworkModel<KomentarList>> get komentarListSink =>
_komentarListController.sink;
......@@ -24,6 +25,7 @@ class KomentarBloc {
try {
KomentarList komentarListResponse =
await _komentarRepository.fetchKomentar(namaLokasi);
allKomentarFromApi = List.from(komentarListResponse.allKomentar);
komentarListSink.add(NetworkModel.completed(komentarListResponse));
} catch (e) {
komentarListSink.add(NetworkModel.error(e.toString()));
......@@ -31,6 +33,33 @@ class KomentarBloc {
}
}
filterKomentarList(String tag, bool value, List<KomentarModel> currentList) {
if (value) {
for (var komentar in allKomentarFromApi) {
if (komentar.tag.contains(tag)) {
currentList.add(komentar);
}
}
} else {
currentList.removeWhere((komentar) => komentar.tag.contains(tag));
}
komentarListSink.add(NetworkModel.completed(KomentarList(currentList)));
}
sortKomentarList(String option, List<KomentarModel> currentList) {
if (option == 'latest') {
currentList.sort((prev_komentar, next_komentar) =>
prev_komentar.date_time.compareTo(next_komentar.date_time));
} else if (option == 'rating') {
currentList.sort((prev_komentar, next_komentar) =>
prev_komentar.like.compareTo(next_komentar.like));
} else {
currentList.sort((prev_komentar, next_komentar) =>
(prev_komentar.like + prev_komentar.dislike)
.compareTo(next_komentar.like + next_komentar.dislike));
}
}
dispose() {
_komentarListController?.close();
}
......
......@@ -27,13 +27,12 @@ class _FasilitasState extends State<Fasilitas> {
var bidangMiringVal = true;
var parkirUmumVal = true;
var parkirDisabilitasVal = true;
var komentarTerbaru = true;
var komentarRatingTertinggi = true;
var komentarTerpopuler = true;
var komentarTerbaru = false;
var komentarRatingTertinggi = false;
var komentarTerpopuler = false;
var showUrutan = true;
var komentarStream;
List<KomentarModel> allKomentarFromApi;
List<KomentarModel> komentarShown = [];
KomentarBloc _bloc;
@override
......@@ -42,12 +41,12 @@ class _FasilitasState extends State<Fasilitas> {
print(widget.nama);
print(widget.id);
_bloc = KomentarBloc(widget.nama);
komentarStream = _bloc.komentarListStream;
super.initState();
}
@override
Widget build(BuildContext context) {
komentarStream = _bloc.komentarListStream;
return Scaffold(
backgroundColor: Colors.white,
drawer: BisaGoDrawer(),
......@@ -203,9 +202,8 @@ class _FasilitasState extends State<Fasilitas> {
break;
case Status.COMPLETED:
allKomentarFromApi = snapshot.data.data.allKomentar;
komentarShown = allKomentarFromApi;
return Column(
children: komentarShown
children: allKomentarFromApi
.map<Widget>((k) => Komentar(
komentar: k,
))
......@@ -390,13 +388,13 @@ class _FasilitasState extends State<Fasilitas> {
activeColor: greenPale,
value: komentarTerbaru,
onChanged: (bool value) {
if (value) {
_bloc.sortKomentarList('latest',
allKomentarFromApi);
}
setStateModal(() {
komentarTerbaru = value;
});
setState(() {
komentarTerbaru = value;
changeKomentarShown();
});
},
),
),
......@@ -421,13 +419,15 @@ class _FasilitasState extends State<Fasilitas> {
activeColor: greenPale,
value: komentarTerpopuler,
onChanged: (bool value) {
if (value) {
print('kesini');
_bloc.sortKomentarList(
'popular',
allKomentarFromApi);
}
setStateModal(() {
komentarTerpopuler = value;
});
setState(() {
komentarTerpopuler = value;
changeKomentarShown();
});
},
),
),
......@@ -454,15 +454,15 @@ class _FasilitasState extends State<Fasilitas> {
activeColor: greenPale,
value: komentarRatingTertinggi,
onChanged: (bool value) {
if (value) {
_bloc.sortKomentarList(
'rating',
allKomentarFromApi);
}
setStateModal(() {
komentarRatingTertinggi =
value;
});
setState(() {
komentarRatingTertinggi =
value;
changeKomentarShown();
});
},
),
),
......@@ -497,29 +497,11 @@ class _FasilitasState extends State<Fasilitas> {
activeColor: greenPale,
value: kursiRodaVal,
onChanged: (bool value) {
_bloc.filterKomentarList('KR',
value, allKomentarFromApi);
setStateModal(() {
kursiRodaVal = value;
});
setState(() {
kursiRodaVal = value;
if (kursiRodaVal) {
print(
'length all komentar from api: ${allKomentarFromApi.length}');
allKomentarFromApi
.map((komentar) {
if (komentar.tag
.contains('KR')) {
komentarShown
.add(komentar);
print('782');
}
});
} else {
komentarShown.removeWhere(
(komentar) => komentar.tag
.contains('KR'));
}
});
},
),
),
......@@ -544,31 +526,10 @@ class _FasilitasState extends State<Fasilitas> {
activeColor: greenPale,
value: liftVal,
onChanged: (bool value) {
_bloc.filterKomentarList('LF',
value, allKomentarFromApi);
setStateModal(() {
liftVal = value;
print(
'lif val $liftVal value $value');
});
setState(() {
liftVal = value;
if (liftVal) {
print('lift val true');
allKomentarFromApi
.map((komentar) {
if (komentar.tag
.contains('LF')) {
komentarShown
.add(komentar);
print('792');
}
});
} else {
komentarShown.removeWhere(
(komentar) => komentar.tag
.contains('LF'));
}
print(
'lif val $liftVal value $value');
});
},
),
......@@ -594,32 +555,11 @@ class _FasilitasState extends State<Fasilitas> {
activeColor: greenPale,
value: toiletDisabilitasVal,
onChanged: (bool value) {
_bloc.filterKomentarList('TD',
value, allKomentarFromApi);
setStateModal(() {
toiletDisabilitasVal = value;
});
setState(() {
toiletDisabilitasVal = value;
if (toiletDisabilitasVal) {
print('601');
print(allKomentarFromApi
.length);
allKomentarFromApi
.map((komentar) {
if (komentar.tag
.contains('TD')) {
komentarShown
.add(komentar);
print('803');
}
});
} else {
print('614');
komentarShown.removeWhere(
(komentar) => komentar.tag
.contains('TD'));
}
});
},
),
),
......@@ -644,12 +584,10 @@ class _FasilitasState extends State<Fasilitas> {
activeColor: greenPale,
value: tempatIbadahVal,
onChanged: (bool value) {
_bloc.filterKomentarList('MM',
value, allKomentarFromApi);
setStateModal(() {
tempatIbadahVal = value;
changeKomentarShown();
});
setState(() {
tempatIbadahVal = value;
});
},
),
......@@ -675,13 +613,11 @@ class _FasilitasState extends State<Fasilitas> {
activeColor: greenPale,
value: bidangMiringVal,
onChanged: (bool value) {
_bloc.filterKomentarList('BM',
value, allKomentarFromApi);
setStateModal(() {
bidangMiringVal = value;
});
setState(() {
bidangMiringVal = value;
changeKomentarShown();
});
},
),
),
......@@ -706,13 +642,11 @@ class _FasilitasState extends State<Fasilitas> {
activeColor: greenPale,
value: parkirUmumVal,
onChanged: (bool value) {
_bloc.filterKomentarList('TB',
value, allKomentarFromApi);
setStateModal(() {
parkirUmumVal = value;
});
setState(() {
parkirUmumVal = value;
changeKomentarShown();
});
},
),
),
......@@ -737,13 +671,11 @@ class _FasilitasState extends State<Fasilitas> {
activeColor: greenPale,
value: parkirDisabilitasVal,
onChanged: (bool value) {
_bloc.filterKomentarList('PK',
value, allKomentarFromApi);
setStateModal(() {
parkirDisabilitasVal = value;
});
setState(() {
parkirDisabilitasVal = value;
changeKomentarShown();
});
},
),
),
......@@ -849,117 +781,19 @@ class _FasilitasState extends State<Fasilitas> {
);
}
void changeKomentarShown() {
print('801');
if (kursiRodaVal) {
print('length all komentar from api: ${allKomentarFromApi.length}');
allKomentarFromApi.map((komentar) {
if (komentar.tag.contains('KR')) {
komentarShown.add(komentar);
print('782');
}
});
} else {
komentarShown.removeWhere((komentar) => komentar.tag.contains('KR'));
}
if (liftVal) {
print('lift val true');
allKomentarFromApi.map((komentar) {
if (komentar.tag.contains('LF')) {
komentarShown.add(komentar);
print('792');
}
});
} else {
komentarShown.removeWhere((komentar) => komentar.tag.contains('LF'));
}
if (toiletDisabilitasVal) {
print('821');
allKomentarFromApi.map((komentar) {
print(allKomentarFromApi.length);
if (komentar.tag.contains('TD')) {
komentarShown.add(komentar);
print('803');
}
});
} else {
komentarShown.removeWhere((komentar) => komentar.tag.contains('TD'));
}
if (tempatIbadahVal) {
allKomentarFromApi.map((komentar) {
if (komentar.tag.contains('MM')) {
komentarShown.add(komentar);
print('813');
}
});
} else {
komentarShown.removeWhere((komentar) => komentar.tag.contains('MM'));
}
if (bidangMiringVal) {
allKomentarFromApi.map((komentar) {
if (komentar.tag.contains('BM')) {
komentarShown.add(komentar);
print('823');
}
});
} else {
komentarShown.removeWhere((komentar) => komentar.tag.contains('BM'));
}
if (parkirUmumVal) {
allKomentarFromApi.map((komentar) {
if (komentar.tag.contains('TB')) {
komentarShown.add(komentar);
}
});
} else {
komentarShown.removeWhere((komentar) => komentar.tag.contains('TB'));
}
if (parkirDisabilitasVal) {
allKomentarFromApi.map((komentar) {
if (komentar.tag.contains('PK')) {
komentarShown.add(komentar);
}
});
} else {
komentarShown.removeWhere((komentar) => komentar.tag.contains('PK'));
}
if (komentarTerbaru) {
komentarShown.sort((prev_komentar, next_komentar) =>
prev_komentar.date_time.compareTo(next_komentar.date_time));
} else {
komentarShown = allKomentarFromApi;
}
if (komentarRatingTertinggi) {
komentarShown.sort((prev_komentar, next_komentar) =>
prev_komentar.like.compareTo(next_komentar.like));
} else {
komentarShown = allKomentarFromApi;
}
if (komentarTerpopuler) {
komentarShown.sort((prev_komentar, next_komentar) =>
(prev_komentar.like + prev_komentar.dislike)
.compareTo(next_komentar.like + next_komentar.dislike));
} else {
komentarShown = allKomentarFromApi;
}
}
@override
void dispose() {
setState(() {
kursiRodaVal = false;
liftVal = false;
toiletDisabilitasVal = false;
tempatIbadahVal = false;
bidangMiringVal = false;
parkirUmumVal = false;
parkirDisabilitasVal = false;
komentarTerbaru = false;
komentarRatingTertinggi = false;
komentarTerpopuler = false;
showUrutan = true;
});
kursiRodaVal = false;
liftVal = false;
toiletDisabilitasVal = false;
tempatIbadahVal = false;
bidangMiringVal = false;
parkirUmumVal = false;
parkirDisabilitasVal = false;
komentarTerbaru = false;
komentarRatingTertinggi = false;
komentarTerpopuler = false;
showUrutan = true;
super.dispose();
}
}
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