diff --git a/.flutter-plugins-dependencies b/.flutter-plugins-dependencies index 8fb2c9cd194bcfac18a0693b835aceceaabd44ae..52b1c6a03a93b4d2cbdeb35281f7e486aaa86feb 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":[]}],"android":[{"name":"flutter_plugin_android_lifecycle","path":"D:\\\\Flutter\\\\flutter_windows_v1.9.1+hotfix.2-stable\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\flutter_plugin_android_lifecycle-1.0.6\\\\","dependencies":[]},{"name":"google_maps_flutter","path":"D:\\\\Flutter\\\\flutter_windows_v1.9.1+hotfix.2-stable\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\google_maps_flutter-0.5.24+1\\\\","dependencies":["flutter_plugin_android_lifecycle"]},{"name":"location","path":"D:\\\\Flutter\\\\flutter_windows_v1.9.1+hotfix.2-stable\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\location-2.5.3\\\\","dependencies":[]},{"name":"path_provider","path":"D:\\\\Flutter\\\\flutter_windows_v1.9.1+hotfix.2-stable\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\path_provider-1.6.5\\\\","dependencies":[]}],"macos":[{"name":"path_provider_macos","path":"D:\\\\Flutter\\\\flutter_windows_v1.9.1+hotfix.2-stable\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\path_provider_macos-0.0.4\\\\","dependencies":[]}],"linux":[],"windows":[],"web":[]},"dependencyGraph":[{"name":"flutter_plugin_android_lifecycle","dependencies":[]},{"name":"google_maps_flutter","dependencies":["flutter_plugin_android_lifecycle"]},{"name":"location","dependencies":[]},{"name":"path_provider","dependencies":["path_provider_macos"]},{"name":"path_provider_macos","dependencies":[]}],"date_created":"2020-03-25 22:33:34.112007","version":"1.15.17"} \ No newline at end of file +{"_info":"// This is a generated file; do not edit or check into version control.","dependencyGraph":[{"name":"flutter_plugin_android_lifecycle","dependencies":[]},{"name":"google_maps_flutter","dependencies":["flutter_plugin_android_lifecycle"]},{"name":"location","dependencies":[]},{"name":"path_provider","dependencies":["path_provider_macos"]},{"name":"path_provider_macos","dependencies":[]}]} \ No newline at end of file diff --git a/lib/page/pencarian/pencarian.dart b/lib/page/pencarian/pencarian.dart index 20aad672ac0a2174716f9d4aedeeb68b47196732..6dec9698ebbbd9159af3891b9c730736af10507b 100644 --- a/lib/page/pencarian/pencarian.dart +++ b/lib/page/pencarian/pencarian.dart @@ -1,216 +1,185 @@ +import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; -import 'package:ppl_disabilitas/bloc/LokasiResponseBloc.dart'; import 'package:ppl_disabilitas/config/styles.dart'; -import 'package:ppl_disabilitas/model/lokasi.dart'; import 'package:ppl_disabilitas/network/data/network_model.dart'; +import 'package:ppl_disabilitas/network/network_interface.dart'; +/// Create Pencarian page widget with a state class Pencarian extends StatefulWidget { @override PencarianState createState() => PencarianState(); } +/// State of Pencacrian page class PencarianState extends State { + /// Controller for textFormField + TextEditingController myController = TextEditingController(); + + /// Search Icon for textFormField Icon searchIcon = Icon(Icons.search); - Widget appBarText = Text("Pencarian Lokasi"); - LokasiResponseBloc _bloc = LokasiResponseBloc(); - LokasiListResponse lokasiFromApi; - LokasiListResponse recentSearch; + + /// Text for appbar + Widget appBarText = Text('Pencarian Lokasi'); + + /// To get API of places + NetworkInterface networkInterface = NetworkInterface(); + + /// List for places from API + List places = []; + + /// List of places currently searched on the textFormField + List currentSearch = []; + + /// Data from API + Future data; + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties..add(DiagnosticsProperty('places', places)) + ..add(DiagnosticsProperty('currentSearch', currentSearch)) + ..add(DiagnosticsProperty('networkInterface', networkInterface)); + } + + @override void initState() { + data = networkInterface.get( + url: 'https://my.api.mockaroo.com/mall.json?key=dbcde960'); + myController.addListener(() { + List tempList = []; + for (int i = 0; i < places.length; i++) { + if (places[i]['nama'] + .toLowerCase() + .contains(myController.text.toLowerCase())) { + tempList.add(places[i]); + } + } + setState(() { + currentSearch = tempList; + }); + }); super.initState(); } @override Widget build(BuildContext context) { return Scaffold( - appBar: AppBar( - backgroundColor: greenPrimary, - leading: IconButton( - icon: Icon(Icons.arrow_back_ios, size: 25), - key: Key("Back Icon Key"), - onPressed: () => Navigator.pop(context, 'Take me back')), - title: Container( - margin: EdgeInsets.only(top: doubleSpace, bottom: doubleSpace), - decoration: BoxDecoration( - color: Colors.white, - borderRadius: doubleBorderRadius, - boxShadow: regularShadow), - child: TextFormField( - key: Key("Text Field Mau Kemana"), - decoration: InputDecoration( - contentPadding: EdgeInsets.all(0), - isDense: false, - prefixIcon: Icon( - Icons.search, - color: greenPrimary, - size: 25, - ), - border: InputBorder.none, - fillColor: Colors.white, - labelText: 'Kamu mau kemana?', - labelStyle: TextStyle( + appBar: AppBar( + backgroundColor: greenPrimary, + leading: IconButton( + icon: Icon(Icons.arrow_back_ios, size: 25), + key: Key('Back Icon Key'), + onPressed: () => Navigator.pop(context, 'Take me back')), + title: Container( + margin: EdgeInsets.only(top: doubleSpace, bottom: doubleSpace), + decoration: BoxDecoration( + color: Colors.white, + borderRadius: doubleBorderRadius, + boxShadow: regularShadow), + child: TextFormField( + controller: myController, + key: Key('Text Field Mau Kemana'), + decoration: InputDecoration( + contentPadding: EdgeInsets.all(0), + isDense: false, + prefixIcon: Icon( + Icons.search, color: greenPrimary, - fontSize: 18, - fontFamily: 'Muli', - fontWeight: FontWeight.w700), - suffixIcon: IconButton( + size: 25, + ), + border: InputBorder.none, + fillColor: Colors.white, + labelText: 'Kamu mau kemana?', + labelStyle: TextStyle( + color: greenPrimary, + fontSize: 18, + fontFamily: 'Muli', + fontWeight: FontWeight.w700), + suffixIcon: IconButton( icon: Icon( Icons.mic, color: greenPrimary, size: 25, - ), - onPressed: () {})), + ), onPressed: () {}, + )), + ), ), ), - ), - body: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - StreamBuilder>( - stream: _bloc.recentSearchStream, + body: Stack(children: [ + FutureBuilder( + future: data, builder: (context, snapshot) { if (snapshot.hasData) { - switch (snapshot.data.status) { - case Status.LOADING: - return Center( - child: CircularProgressIndicator( - valueColor: AlwaysStoppedAnimation(greenPrimary), - ), - ); - break; - case Status.COMPLETED: - recentSearch = snapshot.data.data; - Widget displayWidget; - if (recentSearch.listLokasi.isEmpty) { - displayWidget = Center( - child: Text("Anda belum pernah melakukan pencarian")); - } else { - displayWidget = makeLokasiWidget("history",recentSearch); - } - return Expanded( - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Container( - margin: EdgeInsets.all(doubleSpace), - child: Text( - "Pencarian terdahulu", - style: TextStyle( - fontFamily: 'Muli', fontSize: 15), - )), - Flexible(child: displayWidget), - ], - )); - break; - case Status.ERROR: - return Center( - child: Text("${snapshot.data.status}"), - ); - break; - } + //places = snapshot.data.response; + return Container(); + } else if (snapshot.hasError) { + return Text('${snapshot.error}'); } - return Container(); - }, - ), - Container( - margin: EdgeInsets.only(left: doubleSpace, top: regularSpace, bottom: smallSpace), - child: Text("Hasil Pencarian"), - ), - StreamBuilder>( - stream: _bloc.lokasiListStream, - builder: (context, snapshot) { - if (snapshot.hasData) { - switch (snapshot.data.status) { - case Status.LOADING: - return Center( - child: CircularProgressIndicator( - valueColor: AlwaysStoppedAnimation(greenPrimary), - ), - ); - break; - case Status.COMPLETED: - lokasiFromApi = snapshot.data.data; - return Expanded( - flex: 2, child: makeLokasiWidget("api",lokasiFromApi)); - break; - case Status.ERROR: - return Center( - child: Text(snapshot.data.data.toString()), - ); - break; - } - } - return Container(); - }, - ), - ], - ), - ); - } - Widget makeLokasiWidget(String key, LokasiListResponse places) { - return ListView.builder( - shrinkWrap: true, - itemCount: places.listLokasi.length, - itemBuilder: (context, index) { - return InkWell( - key: Key("$key-${places.listLokasi[index].nama}"), - onTap: () { - _bloc.saveRecentSearch(places.listLokasi[index]); + // By default, show a loading spinner. + return CircularProgressIndicator(); }, - child: Container( - decoration: BoxDecoration( - color: Colors.transparent, - border: Border(bottom: BorderSide(color: Colors.grey[400]))), - margin: EdgeInsets.only(left: doubleSpace, right: doubleSpace), - height: 90, - child: Row( - mainAxisSize: MainAxisSize.max, - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Row( + ), + ListView.builder( + itemCount: currentSearch.length, + itemBuilder: (context, index) { + return Container( + decoration: BoxDecoration( + color: Colors.transparent, + border: + Border(bottom: BorderSide(color: Colors.grey[400]))), + margin: + EdgeInsets.only(left: doubleSpace, right: doubleSpace), + height: 90, + child: Row( + mainAxisSize: MainAxisSize.max, + mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ - CircleAvatar( - backgroundColor: greenPrimary, - child: Text('Test'), - ), - Container( - padding: EdgeInsets.all(doubleSpace), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Text( - places.listLokasi[index].nama, - style: TextStyle( - fontSize: 18, - fontWeight: FontWeight.w800, - color: Colors.black, - fontFamily: 'Muli', - ), - ), - Text( - places.listLokasi[index].alamat, - style: TextStyle( - fontSize: 15, - color: Colors.black, - fontFamily: 'Muli', - ), + Row( + children: [ + CircleAvatar( + backgroundColor: greenPrimary, + child: Text('Test'), + ), + Container( + padding: EdgeInsets.all(doubleSpace), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Text( + currentSearch[index]['nama'], + key: Key('Result text'), + style: TextStyle( + fontSize: 18, + fontWeight: FontWeight.w800, + color: Colors.black, + fontFamily: 'Muli', + ), + ), + Text( + currentSearch[index]['alamat'], + style: TextStyle( + fontSize: 15, + color: Colors.black, + fontFamily: 'Muli', + ), + ), + ], ), - ], - ), + ), + ], ), + Icon( + Icons.arrow_forward_ios, + color: Colors.grey[400], + size: 20, + ) ], ), - Icon( - Icons.arrow_forward_ios, - color: Colors.grey[400], - size: 20, - ) - ], - ), - ), - ); - }); + ); + }) + ])); } -} +} \ No newline at end of file diff --git a/test/pencarian_test.dart b/test/pencarian_test.dart index 1d4f32f7d64818771b5db9b028bc288ee65f8a4e..242b87c79f1e43472f9394857886d86fb5bde468 100644 --- a/test/pencarian_test.dart +++ b/test/pencarian_test.dart @@ -36,7 +36,6 @@ void main() { }); }); testWidgets('display list view in pencarian', (WidgetTester tester) async { - // Provide the childWidget to the Container. await tester.pumpWidget(MaterialApp(home: Pencarian())); // [TODO] pencet textfieldnya, isi textfieldnya pake Coolidge // [TODO] expect nya keluar satu item namanya coolidge, expectnya pake key aja @@ -53,4 +52,13 @@ void main() { expect(find.byKey(textFieldKey), findsOneWidget); }); + + testWidgets('test textfield result', (WidgetTester tester) async { + final textFieldKey = Key("Text Field Mau Kemana"); + await tester.pumpWidget(MaterialApp(home: Pencarian())); + await tester.enterText(find.byKey(textFieldKey), 'Mallory'); + await tester.pump(); + expect(find.text('Mallory'), findsOneWidget); +}); + }