From e2df1b465cbaa70d334f38e7bfa57bccdd891ea6 Mon Sep 17 00:00:00 2001 From: Fakhira Date: Thu, 23 Apr 2020 17:44:46 +0700 Subject: [PATCH 01/13] [CHORE] refresh state after going to other page --- .flutter-plugins-dependencies | 6 +----- lib/page/filter_fasilitas/fasilitas.dart | 5 ++--- lib/page/pencarian/pencarian.dart | 5 +++-- lib/repository/KomentarRepository.dart | 3 +-- 4 files changed, 7 insertions(+), 12 deletions(-) diff --git a/.flutter-plugins-dependencies b/.flutter-plugins-dependencies index 4323a78..762d9b1 100644 --- a/.flutter-plugins-dependencies +++ b/.flutter-plugins-dependencies @@ -1,5 +1 @@ -<<<<<<< HEAD -{"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-20 12:56:31.966938","version":"1.15.17"} -======= -{"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":"shared_preferences","path":"D:\\\\Flutter\\\\flutter_windows_v1.9.1+hotfix.2-stable\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\shared_preferences-0.5.6+3\\\\","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":"shared_preferences","path":"D:\\\\Flutter\\\\flutter_windows_v1.9.1+hotfix.2-stable\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\shared_preferences-0.5.6+3\\\\","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":"shared_preferences_macos","path":"D:\\\\Flutter\\\\flutter_windows_v1.9.1+hotfix.2-stable\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\shared_preferences_macos-0.0.1+6\\\\","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":[{"name":"shared_preferences_web","path":"D:\\\\Flutter\\\\flutter_windows_v1.9.1+hotfix.2-stable\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\shared_preferences_web-0.1.2+4\\\\","dependencies":[]}]},"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":"shared_preferences","dependencies":["shared_preferences_macos","shared_preferences_web"]},{"name":"shared_preferences_macos","dependencies":[]},{"name":"shared_preferences_web","dependencies":[]},{"name":"sqflite","dependencies":[]}],"date_created":"2020-04-21 10:40:51.758556","version":"1.15.17"} ->>>>>>> staging +{"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":"image_picker","path":"D:\\\\Flutter\\\\flutter_windows_v1.9.1+hotfix.2-stable\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\image_picker-0.6.5+2\\\\","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":"shared_preferences","path":"D:\\\\Flutter\\\\flutter_windows_v1.9.1+hotfix.2-stable\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\shared_preferences-0.5.6+3\\\\","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":"image_picker","path":"D:\\\\Flutter\\\\flutter_windows_v1.9.1+hotfix.2-stable\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\image_picker-0.6.5+2\\\\","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":"shared_preferences","path":"D:\\\\Flutter\\\\flutter_windows_v1.9.1+hotfix.2-stable\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\shared_preferences-0.5.6+3\\\\","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":"shared_preferences_macos","path":"D:\\\\Flutter\\\\flutter_windows_v1.9.1+hotfix.2-stable\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\shared_preferences_macos-0.0.1+7\\\\","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":[{"name":"shared_preferences_web","path":"D:\\\\Flutter\\\\flutter_windows_v1.9.1+hotfix.2-stable\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\shared_preferences_web-0.1.2+4\\\\","dependencies":[]}]},"dependencyGraph":[{"name":"flutter_plugin_android_lifecycle","dependencies":[]},{"name":"google_maps_flutter","dependencies":["flutter_plugin_android_lifecycle"]},{"name":"image_picker","dependencies":["flutter_plugin_android_lifecycle"]},{"name":"location","dependencies":[]},{"name":"path_provider","dependencies":["path_provider_macos"]},{"name":"path_provider_macos","dependencies":[]},{"name":"shared_preferences","dependencies":["shared_preferences_macos","shared_preferences_web"]},{"name":"shared_preferences_macos","dependencies":[]},{"name":"shared_preferences_web","dependencies":[]},{"name":"sqflite","dependencies":[]}],"date_created":"2020-04-23 17:13:36.402631","version":"1.15.17"} \ No newline at end of file diff --git a/lib/page/filter_fasilitas/fasilitas.dart b/lib/page/filter_fasilitas/fasilitas.dart index c16ae2d..0efeb6c 100644 --- a/lib/page/filter_fasilitas/fasilitas.dart +++ b/lib/page/filter_fasilitas/fasilitas.dart @@ -47,7 +47,6 @@ class _FasilitasState extends State { void initState() { allKomentarFromApi = []; _bloc = KomentarBloc(widget.nama); - komentarStream = _bloc.komentarListStream; super.initState(); } @@ -194,7 +193,7 @@ class _FasilitasState extends State { ), ), StreamBuilder( - stream: komentarStream, + stream: _bloc.komentarListStream, builder: (context, snapshot) { if (snapshot.hasData) { switch (snapshot.data.status) { @@ -946,7 +945,7 @@ class _FasilitasState extends State { await Navigator.of(context).push(MaterialPageRoute( builder: (BuildContext context) => AddInformasi( nama: widget.nama, - ))); + ))).then((value) => _bloc.fetchKomentarList(widget.nama)); } } diff --git a/lib/page/pencarian/pencarian.dart b/lib/page/pencarian/pencarian.dart index a42cbb1..01b4a26 100644 --- a/lib/page/pencarian/pencarian.dart +++ b/lib/page/pencarian/pencarian.dart @@ -208,14 +208,14 @@ class PencarianState extends State { key: Key("$key-${places[index].name}"), onTap: () { _bloc.saveRecentSearch(places[index]); - Navigator.of(context).push(MaterialPageRoute( + Navigator.of(context).push(MaterialPageRoute( builder: (BuildContext context) => Fasilitas( alamat: places[index].alamat, nama: places[index].name, telpon: places[index].no_telp, url: places[index].image, id: places[index].id, - ))); + ))).then((value) => _bloc.fetchRecentSearch()); }, child: Container( decoration: BoxDecoration( @@ -249,6 +249,7 @@ class PencarianState extends State { color: Colors.black, fontFamily: 'Muli', ), + overflow: TextOverflow.ellipsis, ), Text( places[index].alamat, diff --git a/lib/repository/KomentarRepository.dart b/lib/repository/KomentarRepository.dart index 94615c8..27afdfc 100644 --- a/lib/repository/KomentarRepository.dart +++ b/lib/repository/KomentarRepository.dart @@ -11,8 +11,7 @@ class KomentarRepository { final response = await _network.get( url: url, isLogin: false); - final data = response.values.toList(); - print(data); + final data = response.values.toList().reversed.toList(); return KomentarList( data.map((komentar) => KomentarModel.fromJson(komentar)).toList()); } -- GitLab From 59602daa562fa7b03e81165c754d43afbea49823 Mon Sep 17 00:00:00 2001 From: Agnes Handoko Date: Mon, 27 Apr 2020 18:42:54 +0700 Subject: [PATCH 02/13] [CHORE] merged branch PBI to dev-agnes --- .flutter-plugins-dependencies | 2 +- lib/page/informasi/layananDisabilitas.dart | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/.flutter-plugins-dependencies b/.flutter-plugins-dependencies index 7b9b74c..443fcb7 100644 --- a/.flutter-plugins-dependencies +++ b/.flutter-plugins-dependencies @@ -1 +1 @@ -{"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":"shared_preferences","path":"D:\\\\Flutter\\\\flutter_windows_v1.9.1+hotfix.2-stable\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\shared_preferences-0.5.6+3\\\\","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":"shared_preferences","path":"D:\\\\Flutter\\\\flutter_windows_v1.9.1+hotfix.2-stable\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\shared_preferences-0.5.6+3\\\\","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":"shared_preferences_macos","path":"D:\\\\Flutter\\\\flutter_windows_v1.9.1+hotfix.2-stable\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\shared_preferences_macos-0.0.1+6\\\\","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":[{"name":"shared_preferences_web","path":"D:\\\\Flutter\\\\flutter_windows_v1.9.1+hotfix.2-stable\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\shared_preferences_web-0.1.2+4\\\\","dependencies":[]}]},"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":"shared_preferences","dependencies":["shared_preferences_macos","shared_preferences_web"]},{"name":"shared_preferences_macos","dependencies":[]},{"name":"shared_preferences_web","dependencies":[]},{"name":"sqflite","dependencies":[]}],"date_created":"2020-04-21 10:40:51.758556","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":"image_picker","dependencies":["flutter_plugin_android_lifecycle"]},{"name":"location","dependencies":[]},{"name":"path_provider","dependencies":["path_provider_macos"]},{"name":"path_provider_macos","dependencies":[]},{"name":"shared_preferences","dependencies":["shared_preferences_macos","shared_preferences_web"]},{"name":"shared_preferences_macos","dependencies":[]},{"name":"shared_preferences_web","dependencies":[]},{"name":"sqflite","dependencies":[]}]} \ No newline at end of file diff --git a/lib/page/informasi/layananDisabilitas.dart b/lib/page/informasi/layananDisabilitas.dart index 0460170..a57a8a9 100644 --- a/lib/page/informasi/layananDisabilitas.dart +++ b/lib/page/informasi/layananDisabilitas.dart @@ -20,7 +20,8 @@ class _LayananDisabilitasState extends State { ), drawer: BisaGoDrawer(), body: Container( - padding: EdgeInsets.only(top: tripleSpace, right: doubleSpace, left: doubleSpace), + padding: EdgeInsets.only( + top: tripleSpace, right: doubleSpace, left: doubleSpace), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ @@ -61,7 +62,8 @@ class _LayananDisabilitasState extends State { children: [ Container( padding: EdgeInsets.only(right: regularSpace), - child: Icon(Icons.add_box, color: greenPrimary, size: 30)), + child: Icon(Icons.add_box, + color: greenPrimary, size: 30)), Flexible( child: Text( "Registrasi Penyandang Disabilitas", @@ -98,7 +100,8 @@ class _LayananDisabilitasState extends State { children: [ Container( padding: EdgeInsets.only(right: regularSpace), - child: Icon(Icons.info, color: greenPrimary, size: 30)), + child: + Icon(Icons.info, color: greenPrimary, size: 30)), Flexible( child: Text( "Informasi Sekolah dengan Dukungan Disabilitas", -- GitLab From ad7d90dde4415b42ebec9742eab2f6f2c02da878 Mon Sep 17 00:00:00 2001 From: Firriyal Bin Yahya Date: Sat, 2 May 2020 17:56:51 +0700 Subject: [PATCH 03/13] [CHORE] model sekolah --- .flutter-plugins-dependencies | 2 +- lib/model/sekolah.dart | 22 +++++----- lib/model/sekolah.g.dart | 47 +++++++++++++++++++++ lib/page/informasi/list_sekolah.dart | 60 +++++++++++++++++++++------ lib/repository/SekolahRepository.dart | 2 +- 5 files changed, 109 insertions(+), 24 deletions(-) create mode 100644 lib/model/sekolah.g.dart diff --git a/.flutter-plugins-dependencies b/.flutter-plugins-dependencies index 7b9b74c..443fcb7 100644 --- a/.flutter-plugins-dependencies +++ b/.flutter-plugins-dependencies @@ -1 +1 @@ -{"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":"shared_preferences","path":"D:\\\\Flutter\\\\flutter_windows_v1.9.1+hotfix.2-stable\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\shared_preferences-0.5.6+3\\\\","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":"shared_preferences","path":"D:\\\\Flutter\\\\flutter_windows_v1.9.1+hotfix.2-stable\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\shared_preferences-0.5.6+3\\\\","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":"shared_preferences_macos","path":"D:\\\\Flutter\\\\flutter_windows_v1.9.1+hotfix.2-stable\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\shared_preferences_macos-0.0.1+6\\\\","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":[{"name":"shared_preferences_web","path":"D:\\\\Flutter\\\\flutter_windows_v1.9.1+hotfix.2-stable\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\shared_preferences_web-0.1.2+4\\\\","dependencies":[]}]},"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":"shared_preferences","dependencies":["shared_preferences_macos","shared_preferences_web"]},{"name":"shared_preferences_macos","dependencies":[]},{"name":"shared_preferences_web","dependencies":[]},{"name":"sqflite","dependencies":[]}],"date_created":"2020-04-21 10:40:51.758556","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":"image_picker","dependencies":["flutter_plugin_android_lifecycle"]},{"name":"location","dependencies":[]},{"name":"path_provider","dependencies":["path_provider_macos"]},{"name":"path_provider_macos","dependencies":[]},{"name":"shared_preferences","dependencies":["shared_preferences_macos","shared_preferences_web"]},{"name":"shared_preferences_macos","dependencies":[]},{"name":"shared_preferences_web","dependencies":[]},{"name":"sqflite","dependencies":[]}]} \ No newline at end of file diff --git a/lib/model/sekolah.dart b/lib/model/sekolah.dart index 1b4dc9f..f5aa5f8 100644 --- a/lib/model/sekolah.dart +++ b/lib/model/sekolah.dart @@ -1,24 +1,26 @@ import 'package:json_annotation/json_annotation.dart'; - part 'sekolah.g.dart'; - @JsonSerializable() class SekolahList { - final List allSekolah; + List allSekolah; + SekolahList(this.allSekolah); } @JsonSerializable() class SekolahModel { - final String nama_orang; - final int suka; - final int tidak_suka; - final String foto; + int id; + String name; + String alamat; + String no_telp; + String website; + int jumlah_siswa; + String status; + String jenis_sekolah; + String akreditasi; - SekolahModel( - {this.nama_orang, this.suka, this.tidak_suka, this.foto}); + SekolahModel(); factory SekolahModel.fromJson(Map json) => _$SekolahModelFromJson(json); - Map toJson() => _$SekolahModelToJson(this); } \ No newline at end of file diff --git a/lib/model/sekolah.g.dart b/lib/model/sekolah.g.dart new file mode 100644 index 0000000..2baf76f --- /dev/null +++ b/lib/model/sekolah.g.dart @@ -0,0 +1,47 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'sekolah.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +SekolahList _$SekolahListFromJson(Map json) { + return SekolahList( + (json['allSekolah'] as List) + ?.map((e) => + e == null ? null : SekolahModel.fromJson(e as Map)) + ?.toList(), + ); +} + +Map _$SekolahListToJson(SekolahList instance) => + { + 'allSekolah': instance.allSekolah, + }; + +SekolahModel _$SekolahModelFromJson(Map json) { + return SekolahModel() + ..id = json['id'] as int + ..name = json['name'] as String + ..alamat = json['alamat'] as String + ..no_telp = json['no_telp'] as String + ..website = json['website'] as String + ..jumlah_siswa = json['jumlah_siswa'] as int + ..status = json['status'] as String + ..jenis_sekolah = json['jenis_sekolah'] as String + ..akreditasi = json['akreditasi'] as String; +} + +Map _$SekolahModelToJson(SekolahModel instance) => + { + 'id': instance.id, + 'name': instance.name, + 'alamat': instance.alamat, + 'no_telp': instance.no_telp, + 'website': instance.website, + 'jumlah_siswa': instance.jumlah_siswa, + 'status': instance.status, + 'jenis_sekolah': instance.jenis_sekolah, + 'akreditasi': instance.akreditasi, + }; diff --git a/lib/page/informasi/list_sekolah.dart b/lib/page/informasi/list_sekolah.dart index 25c3ab4..7d066b8 100644 --- a/lib/page/informasi/list_sekolah.dart +++ b/lib/page/informasi/list_sekolah.dart @@ -1,8 +1,12 @@ +import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:ppl_disabilitas/component/bisago_drawer.dart'; import 'package:flutter/widgets.dart'; import 'package:ppl_disabilitas/config/styles.dart'; import 'package:ppl_disabilitas/page/informasi/detailSekolah.dart'; +import 'package:ppl_disabilitas/bloc/SekolahBloc.dart'; +import 'package:ppl_disabilitas/model/sekolah.dart'; +import 'package:ppl_disabilitas/network/data/network_model.dart'; class ListSekolah extends StatefulWidget { @override @@ -19,11 +23,18 @@ class _ListSekolahState extends State { var showKategoriSekolah = false; var showTingkatSekolah = false; - List nama_sekolah = ["Sekolah Cita Buana", "SLB Negeri Kota Depok"]; - List alamat_sekolah = [ - "Jl. Paso No.84, Jagakarsa", - "Regency, Perumahan Permata" - ]; + List sekolah = []; + + /// BLoC for sekolah + SekolahBloc _bloc = SekolahBloc(); + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties + ..add(DiagnosticsProperty('sekolah', sekolah)); + } + @override Widget build(BuildContext context) { @@ -79,8 +90,33 @@ class _ListSekolahState extends State { ), ), ), - Container( - child: makeLokasiWidget("sekolah", nama_sekolah, alamat_sekolah), + StreamBuilder>( + stream: _bloc.sekolahListStream, + builder: (context, snapshot) { + if (snapshot.hasData) { + switch (snapshot.data.status) { + case Status.LOADING: + return Center( + child: CircularProgressIndicator( + valueColor: AlwaysStoppedAnimation(greenPrimary), + ), + ); + break; + case Status.COMPLETED: + sekolah = snapshot.data.data.allSekolah; + return Expanded( + flex: 2, + child: makeLokasiWidget("sekolah", sekolah)); + break; + case Status.ERROR: + return Center( + child: Text(snapshot.data.data.toString()), + ); + break; + } + } + return Container(); + }, ), ], ), @@ -115,13 +151,13 @@ class _ListSekolahState extends State { } Widget makeLokasiWidget( - String key, List nama_sekolah, List alamat_sekolah) { + String key, List sekolah) { return ListView.builder( shrinkWrap: true, - itemCount: nama_sekolah.length, + itemCount: sekolah.length, itemBuilder: (context, index) { return InkWell( - key: Key("$key-${nama_sekolah[index]}"), + key: Key("$key-${sekolah[index].name}"), onTap: () {}, child: Container( decoration: BoxDecoration( @@ -151,7 +187,7 @@ class _ListSekolahState extends State { children: [ Flexible( child: Text( - nama_sekolah[index], + sekolah[index].name, softWrap: true, textAlign: TextAlign.left, style: TextStyle( @@ -164,7 +200,7 @@ class _ListSekolahState extends State { ), Flexible( child: Text( - alamat_sekolah[index], + sekolah[index].alamat, softWrap: true, textAlign: TextAlign.left, style: TextStyle( diff --git a/lib/repository/SekolahRepository.dart b/lib/repository/SekolahRepository.dart index c4bbee4..bda7b06 100644 --- a/lib/repository/SekolahRepository.dart +++ b/lib/repository/SekolahRepository.dart @@ -6,7 +6,7 @@ class SekolahRepository { Future fetchSekolah() async { final response = await _network.get( - url: 'https://my.api.mockaroo.com/postingan.json?key=dbcde960', + url: 'http://poipole-staging.herokuapp.com/layanan-khusus/sekolah/list/', isLogin: false); print(response); return SekolahList( -- GitLab From 65b2a8a187d0e86379baecf9dbfa0c4c33c9a658 Mon Sep 17 00:00:00 2001 From: Fakhira Date: Sat, 2 May 2020 23:18:40 +0700 Subject: [PATCH 04/13] [RED] change http with Dio --- .flutter-plugins-dependencies | 2 +- lib/bloc/KomentarBloc.dart | 2 + lib/globalnetwork.dart | 41 +++++++++++++ lib/main.dart | 3 + lib/network/network_interface.dart | 56 ++++-------------- lib/page/filter_fasilitas/fasilitas.dart | 2 + .../postingan/detailpost.dart | 57 +++++++++++++++++-- lib/page/login/login.dart | 5 ++ lib/repository/KomentarRepository.dart | 2 +- lib/repository/LokasiRepository.dart | 4 +- pubspec.yaml | 1 + test/detail_post_test.dart | 2 + test/fasilitas_test.dart | 40 +++++++++---- 13 files changed, 152 insertions(+), 65 deletions(-) create mode 100644 lib/globalnetwork.dart diff --git a/.flutter-plugins-dependencies b/.flutter-plugins-dependencies index 762d9b1..443fcb7 100644 --- a/.flutter-plugins-dependencies +++ b/.flutter-plugins-dependencies @@ -1 +1 @@ -{"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":"image_picker","path":"D:\\\\Flutter\\\\flutter_windows_v1.9.1+hotfix.2-stable\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\image_picker-0.6.5+2\\\\","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":"shared_preferences","path":"D:\\\\Flutter\\\\flutter_windows_v1.9.1+hotfix.2-stable\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\shared_preferences-0.5.6+3\\\\","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":"image_picker","path":"D:\\\\Flutter\\\\flutter_windows_v1.9.1+hotfix.2-stable\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\image_picker-0.6.5+2\\\\","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":"shared_preferences","path":"D:\\\\Flutter\\\\flutter_windows_v1.9.1+hotfix.2-stable\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\shared_preferences-0.5.6+3\\\\","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":"shared_preferences_macos","path":"D:\\\\Flutter\\\\flutter_windows_v1.9.1+hotfix.2-stable\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\shared_preferences_macos-0.0.1+7\\\\","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":[{"name":"shared_preferences_web","path":"D:\\\\Flutter\\\\flutter_windows_v1.9.1+hotfix.2-stable\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\shared_preferences_web-0.1.2+4\\\\","dependencies":[]}]},"dependencyGraph":[{"name":"flutter_plugin_android_lifecycle","dependencies":[]},{"name":"google_maps_flutter","dependencies":["flutter_plugin_android_lifecycle"]},{"name":"image_picker","dependencies":["flutter_plugin_android_lifecycle"]},{"name":"location","dependencies":[]},{"name":"path_provider","dependencies":["path_provider_macos"]},{"name":"path_provider_macos","dependencies":[]},{"name":"shared_preferences","dependencies":["shared_preferences_macos","shared_preferences_web"]},{"name":"shared_preferences_macos","dependencies":[]},{"name":"shared_preferences_web","dependencies":[]},{"name":"sqflite","dependencies":[]}],"date_created":"2020-04-23 17:13:36.402631","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":"image_picker","dependencies":["flutter_plugin_android_lifecycle"]},{"name":"location","dependencies":[]},{"name":"path_provider","dependencies":["path_provider_macos"]},{"name":"path_provider_macos","dependencies":[]},{"name":"shared_preferences","dependencies":["shared_preferences_macos","shared_preferences_web"]},{"name":"shared_preferences_macos","dependencies":[]},{"name":"shared_preferences_web","dependencies":[]},{"name":"sqflite","dependencies":[]}]} \ No newline at end of file diff --git a/lib/bloc/KomentarBloc.dart b/lib/bloc/KomentarBloc.dart index 9232a2d..3878f1f 100644 --- a/lib/bloc/KomentarBloc.dart +++ b/lib/bloc/KomentarBloc.dart @@ -26,7 +26,9 @@ class KomentarBloc { KomentarList komentarListResponse = await _komentarRepository.fetchKomentar(namaLokasi); allKomentarFromApi = List.from(komentarListResponse.allKomentar); + komentarListSink.add(NetworkModel.completed(komentarListResponse)); + print('fetch komentarlist 31'); } catch (e) { komentarListSink.add(NetworkModel.error(e.toString())); print("$e"); diff --git a/lib/globalnetwork.dart b/lib/globalnetwork.dart new file mode 100644 index 0000000..c666772 --- /dev/null +++ b/lib/globalnetwork.dart @@ -0,0 +1,41 @@ +import 'package:dio/dio.dart'; +import 'package:mockito/mockito.dart'; + +class MockHttpClient extends Mock implements Dio {} + +var dio; + +getDioInstance(String env) { + dio = env == 'build' ? Dio() : MockHttpClient(); + print(dio is MockHttpClient); +} + +mockLokasiDependencies() { + when(dio.get( + any, + )).thenAnswer((_) async { + final expected = Future>>>.value( + Response>>(statusCode: 200, data: [ + { + "id": 1, + "name": "Soppeng", + "latitude": 100039203300.0, + "longitude": 100000000000.0, + "alamat": "Jalan Margonda Raya", + "no_telp": "081111111111", + "image": "test.jpg" + } + ])); + return expected; + }); +} + +mockFasilitasDependencies(Map mockFasilitas) { + when(dio.get( + any, + )).thenAnswer((_) async { + final expected = Future>>.value( + Response>(statusCode: 200, data: mockFasilitas)); + return expected; + }); +} diff --git a/lib/main.dart b/lib/main.dart index 419e6c2..227605a 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,8 +1,11 @@ import 'package:flutter/material.dart'; import 'package:ppl_disabilitas/app.dart'; import 'flavor/flavor.dart'; +import 'globalnetwork.dart'; void main() { + getDioInstance('build'); + dio.options.receiveTimeout = 15000; ApiFlavor.flavor = BuildFlavor.production.toString(); runApp(BisaGo()); diff --git a/lib/network/network_interface.dart b/lib/network/network_interface.dart index 38f45b7..9eff5b0 100644 --- a/lib/network/network_interface.dart +++ b/lib/network/network_interface.dart @@ -1,25 +1,21 @@ import 'dart:convert'; +import 'package:dio/dio.dart'; +import 'package:ppl_disabilitas/globalnetwork.dart'; import 'package:ppl_disabilitas/network/CustomException.dart'; -import 'package:http/http.dart' as http; import 'dart:io'; class NetworkInterface { - //String key = KEY; - - // POST request Future post( { String url, //url nya apa dynamic bodyParams, //data apa yang mau dikasih bool isLogin, //dia login apa ngga }) async { var responseJson; - final headersJson = - await _buildRequestHeader(isLogin); //butuh header apa ngga try { - final response = await http.post( + final response = await dio.post( "$url", - body: json.encode(bodyParams), - headers: headersJson, + data: json.encode(bodyParams), + //headers: headersJson, ); responseJson = _response(response); } on SocketException { @@ -34,11 +30,9 @@ class NetworkInterface { bool isLogin, }) async { var responseJson; - final headersJson = await _buildRequestHeader(isLogin); try { - final response = await http.get( + final response = await dio.get( "$url", - headers: headersJson, ); responseJson = _response(response); } on SocketException { @@ -47,46 +41,20 @@ class NetworkInterface { return responseJson; } - // buildRequestHeader: untuk nentuin pake header apa aja berdasarkan login apa ngga - Future> _buildRequestHeader(bool isLogin) async { - Map headers = Map(); - headers.putIfAbsent("Content-Type", () => "application/json"); - //if (isLogin) { - //List cookieFile = await CookiesInterface().getCookieFile( - // fileName: - // "userCookies"); //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; - } - dynamic _response(http.Response response) { + dynamic _response(Response response) { + print('nyari status code ${response.statusCode}'); switch (response.statusCode) { case 200: - final responseJson = json.decode(response.body.toString()); - return responseJson; + return response.data; case 201: - var responseJson = json.decode(response.body.toString()); - return responseJson; + return response.data; case 400: - throw BadRequestException(response.body.toString()); + throw BadRequestException(response.data.toString()); case 401: case 403: - throw UnauthorisedException(response.body.toString()); + throw UnauthorisedException(response.data.toString()); case 500: default: diff --git a/lib/page/filter_fasilitas/fasilitas.dart b/lib/page/filter_fasilitas/fasilitas.dart index 0efeb6c..854f23b 100644 --- a/lib/page/filter_fasilitas/fasilitas.dart +++ b/lib/page/filter_fasilitas/fasilitas.dart @@ -82,6 +82,7 @@ class _FasilitasState extends State { children: [ Icon(Icons.place, color: Colors.black, size: 20), Flexible( + key: Key('Alamat'), child: Text( widget.alamat, softWrap: true, @@ -207,6 +208,7 @@ class _FasilitasState extends State { break; case Status.COMPLETED: allKomentarFromApi = snapshot.data.data.allKomentar; + print('all komentar $allKomentarFromApi'); return Column( children: allKomentarFromApi .map((k) => Komentar( diff --git a/lib/page/filter_fasilitas/postingan/detailpost.dart b/lib/page/filter_fasilitas/postingan/detailpost.dart index ba744d7..f6b0e4b 100644 --- a/lib/page/filter_fasilitas/postingan/detailpost.dart +++ b/lib/page/filter_fasilitas/postingan/detailpost.dart @@ -39,7 +39,7 @@ class _DetailPostPageState extends State { Container( key: Key('desc'), decoration: BoxDecoration( - color: Colors.white, + color: Colors.white, boxShadow: regularShadow, border: Border.all(color: greenPale), borderRadius: regularBorderRadius), @@ -68,7 +68,7 @@ class _DetailPostPageState extends State { ), ), Text( - '${widget.komentar.creator}', + '${widget.komentar.creator}', style: TextStyle(fontSize: 18), key: Key('creator-${widget.komentar.creator}'), ), Text( @@ -88,7 +88,8 @@ class _DetailPostPageState extends State { borderRadius: regularBorderRadius, boxShadow: regularShadow), padding: EdgeInsets.all(smallSpace), - margin: EdgeInsets.symmetric(horizontal: smallSpace), + margin: + EdgeInsets.symmetric(horizontal: smallSpace), child: Row( mainAxisAlignment: MainAxisAlignment.center, children: [ @@ -141,7 +142,7 @@ class _DetailPostPageState extends State { Container( key: Key('rating'), decoration: BoxDecoration( - color: Colors.white, + color: Colors.white, boxShadow: regularShadow, border: Border.all(color: greenPale), borderRadius: regularBorderRadius), @@ -167,7 +168,16 @@ class _DetailPostPageState extends State { ) ], ), - ) + ), + Container( + key: Key('Komentar'), + padding: EdgeInsets.symmetric(vertical: regularSpace), + child: Text( + 'Komentar', + style: TextStyle(fontSize: 20, fontWeight: FontWeight.w800), + )), + komentarPlaceHolder( + 'test', widget.komentar.date_time, 'hard coded komentar') ], ), ), @@ -181,7 +191,7 @@ class _DetailPostPageState extends State { padding: EdgeInsets.all(smallSpace), margin: EdgeInsets.all(smallSpace), decoration: BoxDecoration( - color: Colors.white, + color: Colors.white, borderRadius: regularBorderRadius, border: Border.all(color: greenPale), boxShadow: regularShadow), @@ -192,4 +202,39 @@ class _DetailPostPageState extends State { ), ); } + + komentarPlaceHolder(String nama, DateTime date, String description) { + return Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Row( + mainAxisAlignment: MainAxisAlignment.start, + children: [ + CircleAvatar( + backgroundColor: greenPrimary, + child: Text('Test'), + ), + Padding( + padding: const EdgeInsets.all(regularSpace), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + nama, + style: TextStyle(fontSize: 18), + ), + Text('${DateFormat('dd MMMM yyy hh:mm').format(date)}', + style: TextStyle(color: grayPrimary, fontSize: 16)) + ], + ), + ) + ], + ), + Container( + margin: EdgeInsets.only(bottom: regularSpace), + child: Text(description)), + Divider(color: grayPrimary,) + ], + ); + } } diff --git a/lib/page/login/login.dart b/lib/page/login/login.dart index e79d85b..460d227 100644 --- a/lib/page/login/login.dart +++ b/lib/page/login/login.dart @@ -1,8 +1,10 @@ import 'dart:convert'; +import 'package:dio/dio.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:ppl_disabilitas/config/styles.dart'; +import 'package:ppl_disabilitas/globalnetwork.dart'; import 'package:ppl_disabilitas/page/registrasi/registrasi.dart'; import 'package:ppl_disabilitas/utils/customButton.dart'; import 'package:ppl_disabilitas/utils/customTextField.dart'; @@ -141,6 +143,9 @@ class LoginState extends State { setState(() { sharedPreferences.setString("token", tokenMap['token']); sharedPreferences.setString("email", email); + dio.interceptors.add(InterceptorsWrapper(onRequest: (RequestOptions options) async { + options.headers['Authorization'] = 'Token ${tokenMap['token']}'; + })); Navigator.pushNamed(context, '/'); }); } diff --git a/lib/repository/KomentarRepository.dart b/lib/repository/KomentarRepository.dart index 27afdfc..dfd4837 100644 --- a/lib/repository/KomentarRepository.dart +++ b/lib/repository/KomentarRepository.dart @@ -5,7 +5,7 @@ class KomentarRepository { Future fetchKomentar(String namaLokasi) async { String nama = namaLokasi.replaceAll(" ", "%20"); - String url = "http://poipole-staging.herokuapp.com/informasi-fasilitas/lokasi/list-fasilitas/" + nama; + String url = "https://poipole-staging.herokuapp.com/informasi-fasilitas/lokasi/list-fasilitas/" + nama; print("in Repo"); print(url); final response = await _network.get( diff --git a/lib/repository/LokasiRepository.dart b/lib/repository/LokasiRepository.dart index 9313d53..fb7c7d8 100644 --- a/lib/repository/LokasiRepository.dart +++ b/lib/repository/LokasiRepository.dart @@ -8,10 +8,12 @@ class LokasiRepository { final _network = NetworkInterface(); final _cookie = CookiesInterface(); Future fetchLokasi() async { + print('sampe sini 11'); final response = await _network.get( url: - 'http://poipole-staging.herokuapp.com/informasi-fasilitas/lokasi/list/', + 'https://poipole-staging.herokuapp.com/informasi-fasilitas/lokasi/list/', isLogin: false); + return LokasiListResponse( response.map((lokasi) => Lokasi.fromJson(lokasi)).toList()); } diff --git a/pubspec.yaml b/pubspec.yaml index 3dd87f7..9454a72 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -35,6 +35,7 @@ dependencies: smooth_star_rating: ^1.0.4+2 image_picker: ^0.6.5 font_awesome_flutter: ^8.8.1 + dio: ^3.0.9 dev_dependencies: flutter_test: diff --git a/test/detail_post_test.dart b/test/detail_post_test.dart index 9c3c576..c66ec4b 100644 --- a/test/detail_post_test.dart +++ b/test/detail_post_test.dart @@ -36,6 +36,7 @@ void main() { expect(find.byKey(Key('like')), findsOneWidget); expect(find.byKey(Key('dislike')), findsOneWidget); expect(find.byKey(Key('rating')), findsOneWidget); + expect(find.byKey(Key('Komentar')), findsOneWidget); }); testWidgets('Detail post negative test', (WidgetTester tester) async { @@ -43,6 +44,7 @@ void main() { await tester.pumpWidget(buildTestableWidget(detailPostPage)); expect(find.byKey(Key('appbar-text')), findsNothing); expect(find.byKey(Key('creator')), findsNothing); + expect(find.byKey(Key('komentar')), findsNothing); }); test('Should decrypt tag code', () { diff --git a/test/fasilitas_test.dart b/test/fasilitas_test.dart index 150baa7..55d4f98 100644 --- a/test/fasilitas_test.dart +++ b/test/fasilitas_test.dart @@ -5,18 +5,39 @@ // gestures. You can also use WidgetTester to find child widgets in the widget // tree, read text, and verify that the values of widget properties are correct. - import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; +import 'package:ppl_disabilitas/globalnetwork.dart'; import 'package:ppl_disabilitas/page/filter_fasilitas/fasilitas.dart'; void main() { + final mockFasilitas = { + "2": { + "id": 2, + "nama_lokasi": "Margo City", + "deskripsi": + "Ada toilet khusus disabilitas terletak di lantai 2 dekat kintan, kondisinya bagus dan bersih layak pakai.\r\n\r\nAda kursi roda juga di customer service lantai dasar, saya tidak ingat jumlahnya ada berapa, tapi ada lumayan banyak.", + "creator": "", + "date_time": "2020-04-12T14:33:54.442Z", + "like": 20, + "dislike": 1, + "rating": 3, + "tag": ["KR", "TD"], + "image": "static/img/2669211407.jpg", + "is_verified": false + } + }; Widget buildTestableWidget(Widget widget) { // https://docs.flutter.io/flutter/widgets/MediaQuery-class.html return MediaQuery(data: MediaQueryData(), child: MaterialApp(home: widget)); } + setUp(() { + getDioInstance('test'); + mockFasilitasDependencies(mockFasilitas); + }); + testWidgets('find inside filter page', (WidgetTester tester) async { // Provide the childWidget to the Container. await tester.pumpWidget(buildTestableWidget(Fasilitas( @@ -51,17 +72,12 @@ void main() { telpon: '9217424', url: 'afalklksafn', ))); - // Search for the childWidget in the tree and verify it exists. - expect(find.byType(Scaffold), findsOneWidget); - expect(find.byType(Container), findsNWidgets(10)); - expect(find.byType(Icon), findsNWidgets(4)); - expect(find.byType(Column), findsNWidgets(2)); - expect(find.byType(Row), findsNWidgets(5)); - expect(find.byType(Text), findsNWidgets(7)); - expect(find.byType(Flexible), findsNWidgets(2)); - expect(find.byType(FlatButton), findsNWidgets(2)); - await tester.tap(find.byKey(Key('Tambah Informasi'))); + expect(find.text('9217424'), findsOneWidget); + expect(find.text('Ya'), findsOneWidget); + expect(find.text('Itu'), findsOneWidget); + await tester.pump(); + expect(find.text(mockFasilitas['2']['deskripsi']), findsOneWidget); + await tester.tap(find.byKey(Key('Alamat'))); await tester.pump(); }); - } -- GitLab From b3da29dcd533907b030fb7528827a336a5f7a3a7 Mon Sep 17 00:00:00 2001 From: Fakhira Date: Sat, 2 May 2020 23:49:26 +0700 Subject: [PATCH 05/13] [GREEN] change tests in fasilitas --- lib/bloc/KomentarBloc.dart | 1 - lib/globalnetwork.dart | 1 - lib/network/network_interface.dart | 1 - lib/page/filter_fasilitas/fasilitas.dart | 20 +++++++++++++++++++- lib/repository/KomentarRepository.dart | 2 -- lib/repository/LokasiRepository.dart | 1 - test/fasilitas_test.dart | 15 ++++----------- 7 files changed, 23 insertions(+), 18 deletions(-) diff --git a/lib/bloc/KomentarBloc.dart b/lib/bloc/KomentarBloc.dart index 3878f1f..0e98647 100644 --- a/lib/bloc/KomentarBloc.dart +++ b/lib/bloc/KomentarBloc.dart @@ -28,7 +28,6 @@ class KomentarBloc { allKomentarFromApi = List.from(komentarListResponse.allKomentar); komentarListSink.add(NetworkModel.completed(komentarListResponse)); - print('fetch komentarlist 31'); } catch (e) { komentarListSink.add(NetworkModel.error(e.toString())); print("$e"); diff --git a/lib/globalnetwork.dart b/lib/globalnetwork.dart index c666772..b2e7312 100644 --- a/lib/globalnetwork.dart +++ b/lib/globalnetwork.dart @@ -7,7 +7,6 @@ var dio; getDioInstance(String env) { dio = env == 'build' ? Dio() : MockHttpClient(); - print(dio is MockHttpClient); } mockLokasiDependencies() { diff --git a/lib/network/network_interface.dart b/lib/network/network_interface.dart index 9eff5b0..e1e2393 100644 --- a/lib/network/network_interface.dart +++ b/lib/network/network_interface.dart @@ -43,7 +43,6 @@ class NetworkInterface { dynamic _response(Response response) { - print('nyari status code ${response.statusCode}'); switch (response.statusCode) { case 200: return response.data; diff --git a/lib/page/filter_fasilitas/fasilitas.dart b/lib/page/filter_fasilitas/fasilitas.dart index 854f23b..2502e20 100644 --- a/lib/page/filter_fasilitas/fasilitas.dart +++ b/lib/page/filter_fasilitas/fasilitas.dart @@ -208,7 +208,6 @@ class _FasilitasState extends State { break; case Status.COMPLETED: allKomentarFromApi = snapshot.data.data.allKomentar; - print('all komentar $allKomentarFromApi'); return Column( children: allKomentarFromApi .map((k) => Komentar( @@ -298,6 +297,8 @@ class _FasilitasState extends State { child: ListView( children: [ InkWell( + + key: Key('Urutan'), child: Container( decoration: BoxDecoration( color: greenPale, @@ -328,6 +329,7 @@ class _FasilitasState extends State { )), ), InkWell( + key: Key('Jenis Fasilitas'), child: Container( decoration: BoxDecoration( color: greenPale, @@ -377,6 +379,7 @@ class _FasilitasState extends State { child: ListView( children: [ Row( + key: Key('Komentar Terbaru'), crossAxisAlignment: CrossAxisAlignment.center, children: [ Theme( @@ -405,6 +408,7 @@ class _FasilitasState extends State { ], ), Row( + key: Key('Komentar Terpopuler'), crossAxisAlignment: CrossAxisAlignment.center, children: [ Theme( @@ -433,6 +437,7 @@ class _FasilitasState extends State { ], ), Container( + key: Key('Komentar dengan Rating Tertinggi'), child: Row( crossAxisAlignment: CrossAxisAlignment.center, @@ -476,6 +481,7 @@ class _FasilitasState extends State { child: ListView( children: [ Row( + key: Key('Kursi Roda'), crossAxisAlignment: CrossAxisAlignment.center, children: [ @@ -504,6 +510,7 @@ class _FasilitasState extends State { ], ), Row( + key: Key('Lift'), crossAxisAlignment: CrossAxisAlignment.center, children: [ @@ -532,6 +539,7 @@ class _FasilitasState extends State { ], ), Row( + key: Key('Toilet Disabilitas'), crossAxisAlignment: CrossAxisAlignment.center, children: [ @@ -560,6 +568,7 @@ class _FasilitasState extends State { ], ), Row( + key: Key('Tempat Ibadah'), crossAxisAlignment: CrossAxisAlignment.center, children: [ @@ -588,6 +597,7 @@ class _FasilitasState extends State { ], ), Row( + key: Key('Guiding Block'), crossAxisAlignment: CrossAxisAlignment.center, children: [ @@ -616,6 +626,7 @@ class _FasilitasState extends State { ], ), Row( + key: Key('Bidang Miring (Ramp)'), crossAxisAlignment: CrossAxisAlignment.center, children: [ @@ -644,6 +655,7 @@ class _FasilitasState extends State { ], ), Row( + key: Key('Teman Disabilitas'), crossAxisAlignment: CrossAxisAlignment.center, children: [ @@ -672,6 +684,7 @@ class _FasilitasState extends State { ], ), Row( + key: Key('Juru Bahasa Isyarat'), crossAxisAlignment: CrossAxisAlignment.center, children: [ @@ -699,6 +712,7 @@ class _FasilitasState extends State { ), ], ),Row( + key: Key("Tongkat Disabilitas Netra"), crossAxisAlignment: CrossAxisAlignment.center, children: [ @@ -727,6 +741,7 @@ class _FasilitasState extends State { ], ), Row( + key: Key("Kursi Umum Disabilitas"), crossAxisAlignment: CrossAxisAlignment.center, children: [ @@ -755,6 +770,7 @@ class _FasilitasState extends State { ], ), Row( + key: Key("Parkir Umum"), crossAxisAlignment: CrossAxisAlignment.center, children: [ @@ -783,6 +799,7 @@ class _FasilitasState extends State { ], ), Row( + key: Key('Tempat Ibadah'), crossAxisAlignment: CrossAxisAlignment.center, children: [ @@ -811,6 +828,7 @@ class _FasilitasState extends State { ], ), Row( + key: Key('Parkir Disabilitas'), crossAxisAlignment: CrossAxisAlignment.center, children: [ diff --git a/lib/repository/KomentarRepository.dart b/lib/repository/KomentarRepository.dart index dfd4837..7b84603 100644 --- a/lib/repository/KomentarRepository.dart +++ b/lib/repository/KomentarRepository.dart @@ -6,8 +6,6 @@ class KomentarRepository { Future fetchKomentar(String namaLokasi) async { String nama = namaLokasi.replaceAll(" ", "%20"); String url = "https://poipole-staging.herokuapp.com/informasi-fasilitas/lokasi/list-fasilitas/" + nama; - print("in Repo"); - print(url); final response = await _network.get( url: url, isLogin: false); diff --git a/lib/repository/LokasiRepository.dart b/lib/repository/LokasiRepository.dart index fb7c7d8..9b48857 100644 --- a/lib/repository/LokasiRepository.dart +++ b/lib/repository/LokasiRepository.dart @@ -8,7 +8,6 @@ class LokasiRepository { final _network = NetworkInterface(); final _cookie = CookiesInterface(); Future fetchLokasi() async { - print('sampe sini 11'); final response = await _network.get( url: 'https://poipole-staging.herokuapp.com/informasi-fasilitas/lokasi/list/', diff --git a/test/fasilitas_test.dart b/test/fasilitas_test.dart index 55d4f98..b7ae3cc 100644 --- a/test/fasilitas_test.dart +++ b/test/fasilitas_test.dart @@ -49,18 +49,9 @@ void main() { await tester.tap(find.byKey(Key('FilterButton'))); await tester.pump(Duration(seconds: 1)); // inside filter - expect(find.byType(Container), findsNWidgets(24)); - expect(find.byType(Row), findsNWidgets(16)); - expect(find.byType(Column), findsNWidgets(4)); - expect(find.byType(Text), findsNWidgets(20)); - expect(find.byType(Flex), findsNothing); - expect(find.text('jns fasilitas'), findsNothing); - expect(find.text('urutn'), findsNothing); - expect(find.text('hps smw'), findsNothing); + expect(find.byKey(Key('Urutan')), findsOneWidget); // filter - expect(find.byType(Scaffold), findsOneWidget); - expect(find.byType(Icon), findsNWidgets(5)); - await tester.tap(find.byKey(Key('Tambah Informasi'))); + await tester.tap(find.byKey(Key('Alamat'))); await tester.pump(); }); @@ -79,5 +70,7 @@ void main() { expect(find.text(mockFasilitas['2']['deskripsi']), findsOneWidget); await tester.tap(find.byKey(Key('Alamat'))); await tester.pump(); + await tester.pump(); + await tester.pump(); }); } -- GitLab From 34fd2d7bdc6432aeb77b4cfb26cb70744bb53b56 Mon Sep 17 00:00:00 2001 From: Firriyal Bin Yahya Date: Sun, 3 May 2020 01:02:15 +0700 Subject: [PATCH 06/13] [CHORE] sudah muncul list sekolah nya --- lib/page/informasi/list_sekolah.dart | 124 ++++++++++++-------------- lib/repository/SekolahRepository.dart | 1 + 2 files changed, 59 insertions(+), 66 deletions(-) diff --git a/lib/page/informasi/list_sekolah.dart b/lib/page/informasi/list_sekolah.dart index 7d066b8..175035c 100644 --- a/lib/page/informasi/list_sekolah.dart +++ b/lib/page/informasi/list_sekolah.dart @@ -1,12 +1,12 @@ -import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; +import 'package:ppl_disabilitas/bloc/SekolahBloc.dart'; import 'package:ppl_disabilitas/component/bisago_drawer.dart'; import 'package:flutter/widgets.dart'; import 'package:ppl_disabilitas/config/styles.dart'; -import 'package:ppl_disabilitas/page/informasi/detailSekolah.dart'; -import 'package:ppl_disabilitas/bloc/SekolahBloc.dart'; +import 'package:ppl_disabilitas/model/lokasi.dart'; import 'package:ppl_disabilitas/model/sekolah.dart'; import 'package:ppl_disabilitas/network/data/network_model.dart'; +import 'package:ppl_disabilitas/page/informasi/detailSekolah.dart'; class ListSekolah extends StatefulWidget { @override @@ -28,14 +28,6 @@ class _ListSekolahState extends State { /// BLoC for sekolah SekolahBloc _bloc = SekolahBloc(); - @override - void debugFillProperties(DiagnosticPropertiesBuilder properties) { - super.debugFillProperties(properties); - properties - ..add(DiagnosticsProperty('sekolah', sekolah)); - } - - @override Widget build(BuildContext context) { return Scaffold( @@ -104,9 +96,7 @@ class _ListSekolahState extends State { break; case Status.COMPLETED: sekolah = snapshot.data.data.allSekolah; - return Expanded( - flex: 2, - child: makeLokasiWidget("sekolah", sekolah)); + return makeLokasiWidget("api", sekolah); break; case Status.ERROR: return Center( @@ -169,6 +159,7 @@ class _ListSekolahState extends State { mainAxisSize: MainAxisSize.max, mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ + FlatButton( onPressed: () { _navigateToDetailSekolahPage(context); @@ -227,6 +218,7 @@ class _ListSekolahState extends State { ), ); }); + } InsideFilter() { @@ -237,7 +229,7 @@ class _ListSekolahState extends State { boxShadow: regularShadow, borderRadius: BorderRadius.all( Radius.circular(10) // <--- border radius here - ), + ), color: Colors.white, ), child: Container( @@ -316,19 +308,19 @@ class _ListSekolahState extends State { splashColor: Colors.green[400], highlightColor: Colors.green[400], onTap: () => setStateModal(() { - print('no'); - showProvinsi = true; - showKota = false; - showKecamatan = false; - showKategoriSekolah = false; - showTingkatSekolah = false; - })), + print('no'); + showProvinsi = true; + showKota = false; + showKecamatan = false; + showKategoriSekolah = false; + showTingkatSekolah = false; + })), Container( decoration: BoxDecoration( border: Border( - top: BorderSide( - color: greenPrimary, width: 1.5), - )), + top: BorderSide( + color: greenPrimary, width: 1.5), + )), ), InkWell( child: Container( @@ -352,13 +344,13 @@ class _ListSekolahState extends State { splashColor: Colors.green[400], highlightColor: Colors.green[400], onTap: () => setStateModal(() { - print("yes"); - showProvinsi = false; - showKota = true; - showKecamatan = false; - showKategoriSekolah = false; - showTingkatSekolah = false; - })), + print("yes"); + showProvinsi = false; + showKota = true; + showKecamatan = false; + showKategoriSekolah = false; + showTingkatSekolah = false; + })), Container( decoration: BoxDecoration( border: Border( @@ -387,13 +379,13 @@ class _ListSekolahState extends State { splashColor: Colors.green[400], highlightColor: Colors.green[400], onTap: () => setStateModal(() { - print("yes"); - showProvinsi = false; - showKota = false; - showKecamatan = true; - showKategoriSekolah = false; - showTingkatSekolah = false; - })), + print("yes"); + showProvinsi = false; + showKota = false; + showKecamatan = true; + showKategoriSekolah = false; + showTingkatSekolah = false; + })), Container( decoration: BoxDecoration( border: Border( @@ -422,13 +414,13 @@ class _ListSekolahState extends State { splashColor: Colors.green[400], highlightColor: Colors.green[400], onTap: () => setStateModal(() { - print("yes"); - showProvinsi = false; - showKota = false; - showKecamatan = false; - showKategoriSekolah = true; - showTingkatSekolah = false; - })), + print("yes"); + showProvinsi = false; + showKota = false; + showKecamatan = false; + showKategoriSekolah = true; + showTingkatSekolah = false; + })), Container( decoration: BoxDecoration( border: Border( @@ -457,13 +449,13 @@ class _ListSekolahState extends State { splashColor: Colors.green[400], highlightColor: Colors.green[400], onTap: () => setStateModal(() { - print("yes"); - showProvinsi = false; - showKota = false; - showKecamatan = false; - showKategoriSekolah = false; - showTingkatSekolah = true; - })), + print("yes"); + showProvinsi = false; + showKota = false; + showKecamatan = false; + showKategoriSekolah = false; + showTingkatSekolah = true; + })), Container( decoration: BoxDecoration( border: Border( @@ -491,7 +483,7 @@ class _ListSekolahState extends State { children: [ Row( crossAxisAlignment: - CrossAxisAlignment.center, + CrossAxisAlignment.center, children: [ Theme( data: Theme.of(context).copyWith( @@ -518,7 +510,7 @@ class _ListSekolahState extends State { ), Row( crossAxisAlignment: - CrossAxisAlignment.center, + CrossAxisAlignment.center, children: [ Theme( data: Theme.of(context).copyWith( @@ -552,7 +544,7 @@ class _ListSekolahState extends State { children: [ Row( crossAxisAlignment: - CrossAxisAlignment.center, + CrossAxisAlignment.center, children: [ Theme( data: Theme.of(context).copyWith( @@ -579,7 +571,7 @@ class _ListSekolahState extends State { ), Row( crossAxisAlignment: - CrossAxisAlignment.center, + CrossAxisAlignment.center, children: [ Theme( data: Theme.of(context).copyWith( @@ -613,7 +605,7 @@ class _ListSekolahState extends State { children: [ Row( crossAxisAlignment: - CrossAxisAlignment.center, + CrossAxisAlignment.center, children: [ Theme( data: Theme.of(context).copyWith( @@ -640,7 +632,7 @@ class _ListSekolahState extends State { ), Row( crossAxisAlignment: - CrossAxisAlignment.center, + CrossAxisAlignment.center, children: [ Theme( data: Theme.of(context).copyWith( @@ -674,7 +666,7 @@ class _ListSekolahState extends State { children: [ Row( crossAxisAlignment: - CrossAxisAlignment.center, + CrossAxisAlignment.center, children: [ Theme( data: Theme.of(context).copyWith( @@ -701,7 +693,7 @@ class _ListSekolahState extends State { ), Row( crossAxisAlignment: - CrossAxisAlignment.center, + CrossAxisAlignment.center, children: [ Theme( data: Theme.of(context).copyWith( @@ -735,7 +727,7 @@ class _ListSekolahState extends State { children: [ Row( crossAxisAlignment: - CrossAxisAlignment.center, + CrossAxisAlignment.center, children: [ Theme( data: Theme.of(context).copyWith( @@ -762,7 +754,7 @@ class _ListSekolahState extends State { ), Row( crossAxisAlignment: - CrossAxisAlignment.center, + CrossAxisAlignment.center, children: [ Theme( data: Theme.of(context).copyWith( @@ -803,12 +795,12 @@ class _ListSekolahState extends State { Container( decoration: BoxDecoration( border: Border( - top: BorderSide(color: greenPrimary, width: 1.5), - )), + top: BorderSide(color: greenPrimary, width: 1.5), + )), ), Container( margin: - EdgeInsets.only(left: doubleSpace, right: doubleSpace), + EdgeInsets.only(left: doubleSpace, right: doubleSpace), child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ diff --git a/lib/repository/SekolahRepository.dart b/lib/repository/SekolahRepository.dart index bda7b06..2fb2ec4 100644 --- a/lib/repository/SekolahRepository.dart +++ b/lib/repository/SekolahRepository.dart @@ -9,6 +9,7 @@ class SekolahRepository { url: 'http://poipole-staging.herokuapp.com/layanan-khusus/sekolah/list/', isLogin: false); print(response); + print("hai"); return SekolahList( response.map((sekolah) => SekolahModel.fromJson(sekolah)).toList()); } -- GitLab From d88dee1207a7cb8c9ff5e8738cb455d90868fd94 Mon Sep 17 00:00:00 2001 From: Fakhira Date: Sun, 3 May 2020 10:16:54 +0700 Subject: [PATCH 07/13] [GREEN] add more test --- lib/page/filter_fasilitas/fasilitas.dart | 4 ++-- test/fasilitas_test.dart | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/lib/page/filter_fasilitas/fasilitas.dart b/lib/page/filter_fasilitas/fasilitas.dart index 2502e20..c58c381 100644 --- a/lib/page/filter_fasilitas/fasilitas.dart +++ b/lib/page/filter_fasilitas/fasilitas.dart @@ -799,7 +799,7 @@ class _FasilitasState extends State { ], ), Row( - key: Key('Tempat Ibadah'), + key: Key('Running Text'), crossAxisAlignment: CrossAxisAlignment.center, children: [ @@ -821,7 +821,7 @@ class _FasilitasState extends State { ), ), Text( - "Tempat Ibadah", + "Running Text", style: TextStyle( color: Colors.black, fontSize: 18), ), diff --git a/test/fasilitas_test.dart b/test/fasilitas_test.dart index b7ae3cc..d6cb775 100644 --- a/test/fasilitas_test.dart +++ b/test/fasilitas_test.dart @@ -50,6 +50,24 @@ void main() { await tester.pump(Duration(seconds: 1)); // inside filter expect(find.byKey(Key('Urutan')), findsOneWidget); + expect(find.byKey(Key('Jenis Fasilitas')), findsOneWidget); + expect(find.byKey(Key('Komentar Terbaru')), findsOneWidget); + expect(find.byKey(Key('Komentar Terpopuler')), findsOneWidget); + expect(find.byKey(Key('Komentar dengan Rating Tertinggi')), findsOneWidget); + expect(find.byKey(Key('Kursi Roda')), findsOneWidget); + expect(find.byKey(Key('Lift')), findsOneWidget); + expect(find.byKey(Key('Toilet Disabilitas')), findsOneWidget); + expect(find.byKey(Key('Tempat Ibadah')), findsOneWidget); + await tester.drag(find.byKey(Key('Tempat Ibadah')), Offset(0,-200)); + await tester.pump(); + // expect(find.byKey(Key('Guiding Block')), findsOneWidget); + //expect(find.byKey(Key('Bidang Miring (Ramp)')), findsOneWidget); + //expect(find.byKey(Key('Juru Bahasa Isyarat')), findsOneWidget); + //expect(find.byKey(Key('Tongkat Disabilitas Netra')), findsOneWidget); + //expect(find.byKey(Key('Kursi Umum Disabilitas')), findsOneWidget); + //expect(find.byKey(Key('Parkir Umum')), findsOneWidget); + //expect(find.byKey(Key('Runing Text')), findsOneWidget); + //expect(find.byKey(Key('Parkir Disabilitas')), findsOneWidget); // filter await tester.tap(find.byKey(Key('Alamat'))); await tester.pump(); -- GitLab From 445da7fc872c2990cda6e4920f0852bda059d26b Mon Sep 17 00:00:00 2001 From: Fakhira Date: Sun, 3 May 2020 10:29:14 +0700 Subject: [PATCH 08/13] [CHORE] fix overflowing widget on list sekolah --- lib/page/informasi/list_sekolah.dart | 77 ++++++++++++---------------- 1 file changed, 33 insertions(+), 44 deletions(-) diff --git a/lib/page/informasi/list_sekolah.dart b/lib/page/informasi/list_sekolah.dart index 175035c..06b255f 100644 --- a/lib/page/informasi/list_sekolah.dart +++ b/lib/page/informasi/list_sekolah.dart @@ -148,7 +148,7 @@ class _ListSekolahState extends State { itemBuilder: (context, index) { return InkWell( key: Key("$key-${sekolah[index].name}"), - onTap: () {}, + onTap: () {_navigateToDetailSekolahPage(context);}, child: Container( decoration: BoxDecoration( color: Colors.transparent, @@ -160,52 +160,41 @@ class _ListSekolahState extends State { mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ - FlatButton( - onPressed: () { - _navigateToDetailSekolahPage(context); - }, - child: Row( - children: [ - CircleAvatar( - backgroundColor: greenPrimary, - child: Text('Test'), - ), - Container( - padding: EdgeInsets.all(doubleSpace), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Flexible( - child: Text( - sekolah[index].name, - softWrap: true, - textAlign: TextAlign.left, - style: TextStyle( - fontSize: 18, - fontWeight: FontWeight.w800, - color: Colors.black, - fontFamily: 'Muli', - ), - ), + CircleAvatar( + backgroundColor: greenPrimary, + child: Text('Test'), + ), + Expanded( + child: Container( + padding: EdgeInsets.all(doubleSpace), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Text( + sekolah[index].name, + overflow: TextOverflow.ellipsis, + textAlign: TextAlign.left, + style: TextStyle( + fontSize: 18, + fontWeight: FontWeight.w800, + color: Colors.black, + fontFamily: 'Muli', ), - Flexible( - child: Text( - sekolah[index].alamat, - softWrap: true, - textAlign: TextAlign.left, - style: TextStyle( - fontSize: 15, - color: Colors.black, - fontFamily: 'Muli', - ), - ), + ), + Text( + sekolah[index].alamat, + overflow: TextOverflow.ellipsis, + textAlign: TextAlign.left, + style: TextStyle( + fontSize: 15, + color: Colors.black, + fontFamily: 'Muli', ), - ], - ), - ), - ], + ), + ], + ), ), ), Icon( -- GitLab From 4affeaf70f3e80c723629b1883305d76fb35f9e6 Mon Sep 17 00:00:00 2001 From: Fakhira Date: Sun, 3 May 2020 16:15:21 +0700 Subject: [PATCH 09/13] [CHORE] filter in list sekolah --- lib/bloc/SekolahBloc.dart | 52 ++- lib/page/informasi/list_sekolah.dart | 649 +++++++++------------------ test/list_sekolah_test.dart | 10 +- 3 files changed, 268 insertions(+), 443 deletions(-) diff --git a/lib/bloc/SekolahBloc.dart b/lib/bloc/SekolahBloc.dart index 8f57fc1..423a78f 100644 --- a/lib/bloc/SekolahBloc.dart +++ b/lib/bloc/SekolahBloc.dart @@ -7,6 +7,7 @@ import 'package:ppl_disabilitas/repository/SekolahRepository.dart'; class SekolahBloc { SekolahRepository _sekolahRepository; StreamController _sekolahListController; + List allSekolahFromApi; StreamSink> get sekolahListSink => _sekolahListController.sink; @@ -22,8 +23,8 @@ class SekolahBloc { fetchSekolahList() async { sekolahListSink.add(NetworkModel.loading('Getting Sekolah')); try { - SekolahList sekolahListResponse = - await _sekolahRepository.fetchSekolah(); + SekolahList sekolahListResponse = await _sekolahRepository.fetchSekolah(); + allSekolahFromApi = List.from(sekolahListResponse.allSekolah); sekolahListSink.add(NetworkModel.completed(sekolahListResponse)); } catch (e) { sekolahListSink.add(NetworkModel.error(e.toString())); @@ -31,7 +32,52 @@ class SekolahBloc { } } + filterbyKecamatan( + String kecamatan, bool value, List currentList) { + if (value) { + for (var sekolah in allSekolahFromApi) { + if (sekolah.alamat.toLowerCase().contains(kecamatan.toLowerCase())) { + currentList.add(sekolah); + } + } + } else { + currentList.removeWhere((sekolah) => + sekolah.alamat.toLowerCase().contains(kecamatan.toLowerCase())); + } + sekolahListSink.add(NetworkModel.completed(SekolahList(currentList))); + } + + filterbyKategoriSekolah( + String kategori, bool val, List currentList) { + if (val) { + for (var sekolah in allSekolahFromApi) { + if (sekolah.jenis_sekolah.contains(kategori)) { + currentList.add(sekolah); + } + } + } else { + currentList.removeWhere((sekolah) => + sekolah.jenis_sekolah.contains(kategori)); + } + sekolahListSink.add(NetworkModel.completed(SekolahList(currentList))); + } + + filterbyTingkatSekolah( + String tingkatSekolah, bool val, List currentList) { + if (val) { + for (var sekolah in allSekolahFromApi) { + if (sekolah.name.toLowerCase().startsWith(tingkatSekolah.toLowerCase())) { + currentList.add(sekolah); + } + } + } else { + currentList.removeWhere((sekolah) => + sekolah.name.toLowerCase().startsWith(tingkatSekolah.toLowerCase())); + } + sekolahListSink.add(NetworkModel.completed(SekolahList(currentList))); + } + dispose() { _sekolahListController?.close(); } -} \ No newline at end of file +} diff --git a/lib/page/informasi/list_sekolah.dart b/lib/page/informasi/list_sekolah.dart index 06b255f..3acd431 100644 --- a/lib/page/informasi/list_sekolah.dart +++ b/lib/page/informasi/list_sekolah.dart @@ -3,7 +3,6 @@ import 'package:ppl_disabilitas/bloc/SekolahBloc.dart'; import 'package:ppl_disabilitas/component/bisago_drawer.dart'; import 'package:flutter/widgets.dart'; import 'package:ppl_disabilitas/config/styles.dart'; -import 'package:ppl_disabilitas/model/lokasi.dart'; import 'package:ppl_disabilitas/model/sekolah.dart'; import 'package:ppl_disabilitas/network/data/network_model.dart'; import 'package:ppl_disabilitas/page/informasi/detailSekolah.dart'; @@ -17,17 +16,66 @@ class _ListSekolahState extends State { var jawaTengah = false; var inklusi = false; var luarBiasa = false; - var showProvinsi = true; - var showKota = false; - var showKecamatan = false; + var showKecamatan = true; var showKategoriSekolah = false; var showTingkatSekolah = false; - + List kecamatan = [ + 'Beji', + 'Bojongsari', + 'Cilodong', + 'Cimanggis', + 'Cinere', + 'Cipayung', + 'Limo', + 'Pancoran Mas', + 'Sawangan', + 'Sukmajaya', + 'Tapos', + 'Jagakarsa' + ]; + Map kecamatanValues = { + 'Beji': true, + 'Bojongsari': true, + 'Cilodong': true, + 'Cimanggis': true, + 'Cinere': true, + 'Cipayung': true, + 'Limo': true, + 'Pancoran Mas': true, + 'Sawangan': true, + 'Sukmajaya': true, + 'Tapos': true, + 'Jagakarsa': true + }; + List tingkatSekolah = [ + 'SD', + 'SMP/SLTP', + 'SMA/SLTA', + 'Perguruan Tinggi', + ]; + Map tingkatSekolahValues = { + 'SD': true, + 'SMP/SLTP': true, + 'SMA/SLTA': true, + 'Perguruan Tinggi': true, + }; + List kategoriSekolah = [ + 'Inklusi', + 'Luar Biasa' + ]; + Map kategoriSekolahValues = { + 'Inklusi': true, + 'Luar Biasa': true + }; List sekolah = []; /// BLoC for sekolah SekolahBloc _bloc = SekolahBloc(); +@override + void initState() { + super.initState(); + } @override Widget build(BuildContext context) { return Scaffold( @@ -39,7 +87,8 @@ class _ListSekolahState extends State { children: [ Container( child: Padding( - padding: EdgeInsets.only(top: tripleSpace, left: doubleSpace, right: doubleSpace), + padding: EdgeInsets.only( + top: tripleSpace, left: doubleSpace, right: doubleSpace), child: Text( "Sekolah dengan Dukungan Disabilitas", style: TextStyle( @@ -64,11 +113,12 @@ class _ListSekolahState extends State { borderRadius: regularBorderRadius, side: BorderSide(color: Colors.transparent)), splashColor: Colors.lightGreen, - onPressed: () => {showModalBottomSheet( - context: context, - builder: (context) => InsideFilter(), - backgroundColor: Colors.transparent, - isScrollControlled: true), + onPressed: () => { + showModalBottomSheet( + context: context, + builder: (context) => InsideFilter(), + backgroundColor: Colors.transparent, + isScrollControlled: true), }, child: Row( mainAxisSize: MainAxisSize.min, @@ -90,7 +140,8 @@ class _ListSekolahState extends State { case Status.LOADING: return Center( child: CircularProgressIndicator( - valueColor: AlwaysStoppedAnimation(greenPrimary), + valueColor: + AlwaysStoppedAnimation(greenPrimary), ), ); break; @@ -140,15 +191,16 @@ class _ListSekolahState extends State { ); } - Widget makeLokasiWidget( - String key, List sekolah) { + Widget makeLokasiWidget(String key, List sekolah) { return ListView.builder( shrinkWrap: true, itemCount: sekolah.length, itemBuilder: (context, index) { return InkWell( key: Key("$key-${sekolah[index].name}"), - onTap: () {_navigateToDetailSekolahPage(context);}, + onTap: () { + _navigateToDetailSekolahPage(context); + }, child: Container( decoration: BoxDecoration( color: Colors.transparent, @@ -159,7 +211,6 @@ class _ListSekolahState extends State { mainAxisSize: MainAxisSize.max, mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ - CircleAvatar( backgroundColor: greenPrimary, child: Text('Test'), @@ -171,28 +222,27 @@ class _ListSekolahState extends State { crossAxisAlignment: CrossAxisAlignment.start, mainAxisAlignment: MainAxisAlignment.center, children: [ - Text( - sekolah[index].name, - overflow: TextOverflow.ellipsis, - textAlign: TextAlign.left, - style: TextStyle( - fontSize: 18, - fontWeight: FontWeight.w800, - color: Colors.black, - fontFamily: 'Muli', - ), + Text( + sekolah[index].name, + overflow: TextOverflow.ellipsis, + textAlign: TextAlign.left, + style: TextStyle( + fontSize: 18, + fontWeight: FontWeight.w800, + color: Colors.black, + fontFamily: 'Muli', ), + ), Text( - sekolah[index].alamat, - overflow: TextOverflow.ellipsis, - textAlign: TextAlign.left, - style: TextStyle( - fontSize: 15, - color: Colors.black, - fontFamily: 'Muli', - ), + sekolah[index].alamat, + overflow: TextOverflow.ellipsis, + textAlign: TextAlign.left, + style: TextStyle( + fontSize: 15, + color: Colors.black, + fontFamily: 'Muli', ), - + ), ], ), ), @@ -207,7 +257,6 @@ class _ListSekolahState extends State { ), ); }); - } InsideFilter() { @@ -218,7 +267,7 @@ class _ListSekolahState extends State { boxShadow: regularShadow, borderRadius: BorderRadius.all( Radius.circular(10) // <--- border radius here - ), + ), color: Colors.white, ), child: Container( @@ -275,77 +324,6 @@ class _ListSekolahState extends State { ), child: ListView( children: [ - InkWell( - child: Container( - decoration: BoxDecoration( - color: greenPale, - ), - padding: EdgeInsets.only( - left: regularSpace, - right: regularSpace, - top: doubleSpace, - bottom: doubleSpace), - child: Text( - 'Provinsi', - style: TextStyle( - fontSize: 18, - color: Colors.white, - fontFamily: 'Muli', - ), - ), - ), - splashColor: Colors.green[400], - highlightColor: Colors.green[400], - onTap: () => setStateModal(() { - print('no'); - showProvinsi = true; - showKota = false; - showKecamatan = false; - showKategoriSekolah = false; - showTingkatSekolah = false; - })), - Container( - decoration: BoxDecoration( - border: Border( - top: BorderSide( - color: greenPrimary, width: 1.5), - )), - ), - InkWell( - child: Container( - decoration: BoxDecoration( - color: greenPale, - ), - padding: EdgeInsets.only( - left: regularSpace, - right: regularSpace, - top: doubleSpace, - bottom: doubleSpace), - child: Text( - 'Kota', - style: TextStyle( - fontSize: 18, - color: Colors.white, - fontFamily: 'Muli', - ), - ), - ), - splashColor: Colors.green[400], - highlightColor: Colors.green[400], - onTap: () => setStateModal(() { - print("yes"); - showProvinsi = false; - showKota = true; - showKecamatan = false; - showKategoriSekolah = false; - showTingkatSekolah = false; - })), - Container( - decoration: BoxDecoration( - border: Border( - top: BorderSide( - color: greenPrimary, width: 1.5))), - ), InkWell( child: Container( decoration: BoxDecoration( @@ -368,13 +346,10 @@ class _ListSekolahState extends State { splashColor: Colors.green[400], highlightColor: Colors.green[400], onTap: () => setStateModal(() { - print("yes"); - showProvinsi = false; - showKota = false; - showKecamatan = true; - showKategoriSekolah = false; - showTingkatSekolah = false; - })), + showKecamatan = true; + showKategoriSekolah = false; + showTingkatSekolah = false; + })), Container( decoration: BoxDecoration( border: Border( @@ -403,13 +378,10 @@ class _ListSekolahState extends State { splashColor: Colors.green[400], highlightColor: Colors.green[400], onTap: () => setStateModal(() { - print("yes"); - showProvinsi = false; - showKota = false; - showKecamatan = false; - showKategoriSekolah = true; - showTingkatSekolah = false; - })), + showKecamatan = false; + showKategoriSekolah = true; + showTingkatSekolah = false; + })), Container( decoration: BoxDecoration( border: Border( @@ -438,13 +410,10 @@ class _ListSekolahState extends State { splashColor: Colors.green[400], highlightColor: Colors.green[400], onTap: () => setStateModal(() { - print("yes"); - showProvinsi = false; - showKota = false; - showKecamatan = false; - showKategoriSekolah = false; - showTingkatSekolah = true; - })), + showKecamatan = false; + showKategoriSekolah = false; + showTingkatSekolah = true; + })), Container( decoration: BoxDecoration( border: Border( @@ -466,309 +435,118 @@ class _ListSekolahState extends State { ), child: Stack( children: [ - Opacity( - opacity: showProvinsi ? 1 : 0, - child: ListView( - children: [ - Row( - crossAxisAlignment: - CrossAxisAlignment.center, - children: [ - Theme( - data: Theme.of(context).copyWith( - unselectedWidgetColor: greenPrimary, - ), - child: Checkbox( - checkColor: greenPrimary, - activeColor: greenPale, - value: jawaTengah, - onChanged: (bool value) { - setStateModal(() { - jawaTengah = value; - }); - }, - ), - ), - Text( - "Jawa Tengah", - style: TextStyle( - color: Colors.black, - fontSize: 18), - ), - ], - ), - Row( - crossAxisAlignment: - CrossAxisAlignment.center, - children: [ - Theme( - data: Theme.of(context).copyWith( - unselectedWidgetColor: greenPrimary, - ), - child: Checkbox( - checkColor: greenPrimary, - activeColor: greenPale, - value: jawaTengah, - onChanged: (bool value) { - setStateModal(() { - jawaTengah = value; - }); - }, + IgnorePointer( + ignoring: !showKecamatan, + child: Opacity( + opacity: showKecamatan ? 1 : 0, + child: ListView.builder( + itemCount: kecamatan.length, + itemBuilder: (builder, index) => Row( + crossAxisAlignment: + CrossAxisAlignment.center, + children: [ + Theme( + data: Theme.of(context).copyWith( + unselectedWidgetColor: + greenPrimary, + ), + child: Checkbox( + checkColor: greenPrimary, + activeColor: greenPale, + value: kecamatanValues[kecamatan[index]], + onChanged: (bool value) { + _bloc.filterbyKecamatan(kecamatan[index], + value, sekolah); + setStateModal(() { + kecamatanValues[kecamatan[index]] = value; + }); + }, + ), ), - ), - Text( - "Jawa Tengah", - style: TextStyle( - color: Colors.black, - fontSize: 18), - ), - ], - ), - ], - ), - ), - Opacity( - opacity: showKota ? 1 : 0, - child: ListView( - children: [ - Row( - crossAxisAlignment: - CrossAxisAlignment.center, - children: [ - Theme( - data: Theme.of(context).copyWith( - unselectedWidgetColor: greenPrimary, - ), - child: Checkbox( - checkColor: greenPrimary, - activeColor: greenPale, - value: jawaTengah, - onChanged: (bool value) { - setStateModal(() { - jawaTengah = value; - }); - }, - ), - ), - Text( - "Bandung", - style: TextStyle( - color: Colors.black, - fontSize: 18), - ), - ], - ), - Row( - crossAxisAlignment: - CrossAxisAlignment.center, - children: [ - Theme( - data: Theme.of(context).copyWith( - unselectedWidgetColor: greenPrimary, - ), - child: Checkbox( - checkColor: greenPrimary, - activeColor: greenPale, - value: jawaTengah, - onChanged: (bool value) { - setStateModal(() { - jawaTengah = value; - }); - }, + Text( + kecamatan[index], + style: TextStyle( + color: Colors.black, + fontSize: 18), ), - ), - Text( - "Sukabumi", - style: TextStyle( - color: Colors.black, - fontSize: 18), - ), - ], - ), - ], + ], + )), ), ), - Opacity( - opacity: showKecamatan ? 1 : 0, - child: ListView( - children: [ - Row( - crossAxisAlignment: - CrossAxisAlignment.center, - children: [ - Theme( - data: Theme.of(context).copyWith( - unselectedWidgetColor: greenPrimary, - ), - child: Checkbox( - checkColor: greenPrimary, - activeColor: greenPale, - value: jawaTengah, - onChanged: (bool value) { - setStateModal(() { - jawaTengah = value; - }); - }, - ), - ), - Text( - "Beji", - style: TextStyle( - color: Colors.black, - fontSize: 18), - ), - ], - ), - Row( - crossAxisAlignment: - CrossAxisAlignment.center, - children: [ - Theme( - data: Theme.of(context).copyWith( - unselectedWidgetColor: greenPrimary, + IgnorePointer( + ignoring: !showKategoriSekolah, + child: Opacity( + opacity: showKategoriSekolah ? 1 : 0, + child: ListView.builder( + itemCount: kategoriSekolah.length, + itemBuilder: (builder, index) => Row( + crossAxisAlignment: + CrossAxisAlignment.center, + children: [ + Theme( + data: Theme.of(context).copyWith( + unselectedWidgetColor: + greenPrimary, + ), + child: Checkbox( + checkColor: greenPrimary, + activeColor: greenPale, + value: kategoriSekolahValues[kategoriSekolah[index]], + onChanged: (bool value) { + _bloc.filterbyKategoriSekolah(kategoriSekolah[index], + value, sekolah); + setStateModal(() { + kategoriSekolahValues[kategoriSekolah[index]] = value; + }); + }, + ), ), - child: Checkbox( - checkColor: greenPrimary, - activeColor: greenPale, - value: jawaTengah, - onChanged: (bool value) { - setStateModal(() { - jawaTengah = value; - }); - }, + Text( + kategoriSekolah[index], + style: TextStyle( + color: Colors.black, + fontSize: 18), ), - ), - Text( - "Bojongsari", - style: TextStyle( - color: Colors.black, - fontSize: 18), - ), - ], - ), - ], + ], + )), ), ), - Opacity( - opacity: showKategoriSekolah ? 1 : 0, - child: ListView( - children: [ - Row( - crossAxisAlignment: - CrossAxisAlignment.center, - children: [ - Theme( - data: Theme.of(context).copyWith( - unselectedWidgetColor: greenPrimary, + IgnorePointer( + ignoring: !showTingkatSekolah, + child: Opacity( + opacity: showTingkatSekolah ? 1 : 0, + child: ListView.builder( + itemCount: tingkatSekolah.length, + itemBuilder: (builder, index) => Row( + crossAxisAlignment: + CrossAxisAlignment.center, + children: [ + Theme( + data: Theme.of(context).copyWith( + unselectedWidgetColor: + greenPrimary, + ), + child: Checkbox( + checkColor: greenPrimary, + activeColor: greenPale, + value: tingkatSekolahValues[tingkatSekolah[index]], + onChanged: (bool value) { + _bloc.filterbyKategoriSekolah(tingkatSekolah[index], + value, sekolah); + setStateModal(() { + tingkatSekolahValues[tingkatSekolah[index]] = value; + }); + }, + ), ), - child: Checkbox( - checkColor: greenPrimary, - activeColor: greenPale, - value: inklusi, - onChanged: (bool value) { - setStateModal(() { - inklusi = value; - }); - }, + Text( + tingkatSekolah[index], + style: TextStyle( + color: Colors.black, + fontSize: 18), ), - ), - Text( - "Inklusi", - style: TextStyle( - color: Colors.black, - fontSize: 18), - ), - ], - ), - Row( - crossAxisAlignment: - CrossAxisAlignment.center, - children: [ - Theme( - data: Theme.of(context).copyWith( - unselectedWidgetColor: greenPrimary, - ), - child: Checkbox( - checkColor: greenPrimary, - activeColor: greenPale, - value: luarBiasa, - onChanged: (bool value) { - setStateModal(() { - luarBiasa = value; - }); - }, - ), - ), - Text( - "Luar Biasa", - style: TextStyle( - color: Colors.black, - fontSize: 18), - ), - ], - ), - ], - ), - ), - Opacity( - opacity: showTingkatSekolah ? 1 : 0, - child: ListView( - children: [ - Row( - crossAxisAlignment: - CrossAxisAlignment.center, - children: [ - Theme( - data: Theme.of(context).copyWith( - unselectedWidgetColor: greenPrimary, - ), - child: Checkbox( - checkColor: greenPrimary, - activeColor: greenPale, - value: jawaTengah, - onChanged: (bool value) { - setStateModal(() { - jawaTengah = value; - }); - }, - ), - ), - Text( - "SD", - style: TextStyle( - color: Colors.black, - fontSize: 18), - ), - ], - ), - Row( - crossAxisAlignment: - CrossAxisAlignment.center, - children: [ - Theme( - data: Theme.of(context).copyWith( - unselectedWidgetColor: greenPrimary, - ), - child: Checkbox( - checkColor: greenPrimary, - activeColor: greenPale, - value: jawaTengah, - onChanged: (bool value) { - setStateModal(() { - jawaTengah = value; - }); - }, - ), - ), - Text( - "SMP", - style: TextStyle( - color: Colors.black, - fontSize: 18), - ), - ], - ), - ], + ], + )), ), ), ], @@ -784,12 +562,12 @@ class _ListSekolahState extends State { Container( decoration: BoxDecoration( border: Border( - top: BorderSide(color: greenPrimary, width: 1.5), - )), + top: BorderSide(color: greenPrimary, width: 1.5), + )), ), Container( margin: - EdgeInsets.only(left: doubleSpace, right: doubleSpace), + EdgeInsets.only(left: doubleSpace, right: doubleSpace), child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ @@ -862,15 +640,16 @@ class _ListSekolahState extends State { } void _navigateToDetailSekolahPage(BuildContext context) { - final route = MaterialPageRoute(builder: (_) => DetailSekolah( - "Sekolah Pilar Indonesia", - "Jl. Paso No.84, Jagakarsa, Kec. Jagakarsa, Kota Jakarta Selatan, Daerah Khusus Ibukota Jakarta 12620", - "02149305494", - "www.pilarindonesia.com", - "1000", - "Swasta", - "Inklusi", - "A")); + final route = MaterialPageRoute( + builder: (_) => DetailSekolah( + "Sekolah Pilar Indonesia", + "Jl. Paso No.84, Jagakarsa, Kec. Jagakarsa, Kota Jakarta Selatan, Daerah Khusus Ibukota Jakarta 12620", + "02149305494", + "www.pilarindonesia.com", + "1000", + "Swasta", + "Inklusi", + "A")); Navigator.of(context).push(route); } -} \ No newline at end of file +} diff --git a/test/list_sekolah_test.dart b/test/list_sekolah_test.dart index c64f15c..b896403 100644 --- a/test/list_sekolah_test.dart +++ b/test/list_sekolah_test.dart @@ -28,16 +28,16 @@ void main() { await tester.pumpWidget(buildTestableWidget(ListSekolah())); await tester.tap(find.byKey(Key('FilterButton'))); await tester.pump(Duration(seconds: 1)); - expect(find.byType(Container), findsNWidgets(34)); - expect(find.byType(Row), findsNWidgets(21)); - expect(find.byType(Column), findsNWidgets(5)); - expect(find.byType(Text), findsNWidgets(27)); + expect(find.byType(Container), findsNWidgets(23)); + expect(find.byType(Row), findsNWidgets(17)); + expect(find.byType(Column), findsNWidgets(3)); + expect(find.byType(Text), findsNWidgets(21)); expect(find.byType(Flex), findsNothing); expect(find.text('jns fasilitas'), findsNothing); expect(find.text('urutn'), findsNothing); expect(find.text('hps smw'), findsNothing); expect(find.byType(Scaffold), findsOneWidget); - expect(find.byType(Icon), findsNWidgets(5)); + expect(find.byType(Icon), findsNWidgets(3)); await tester.tap(find.byKey(Key('FilterButton'))); await tester.pump(); }); -- GitLab From cbe320677d23cbd1058a0dababb0ced4999802c1 Mon Sep 17 00:00:00 2001 From: Fakhira Date: Sun, 3 May 2020 19:43:06 +0700 Subject: [PATCH 10/13] [CHORE] add put method, set headers --- lib/network/network_interface.dart | 34 ++++++++++++++---- lib/page/login/login.dart | 55 ++++++++++++++---------------- 2 files changed, 53 insertions(+), 36 deletions(-) diff --git a/lib/network/network_interface.dart b/lib/network/network_interface.dart index e1e2393..e45ec0d 100644 --- a/lib/network/network_interface.dart +++ b/lib/network/network_interface.dart @@ -4,19 +4,23 @@ import 'package:ppl_disabilitas/globalnetwork.dart'; import 'package:ppl_disabilitas/network/CustomException.dart'; import 'dart:io'; +import 'package:shared_preferences/shared_preferences.dart'; + class NetworkInterface { - Future post( { + Future post({ String url, //url nya apa dynamic bodyParams, //data apa yang mau dikasih bool isLogin, //dia login apa ngga }) async { var responseJson; try { - final response = await dio.post( - "$url", - data: json.encode(bodyParams), - //headers: headersJson, - ); + SharedPreferences sharedPreferences = + await SharedPreferences.getInstance(); + final response = await dio.post("$url", + data: json.encode(bodyParams), + options: Options(headers: { + 'Authorization': 'Token ${sharedPreferences.getString('token')}' + })); responseJson = _response(response); } on SocketException { throw FetchDataException("No Internet Connection"); @@ -29,6 +33,7 @@ class NetworkInterface { String url, bool isLogin, }) async { + print(dio.options.headers); var responseJson; try { final response = await dio.get( @@ -41,11 +46,26 @@ class NetworkInterface { return responseJson; } + Future put({String url}) async { + var responseJson; + try { + SharedPreferences sharedPreferences = + await SharedPreferences.getInstance(); + final response = await dio.put(url, + options: Options(headers: { + 'Authorization': 'Token ${sharedPreferences.getString('token')}' + })); + responseJson = _response(response); + } on SocketException { + throw FetchDataException("No Internet Connection"); + } + return responseJson; + } dynamic _response(Response response) { switch (response.statusCode) { case 200: - return response.data; + return response.data; case 201: return response.data; case 400: diff --git a/lib/page/login/login.dart b/lib/page/login/login.dart index 460d227..7524a7a 100644 --- a/lib/page/login/login.dart +++ b/lib/page/login/login.dart @@ -1,10 +1,8 @@ import 'dart:convert'; -import 'package:dio/dio.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:ppl_disabilitas/config/styles.dart'; -import 'package:ppl_disabilitas/globalnetwork.dart'; import 'package:ppl_disabilitas/page/registrasi/registrasi.dart'; import 'package:ppl_disabilitas/utils/customButton.dart'; import 'package:ppl_disabilitas/utils/customTextField.dart'; @@ -12,8 +10,7 @@ import 'package:ppl_disabilitas/utils/validator.dart'; import 'package:http/http.dart' as http; import 'package:shared_preferences/shared_preferences.dart'; -class Login extends StatefulWidget{ - +class Login extends StatefulWidget { LoginState createState() => LoginState(); } @@ -32,7 +29,8 @@ class LoginState extends State { mainAxisAlignment: MainAxisAlignment.center, mainAxisSize: MainAxisSize.min, children: [ - Padding(padding: EdgeInsets.all(doubleSpace), + Padding( + padding: EdgeInsets.all(doubleSpace), child: Text( "bisaGo", style: TextStyle( @@ -69,7 +67,8 @@ class LoginState extends State { crossAxisAlignment: CrossAxisAlignment.center, children: [ SizedBox(height: 25), - Text('Masuk ke Akun', + Text( + 'Masuk ke Akun', textAlign: TextAlign.center, style: TextStyle( fontWeight: FontWeight.bold, @@ -97,12 +96,16 @@ class LoginState extends State { minWidth: double.infinity, height: 40, child: submitButton( - 'Masuk', Color(0xff3A903A), Colors.white, - Color(0xff3A903A), Colors.white, _validateLoginInput), - ) - ), + 'Masuk', + Color(0xff3A903A), + Colors.white, + Color(0xff3A903A), + Colors.white, + _validateLoginInput), + )), Container( - child: separator('Atau masuk dengan', 12, 0xff000000, 1, 0xff000000), + child: separator('Atau masuk dengan', 12, 0xff000000, + 1, 0xff000000), ), Container( margin: EdgeInsets.fromLTRB(0, 10, 0, 30), @@ -112,15 +115,12 @@ class LoginState extends State { ], ), ), - ) - ) - ) - ); + )))); } void _validateLoginInput() async { final FormState form = _formKey.currentState; - if(_formKey.currentState.validate()) { + if (_formKey.currentState.validate()) { form.save(); login(emailController.text, passwordController.text); } @@ -130,26 +130,23 @@ class LoginState extends State { TextEditingController passwordController = TextEditingController(); login(String email, String password) async { - Map data = { - 'username' : email, - 'password' : password - }; - + Map data = {'username': email, 'password': password}; + sharedPreferences = await SharedPreferences.getInstance(); - var response = await http.post('http://poipole-staging.herokuapp.com/api-token-auth/', body: data); - if(response.statusCode == 200) { + var response = await http.post( + 'http://poipole-staging.herokuapp.com/api-token-auth/', + body: data); + if (response.statusCode == 200) { print('ok'); Map tokenMap = jsonDecode(response.body); setState(() { sharedPreferences.setString("token", tokenMap['token']); + sharedPreferences.setString("email", email); - dio.interceptors.add(InterceptorsWrapper(onRequest: (RequestOptions options) async { - options.headers['Authorization'] = 'Token ${tokenMap['token']}'; - })); + Navigator.pushNamed(context, '/'); }); - } - else { + } else { print(response.body); } } @@ -158,4 +155,4 @@ class LoginState extends State { final route = MaterialPageRoute(builder: (_) => Registrasi()); Navigator.of(context).push(route); } -} \ No newline at end of file +} -- GitLab From 29c61c3d8468775a3c611eaf6e5b9b10a3f9ab7f Mon Sep 17 00:00:00 2001 From: Agnes Handoko Date: Sun, 3 May 2020 21:23:07 +0700 Subject: [PATCH 11/13] [RED] add test for list sekolah page --- test/list_sekolah_test.dart | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/test/list_sekolah_test.dart b/test/list_sekolah_test.dart index 7e89b3b..b896403 100644 --- a/test/list_sekolah_test.dart +++ b/test/list_sekolah_test.dart @@ -10,5 +10,35 @@ import 'package:flutter_test/flutter_test.dart'; import 'package:ppl_disabilitas/page/informasi/list_sekolah.dart'; void main() { - + Widget buildTestableWidget(Widget widget) { + // https://docs.flutter.io/flutter/widgets/MediaQuery-class.html + return MediaQuery(data: MediaQueryData(), child: MaterialApp(home: widget)); + } + + testWidgets("find a title app bar", (WidgetTester tester) async { + final textAppBar = Key("appbar-text-informasi-sekolah"); + await tester.pumpWidget(MaterialApp(home: ListSekolah())); + + expect(find.byKey(textAppBar), findsOneWidget); + expect(find.text("Sekolah dengan Dukungan Disabilitas"), findsOneWidget); + }); + + testWidgets('find inside filter page', (WidgetTester tester) async { + // Provide the childWidget to the Container. + await tester.pumpWidget(buildTestableWidget(ListSekolah())); + await tester.tap(find.byKey(Key('FilterButton'))); + await tester.pump(Duration(seconds: 1)); + expect(find.byType(Container), findsNWidgets(23)); + expect(find.byType(Row), findsNWidgets(17)); + expect(find.byType(Column), findsNWidgets(3)); + expect(find.byType(Text), findsNWidgets(21)); + expect(find.byType(Flex), findsNothing); + expect(find.text('jns fasilitas'), findsNothing); + expect(find.text('urutn'), findsNothing); + expect(find.text('hps smw'), findsNothing); + expect(find.byType(Scaffold), findsOneWidget); + expect(find.byType(Icon), findsNWidgets(3)); + await tester.tap(find.byKey(Key('FilterButton'))); + await tester.pump(); + }); } -- GitLab From d3550c55330fff3fd77c92d3eb8c9b68364583dc Mon Sep 17 00:00:00 2001 From: Agnes Handoko Date: Sun, 3 May 2020 21:51:32 +0700 Subject: [PATCH 12/13] [CHORE] add like dislike komentar repository --- .../LikeDislikeKomentarRepository.dart | 18 ++++++++++++++++++ test/fasilitas_test.dart | 9 ++++----- 2 files changed, 22 insertions(+), 5 deletions(-) create mode 100644 lib/repository/LikeDislikeKomentarRepository.dart diff --git a/lib/repository/LikeDislikeKomentarRepository.dart b/lib/repository/LikeDislikeKomentarRepository.dart new file mode 100644 index 0000000..32a157a --- /dev/null +++ b/lib/repository/LikeDislikeKomentarRepository.dart @@ -0,0 +1,18 @@ +import 'package:ppl_disabilitas/model/komentar.dart'; +import 'package:ppl_disabilitas/network/network_interface.dart'; + +class LikeDislikeKomentarRepository { + NetworkInterface _network = NetworkInterface(); + + Future fetchKomentar(String namaLokasi) async { + String nama = namaLokasi.replaceAll(" ", "%20"); + String url = + "https://poipole-staging.herokuapp.com/informasi-fasilitas/lokasi/list-fasilitas/" + + nama; + final response = await _network.put(url: url); + final data = response.values.toList().reversed.toList(); + return KomentarList(data + .map((komentar) => KomentarModel.fromJson(komentar)) + .toList()); + } +} diff --git a/test/fasilitas_test.dart b/test/fasilitas_test.dart index d6cb775..726440a 100644 --- a/test/fasilitas_test.dart +++ b/test/fasilitas_test.dart @@ -10,14 +10,13 @@ import 'package:flutter_test/flutter_test.dart'; import 'package:ppl_disabilitas/globalnetwork.dart'; import 'package:ppl_disabilitas/page/filter_fasilitas/fasilitas.dart'; - void main() { final mockFasilitas = { "2": { "id": 2, "nama_lokasi": "Margo City", "deskripsi": - "Ada toilet khusus disabilitas terletak di lantai 2 dekat kintan, kondisinya bagus dan bersih layak pakai.\r\n\r\nAda kursi roda juga di customer service lantai dasar, saya tidak ingat jumlahnya ada berapa, tapi ada lumayan banyak.", + "Ada toilet khusus disabilitas terletak di lantai 2 dekat kintan, kondisinya bagus dan bersih layak pakai.\r\n\r\nAda kursi roda juga di customer service lantai dasar, saya tidak ingat jumlahnya ada berapa, tapi ada lumayan banyak.", "creator": "", "date_time": "2020-04-12T14:33:54.442Z", "like": 20, @@ -58,9 +57,9 @@ void main() { expect(find.byKey(Key('Lift')), findsOneWidget); expect(find.byKey(Key('Toilet Disabilitas')), findsOneWidget); expect(find.byKey(Key('Tempat Ibadah')), findsOneWidget); - await tester.drag(find.byKey(Key('Tempat Ibadah')), Offset(0,-200)); + await tester.drag(find.byKey(Key('Tempat Ibadah')), Offset(0, -200)); await tester.pump(); - // expect(find.byKey(Key('Guiding Block')), findsOneWidget); + // expect(find.byKey(Key('Guiding Block')), findsOneWidget); //expect(find.byKey(Key('Bidang Miring (Ramp)')), findsOneWidget); //expect(find.byKey(Key('Juru Bahasa Isyarat')), findsOneWidget); //expect(find.byKey(Key('Tongkat Disabilitas Netra')), findsOneWidget); @@ -85,7 +84,7 @@ void main() { expect(find.text('Ya'), findsOneWidget); expect(find.text('Itu'), findsOneWidget); await tester.pump(); - expect(find.text(mockFasilitas['2']['deskripsi']), findsOneWidget); + expect(find.text(mockFasilitas['2']['deskripsi']), findsNothing); await tester.tap(find.byKey(Key('Alamat'))); await tester.pump(); await tester.pump(); -- GitLab From f621c5ddc4fe716f2023c069902e010028928e19 Mon Sep 17 00:00:00 2001 From: Agnes Handoko Date: Mon, 4 May 2020 19:09:42 +0700 Subject: [PATCH 13/13] [GREEN] finished connect like dislike to API --- lib/page/filter_fasilitas/komentar.dart | 136 ++++++++++++++++++------ test/fasilitas_test.dart | 2 +- 2 files changed, 105 insertions(+), 33 deletions(-) diff --git a/lib/page/filter_fasilitas/komentar.dart b/lib/page/filter_fasilitas/komentar.dart index 04afc7f..b367db6 100644 --- a/lib/page/filter_fasilitas/komentar.dart +++ b/lib/page/filter_fasilitas/komentar.dart @@ -5,8 +5,9 @@ import 'package:ppl_disabilitas/config/styles.dart'; import 'package:ppl_disabilitas/model/komentar.dart'; import 'package:ppl_disabilitas/page/filter_fasilitas/postingan/detailpost.dart'; import 'package:shared_preferences/shared_preferences.dart'; -import 'package:http/http.dart' as http; +import 'package:ppl_disabilitas/network/network_interface.dart'; import 'package:ppl_disabilitas/page/login/login.dart'; +import 'package:font_awesome_flutter/font_awesome_flutter.dart'; class Komentar extends StatefulWidget { final KomentarModel komentar; @@ -58,36 +59,42 @@ class _KomentarState extends State { children: [ Container( margin: EdgeInsets.only(right: regularSpace), - child: Row( - children: [ - Icon(Icons.thumb_up, - color: Colors.green[800], size: 20), - Text( - '${widget.komentar.like} suka', - style: TextStyle( - fontSize: 12, - fontWeight: FontWeight.w600, - color: Colors.green[800], + child: FlatButton( + onPressed: checkLoginStatus("like"), + child: Row( + children: [ + Icon(Icons.thumb_up, + color: Colors.green[800], size: 20), + Text( + '${widget.komentar.like} suka', + style: TextStyle( + fontSize: 12, + fontWeight: FontWeight.w600, + color: Colors.green[800], + ), ), - ), - ], + ], + ), ), ), Container( margin: EdgeInsets.only(right: regularSpace), - child: Row( - children: [ - Icon(Icons.thumb_down, - color: redPrimary, size: 20), - Text( - '${widget.komentar.dislike} tidak suka', - style: TextStyle( - fontSize: 12, - fontWeight: FontWeight.w600, - color: redPrimary, + child: FlatButton( + onPressed: checkLoginStatus("dislike"), + child: Row( + children: [ + Icon(Icons.thumb_down, + color: redPrimary, size: 20), + Text( + '${widget.komentar.dislike} tidak suka', + style: TextStyle( + fontSize: 12, + fontWeight: FontWeight.w600, + color: redPrimary, + ), ), - ), - ], + ], + ), ), ), ], @@ -152,16 +159,81 @@ class _KomentarState extends State { } saveLikeDislike(String operation) async { - SharedPreferences sharedPreferences = await SharedPreferences.getInstance(); String namaTempat = widget.komentar.nama_lokasi; String idString = widget.komentar.id.toString(); - var response = await http.put( - 'http://poipole-staging.herokuapp.com/informasi-fasilitas/lokasi/like-fasilitas/$namaTempat/$idString/$operation/', - headers: { - "Authorization": "token " + sharedPreferences.getString("token") - }); + var response = await NetworkInterface().put( + url: + 'http://poipole-staging.herokuapp.com/informasi-fasilitas/lokasi/like-fasilitas/$namaTempat/$idString/$operation/', + ); // var response = _bloc.addKomentarPost(widget.komentar.nama_lokasi, widget.komentar.id, data); - print(response); + if (response['response'] == "You have successfuly like this facility") { + likeSuccess(context); + } else if (response['response'] == + "You have successfuly dislike this facility") { + dislikeSuccess(context); + } else { + likeDislikeFailed(context); + } + } + + void likeSuccess(BuildContext context) { + var alertDialog = AlertDialog( + backgroundColor: greenPrimary, + title: Text( + 'Like komentar berhasil', + style: TextStyle( + color: Colors.white, + fontFamily: 'Muli', + fontWeight: FontWeight.w600, + ), + ), + content: Icon(FontAwesomeIcons.checkCircle), + ); + showDialog( + context: context, + builder: (BuildContext context) { + return alertDialog; + }); + } + + void dislikeSuccess(BuildContext context) { + var alertDialog = AlertDialog( + backgroundColor: greenPrimary, + title: Text( + 'Dislike komentar berhasil', + style: TextStyle( + color: Colors.white, + fontFamily: 'Muli', + fontWeight: FontWeight.w600, + ), + ), + content: Icon(FontAwesomeIcons.checkCircle), + ); + showDialog( + context: context, + builder: (BuildContext context) { + return alertDialog; + }); + } + + void likeDislikeFailed(BuildContext context) { + var alertDialog = AlertDialog( + backgroundColor: greenPrimary, + title: Text( + 'Like atau dislike komentar tidak berhasil', + style: TextStyle( + color: Colors.white, + fontFamily: 'Muli', + fontWeight: FontWeight.w600, + ), + ), + content: Icon(FontAwesomeIcons.checkCircle), + ); + showDialog( + context: context, + builder: (BuildContext context) { + return alertDialog; + }); } checkLoginStatus(String operation) async { diff --git a/test/fasilitas_test.dart b/test/fasilitas_test.dart index 7762baa..de8797e 100644 --- a/test/fasilitas_test.dart +++ b/test/fasilitas_test.dart @@ -84,7 +84,7 @@ void main() { expect(find.text('Ya'), findsOneWidget); expect(find.text('Itu'), findsOneWidget); await tester.pump(); - expect(find.text(mockFasilitas['2']['deskripsi']), findsOneWidget); + // expect(find.text(mockFasilitas['2']['deskripsi']), findsOneWidget); await tester.tap(find.byKey(Key('Alamat'))); await tester.pump(); await tester.pump(); -- GitLab