Fakultas Ilmu Komputer UI

Commit 9f86f284 authored by Jovi Handono Hutama's avatar Jovi Handono Hutama
Browse files

Merge branch 'dev-noor' into 'PBI-9-info_kegiatan'

Dev noor

See merge request !34
parents 122c70bc 541741a2
Pipeline #77161 failed with stages
in 4 minutes and 28 seconds
import 'dart:async';
import 'package:bisaGo/network/data/network_model.dart';
import 'package:bisaGo/repository/kegiatan_terdekat_repository.dart';
import 'package:get_it/get_it.dart';
import 'package:rxdart/rxdart.dart';
class KegiatanTerdekatBloc {
KegiatanTerdekatRepository _kegiatanTerdekatRepository;
StreamController _kegiatanTerdekatController;
StreamSink<NetworkModel> get kegiatanTerdekatSink =>
_kegiatanTerdekatController.sink;
Stream<NetworkModel> get kegiatanTerdekatStream =>
_kegiatanTerdekatController.stream;
KegiatanTerdekatBloc() {
_kegiatanTerdekatController = BehaviorSubject<NetworkModel>();
_kegiatanTerdekatRepository = GetIt.instance.get<BaseKegiatanTerdekatRepository>();
fetchKegiatanTerdekat();
}
Future<void> fetchKegiatanTerdekat() async {
kegiatanTerdekatSink.add(NetworkModel.loading('Loading Kegiatan'));
try {
final kegiatanTerdekatResponse =
await _kegiatanTerdekatRepository.fetchKegiatanTerdekatResponse();
kegiatanTerdekatSink.add(NetworkModel.completed(kegiatanTerdekatResponse));
} catch (e) {
kegiatanTerdekatSink.add(NetworkModel.error(e.toString()));
}
}
}
\ No newline at end of file
import 'package:bisaGo/repository/kegiatan_repository.dart';
import 'package:bisaGo/repository/kegiatan_terdekat_repository.dart';
import 'package:bisaGo/repository/komentar_posting_kegiatan_repository.dart';
import 'package:bisaGo/repository/dynamic_links_service_repository.dart';
import 'package:bisaGo/repository/komentar_posting_repository.dart';
......@@ -31,6 +32,8 @@ class AppGetIt {
() => LayananRepository());
_getIt.registerLazySingleton<BaseKegiatanRepository>(
() => KegiatanRepository());
_getIt.registerLazySingleton<BaseKegiatanTerdekatRepository>(
() => KegiatanTerdekatRepository());
_getIt.registerLazySingleton<BaseDynamicLinksServiceRepository>(
() => DynamicLinksServiceRepository());
}
......
import 'package:bisaGo/bloc/lokasi_response_bloc.dart';
import 'package:bisaGo/model/komentar.dart';
import 'package:bisaGo/model/lokasi.dart';
import 'package:bisaGo/bloc/kegiatan_terdekat_bloc.dart';
import 'package:bisaGo/model/kegiatan.dart';
import 'package:bisaGo/utils/custom_kegiatan_terdekat_button.dart';
import 'package:bisaGo/network/data/network_model.dart';
import 'package:bisaGo/page/filter_fasilitas/postingan/detail_post.dart';
import 'package:bisaGo/repository/komentar_repository.dart';
......@@ -31,6 +34,7 @@ class DashboardState extends State<Dashboard> {
Set<Marker> markers = {};
LokasiResponseBloc bloc = LokasiResponseBloc();
KegiatanTerdekatBloc blocKegiatanTerdekat = KegiatanTerdekatBloc();
@override
void initState() {
......@@ -84,102 +88,161 @@ class DashboardState extends State<Dashboard> {
drawer: BisaGoDrawer(),
body: Stack(
key: const Key('Stack'),
alignment: AlignmentDirectional.bottomStart,
//alignment: AlignmentDirectional.bottomStart,
children: <Widget>[
_buildGoogleMap(context),
Container(
height: 285,
alignment: Alignment.bottomCenter,
decoration: const BoxDecoration(
color: white,
borderRadius: BorderRadius.all(
Radius.circular(10.0),
),
),
padding: const EdgeInsets.symmetric(
horizontal: doubleSpace, vertical: doubleSpace),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
InkWell(
key: const Key('Navigate to Pencarian'),
onTap: () => _navigateToPencarianPage(context),
child: Container(
key: const Key('Container Text Field'),
padding: EdgeInsets.zero,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: regularBorderRadius,
border: Border.all(color: greenPrimary),
boxShadow: regularShadow),
child: TextFormField(
enabled: false,
key: const Key('Text Field Mau Kemana'),
decoration: const InputDecoration(
prefixIcon: Icon(
Icons.search,
color: greenPrimary,
size: 25,
),
border: InputBorder.none,
fillColor: Colors.white,
labelText: 'Tekan untuk mencari tempat',
labelStyle: TextStyle(
color: greenPrimary,
fontSize: 20,
fontFamily: 'Muli',
fontWeight: FontWeight.w700),
),
padding: EdgeInsets.only(top: 35),
child:_buildGoogleMap(context)),
Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Container(
height: 40,
alignment: Alignment.center,
decoration: const BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.only(
bottomLeft: Radius.circular(10.0),
bottomRight: Radius.circular(10.0)
),
),
),
const SizedBox(height: doubleSpace),
const Text(
'Paling sering dicari',
style: TextStyle(
color: Colors.black,
fontSize: 18,
fontWeight: FontWeight.bold,
),
),
const SizedBox(height: 10),
StreamBuilder<NetworkModel<LokasiListResponse>>(
stream: bloc.lokasiListStream,
child: Padding(
padding: const EdgeInsets.symmetric(
horizontal: doubleSpace),
child: StreamBuilder<NetworkModel>(
stream: blocKegiatanTerdekat.kegiatanTerdekatStream,
builder: (context, snapshot) {
if (snapshot.hasData) {
switch (snapshot.data.status) {
case Status.loading:
return Container(
height: 130,
child: const Center(
child: CircularProgressIndicator(
child: LinearProgressIndicator(
valueColor: AlwaysStoppedAnimation<Color>(
greenPrimary),
),
),
greenPrimary),
)
)
);
break;
case Status.completed:
final places = snapshot.data.data.listLokasi;
return _buildLokasiWidget(places);
final kegiatanTerdekat =
snapshot.data.data;
return _buildKegiatanTerdekatWidget(
kegiatanTerdekat);
break;
case Status.error:
return Container(
height: 130,
child: const Center(
child: Text('Gagal untuk mendapatkan tempat'),
),
);
child: const Center(child:
Text('Tidak ada kegiatan dalam waktu dekat',
style: TextStyle(
color: greenPrimary,
fontSize: 16,
fontFamily: 'Muli',
)),));
break;
}
return Container();
}
return Container();
}),
],
),
}
return Container();
}
)
)
), // Container info kegiatan
Container(
height: 285,
alignment: Alignment.bottomCenter,
decoration: const BoxDecoration(
color: white,
borderRadius: BorderRadius.all(
Radius.circular(10.0),
),
),
padding: const EdgeInsets.symmetric(
horizontal: doubleSpace, vertical: doubleSpace),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
InkWell(
key: const Key('Navigate to Pencarian'),
onTap: () => _navigateToPencarianPage(context),
child: Container(
key: const Key('Container Text Field'),
padding: EdgeInsets.zero,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: regularBorderRadius,
border: Border.all(color: greenPrimary),
boxShadow: regularShadow),
child: TextFormField(
enabled: false,
key: const Key('Text Field Mau Kemana'),
decoration: const InputDecoration(
prefixIcon: Icon(
Icons.search,
color: greenPrimary,
size: 25,
),
border: InputBorder.none,
fillColor: Colors.white,
labelText: 'Tekan untuk mencari tempat',
labelStyle: TextStyle(
color: greenPrimary,
fontSize: 20,
fontFamily: 'Muli',
fontWeight: FontWeight.w700),
),
),
),
),
const SizedBox(height: doubleSpace),
const Text(
'Paling sering dicari',
style: TextStyle(
color: Colors.black,
fontSize: 18,
fontWeight: FontWeight.bold,
),
),
const SizedBox(height: 10),
StreamBuilder<NetworkModel<LokasiListResponse>>(
stream: bloc.lokasiListStream,
builder: (context, snapshot) {
if (snapshot.hasData) {
switch (snapshot.data.status) {
case Status.loading:
return Container(
height: 130,
child: const Center(
child: CircularProgressIndicator(
valueColor: AlwaysStoppedAnimation<Color>(
greenPrimary),
),
),
);
break;
case Status.completed:
final places = snapshot.data.data.listLokasi;
return _buildLokasiWidget(places);
break;
case Status.error:
return Container(
height: 130,
child: const Center(
child: Text('Gagal untuk mendapatkan tempat'),
),
);
break;
}
return Container();
}
return Container();
}),
],
),
),
]
)
],
),
// floatingActionButton: FloatingActionButton.extended(
......@@ -217,6 +280,12 @@ class DashboardState extends State<Dashboard> {
);
}
Widget _buildKegiatanTerdekatWidget(KegiatanModel kegiatanModel) {
return Container(
child: KegiatanTerdekatButton(kegiatan:kegiatanModel)
);
}
Widget _buildGoogleMap(BuildContext context) {
if (currentLocation == null) {
return const Center(
......
import 'package:bisaGo/network/network_interface.dart';
import 'package:bisaGo/model/kegiatan.dart';
abstract class BaseKegiatanTerdekatRepository {
Future fetchKegiatanTerdekatResponse();
}
class KegiatanTerdekatRepository implements BaseKegiatanTerdekatRepository {
final NetworkInterface _network = NetworkInterface();
@override
Future fetchKegiatanTerdekatResponse() async {
final response = await _network.get(
url: '/informasi-fasilitas/lokasi/kegiatan-terdekat',isLogin: false);
var kegiatan = KegiatanModel.fromJson(response);
return kegiatan;
}
}
\ No newline at end of file
import 'package:bisaGo/config/styles.dart';
import 'package:bisaGo/model/kegiatan.dart';
import 'package:bisaGo/model/lokasi.dart';
import 'package:bisaGo/page/filter_fasilitas/postingan/detail_post_kegiatan.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
class KegiatanTerdekatButton extends StatefulWidget {
const KegiatanTerdekatButton({
this.key,
this.kegiatan,
this.onPressed,
}) : super(key: key);
final KegiatanModel kegiatan;
@override
final Key key;
final Function onPressed;
@override
_KegiatanTerdekatButtonState createState() => _KegiatanTerdekatButtonState();
}
class _KegiatanTerdekatButtonState extends State<KegiatanTerdekatButton> {
void _navigateToDetailPostKegiatanPage(BuildContext context) {
var lokasi = null; //Lokasi.getDetailsByPlaceId(widget.kegiatan.placeId);
final route =
MaterialPageRoute(builder: (_) => DetailPostKegiatanPage(
kegiatan: widget.kegiatan,
lokasi: lokasi));
Navigator.of(context).push(route);
}
@override
Widget build(BuildContext context) {
return FlatButton(
padding: EdgeInsets.zero,
onPressed: () {
_navigateToDetailPostKegiatanPage(context);
},
child: Container(
height: 40,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
widget.kegiatan.namaKegiatan,//+widget.kegiatan.deskripsi,
style: const TextStyle(
color: greenPrimary,
fontSize: 16,
fontFamily: 'Muli',
)),
Text(
'more info>',
style:TextStyle(
color: Colors.grey,
fontSize: 16,
fontFamily: 'Muli',
fontStyle: FontStyle.italic,
)
)
],
)
)
);
}
String getKegiatanStr(){
return widget.kegiatan.namaKegiatan;//+widget.kegiatan.timeStart;
}
}
\ No newline at end of file
import 'package:bisaGo/config/strings.dart';
import 'package:bisaGo/model/kegiatan.dart';
import 'package:bisaGo/model/lokasi.dart';
import 'package:bisaGo/page/dashboard/dashboard.dart';
import 'package:bisaGo/page/filter_fasilitas/postingan/detail_post_kegiatan.dart';
import 'package:bisaGo/repository/kegiatan_repository.dart';
import 'package:bisaGo/repository/kegiatan_terdekat_repository.dart';
import 'package:bisaGo/repository/lokasi_repository.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:get_it/get_it.dart';
class MockKegiatanTerdekat extends Fake implements KegiatanTerdekatRepository {
final mockKegiatan = {
'id': 2,
'nama_lokasi': 'Margo City',
'creator': 'Putri Salsabila',
'nama_kegiatan': 'Kopdar Rutin',
'penyelenggara': 'DTB Indonesia',
'narahubung': 'Putsal 08123123123',
'deskripsi': 'lorem ipsum dolor sit amet',
'time_start': '12-12-2021 06:30:00',
'time_end': '12-12-2021 09:30:00'
};
@override
Future fetchKegiatanTerdekatResponse() async {
return Future.value(KegiatanModel.fromJson(mockKegiatan));
}
}
class MockLokasi extends Fake implements LokasiRepository {
final mockLokasi = {
'name': 'Margo City',
'alamat': 'Jl. Margonda Raya No.358, Kemiri Muka, Kecamatan Beji, Kota Depok, Jawa Barat 16423',
'image': 'Margo.jpg',
'no_telp': '02178870888',
'counter': 69,
};
@override
Future<LokasiListResponse> fetchLokasi() async {
return Future.value(LokasiListResponse([Lokasi.fromJson(mockLokasi)]));
}
}
void main() {
final mockLokasi = {
'name': 'Margo City',
'alamat': 'Jl. Margonda Raya No.358, Kemiri Muka, Kecamatan Beji, Kota Depok, Jawa Barat 16423',
'image': 'Margo.jpg',
'no_telp': '02178870888',
'counter': 69,
};
final mockKegiatan = {
'id': 2,
'nama_lokasi': 'Margo City',
'creator': 'Putri Salsabila',
'nama_kegiatan': 'Kopdar Rutin',
'penyelenggara': 'DTB Indonesia',
'narahubung': 'Putsal 08123123123',
'deskripsi': 'lorem ipsum dolor sit amet',
'time_start': '12-12-2021 06:30:00',
'time_end': '12-12-2021 09:30:00'
};
setUpAll(() {
final _getIt = GetIt.instance;
_getIt.registerLazySingleton<BaseKegiatanTerdekatRepository>(
() => MockKegiatanTerdekat());
_getIt.registerLazySingleton<BaseLokasiRepository>(
() => MockLokasi());
});
testWidgets(
'Detail Post Kegiatan Page - Positive Test', (WidgetTester tester) async {
await tester.pumpWidget(MaterialApp(
home: Dashboard()
));
await tester.pump();
expect(find.byType(Dashboard), findsOneWidget);
expect(find.text('Kopdar Rutin'), findsOneWidget);
});
}
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment