Fakultas Ilmu Komputer UI

Commit ce7dbd1b authored by Muhammad Rafif Elfazri's avatar Muhammad Rafif Elfazri
Browse files

Merge branch 'PBI-9-info_kegiatan' into 'development'

Pbi 9 info kegiatan

See merge request !37
parents 9d862c9a 9fdefeba
Pipeline #78596 passed with stages
in 14 minutes and 41 seconds
3.3.0:
- New feature for add kegiatan
- Fix bugs
3.2.1:
- Fix cant update fasilitas
......
import 'dart:async';
import 'package:bisaGo/model/kegiatan.dart';
import 'package:bisaGo/network/data/network_model.dart';
import 'package:bisaGo/repository/kegiatan_repository.dart';
import 'package:get_it/get_it.dart';
import 'package:http/http.dart';
import 'package:rxdart/rxdart.dart';
class KegiatanBloc {
KegiatanRepository _kegiatanRepository;
StreamController _kegiatanListController;
List<KegiatanModel> allKegiatanFromApi;
StreamSink<NetworkModel<KegiatanList>> get kegiatanListSink =>
_kegiatanListController.sink;
Stream<NetworkModel<KegiatanList>> get kegiatanListStream =>
_kegiatanListController.stream;
KegiatanBloc(String placeId) {
_kegiatanListController = BehaviorSubject<NetworkModel<KegiatanList>>();
_kegiatanRepository = GetIt.instance.get<BaseKegiatanRepository>();
fetchKegiatanList(placeId);
}
Future<void> fetchKegiatanList(String placeId) async {
kegiatanListSink.add(NetworkModel.loading('Getting Kegiatan'));
try {
final kegiatanListResponse =
await _kegiatanRepository.fetchKegiatan(placeId);
allKegiatanFromApi = List.from(kegiatanListResponse.allKegiatan);
kegiatanListSink.add(NetworkModel.completed(kegiatanListResponse));
} catch (e) {
kegiatanListSink.add(NetworkModel.error(e.toString()));
}
}
Future<dynamic> addNewKegiatan(
Map<String, dynamic> newKegiatanData, String placeId) async {
try {
return await _kegiatanRepository.createKegiatan(newKegiatanData, placeId);
} catch (e) {
return Response('Failed to register komentar', 400);
}
}
void resetKegiatanList() {
kegiatanListSink
.add(NetworkModel.completed(KegiatanList(allKegiatanFromApi)));
}
void dispose() {
_kegiatanListController?.close();
}
}
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()));
}
}
}
......@@ -5,6 +5,7 @@ import 'package:bisaGo/network/data/network_model.dart';
import 'package:bisaGo/repository/komentar_repository.dart';
import 'package:get_it/get_it.dart';
import 'package:http/http.dart';
import 'package:rxdart/rxdart.dart';
class KomentarBloc {
KomentarRepository _komentarRepository;
......@@ -17,7 +18,7 @@ class KomentarBloc {
_komentarListController.stream;
KomentarBloc(String placeId) {
_komentarListController = StreamController<NetworkModel<KomentarList>>();
_komentarListController = BehaviorSubject<NetworkModel<KomentarList>>();
_komentarRepository = GetIt.instance.get<BaseKomentarRepository>();
fetchKomentarList(placeId);
}
......
import 'dart:async';
import 'package:bisaGo/model/komentar_posting_kegiatan.dart';
import 'package:bisaGo/network/data/network_model.dart';
import 'package:bisaGo/repository/komentar_posting_kegiatan_repository.dart';
import 'package:get_it/get_it.dart';
import 'package:http/http.dart';
class KomentarPostingKegiatanBloc {
KomentarPostingKegiatanRepository _komentarPostingKegiatanRepository;
StreamController _komentarPostingKegiatanListController;
List<KomentarPostingKegiatanModel> allKomentarPositngKegiatanFromApi;
StreamSink<NetworkModel<KomentarPostingKegiatanList>>
get komentarPostingKegiatanListSink =>
_komentarPostingKegiatanListController.sink;
Stream<NetworkModel<KomentarPostingKegiatanList>>
get komentarPostingKegiatanListStream =>
_komentarPostingKegiatanListController.stream;
KomentarPostingKegiatanBloc(String placeId, int id) {
_komentarPostingKegiatanListController =
StreamController<NetworkModel<KomentarPostingKegiatanList>>();
_komentarPostingKegiatanRepository =
GetIt.instance.get<BaseKomentarPostingKegiatanRepository>();
fetchKomentarPostingKegiatanList(placeId, id);
}
Future<void> fetchKomentarPostingKegiatanList(String placeId, int id) async {
komentarPostingKegiatanListSink
.add(NetworkModel.loading('Getting Komentar'));
try {
final komentarPostingKegiatanListResponse =
await _komentarPostingKegiatanRepository.fetchKomentarPostingKegiatan(
placeId, id);
allKomentarPositngKegiatanFromApi =
List.from(komentarPostingKegiatanListResponse.allKomentarKegiatan);
komentarPostingKegiatanListSink
.add(NetworkModel.completed(komentarPostingKegiatanListResponse));
} catch (e) {
komentarPostingKegiatanListSink.add(NetworkModel.error(e.toString()));
}
}
Future<dynamic> addKomentarPostingKegiatan(
Map<String, dynamic> newKomentarPostingKegiatanData,
String placeId,
int id) async {
try {
return await _komentarPostingKegiatanRepository
.createKomentarPostingKegiatan(
newKomentarPostingKegiatanData, placeId, id);
} catch (e) {
return Response('Failed to add komentar', 400);
}
}
void resetKomentarPostingKegiatanList() {
komentarPostingKegiatanListSink.add(NetworkModel.completed(
KomentarPostingKegiatanList(allKomentarPositngKegiatanFromApi)));
}
void dispose() {
_komentarPostingKegiatanListController?.close();
}
}
......@@ -2,6 +2,6 @@ import 'package:intl/intl.dart';
class CustomSerializer {
static DateTime stringToDateTime(String date) {
return DateFormat('dd-MM-yyyy hh:mm:ss').parse(date);
return DateFormat('yyyy-MM-dd hh:mm').parse(date);
}
}
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';
import 'package:bisaGo/repository/komentar_repository.dart';
......@@ -21,10 +24,16 @@ class AppGetIt {
() => KomentarRepository());
_getIt.registerLazySingleton<BaseKomentarPostingRepository>(
() => KomentarPostingRepository());
_getIt
.registerLazySingleton<BaseLokasiRepository>(() => LokasiRepository());
_getIt.registerLazySingleton<BaseKomentarPostingKegiatanRepository>(
() => KomentarPostingKegiatanRepository());
_getIt.registerLazySingleton<BaseLokasiRepository>(
() => LokasiRepository());
_getIt.registerLazySingleton<BaseLayananRepository>(
() => LayananRepository());
_getIt.registerLazySingleton<BaseKegiatanRepository>(
() => KegiatanRepository());
_getIt.registerLazySingleton<BaseKegiatanTerdekatRepository>(
() => KegiatanTerdekatRepository());
_getIt.registerLazySingleton<BaseDynamicLinksServiceRepository>(
() => DynamicLinksServiceRepository());
}
......
import 'package:json_annotation/json_annotation.dart';
import 'package:bisaGo/config/custom_serializer.dart';
part 'kegiatan.g.dart';
@JsonSerializable()
class KegiatanList {
final List<KegiatanModel> allKegiatan;
KegiatanList(this.allKegiatan);
}
@JsonSerializable()
class KegiatanModel {
final int id;
@JsonKey(name: 'place_id')
final String placeId;
final String creator;
@JsonKey(name: 'nama_kegiatan')
final String namaKegiatan;
final String penyelenggara;
final String narahubung;
final String deskripsi;
@JsonKey(name: 'time_start', fromJson: CustomSerializer.stringToDateTime)
final DateTime timeStart;
@JsonKey(name: 'time_end', fromJson: CustomSerializer.stringToDateTime)
final DateTime timeEnd;
List<String> image;
KegiatanModel(
{
this.id,
this.placeId,
this.creator,
this.namaKegiatan,
this.penyelenggara,
this.narahubung,
this.deskripsi,
this.timeStart,
this.timeEnd,
this.image,
}
);
factory KegiatanModel.fromJson(Map<String, dynamic> json) => _$KegiatanModelFromJson(json);
Map<String, dynamic> toJson() => _$KegiatanModelToJson(this);
}
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'kegiatan.dart';
// **************************************************************************
// JsonSerializableGenerator
// **************************************************************************
KegiatanList _$KegiatanListFromJson(Map<String, dynamic> json) {
return KegiatanList(
(json['allKegiatan'] as List)
?.map((e) => e == null
? null
: KegiatanModel.fromJson(e as Map<String, dynamic>))
?.toList(),
);
}
Map<String, dynamic> _$KegiatanListToJson(KegiatanList instance) =>
<String, dynamic>{
'allKegiatan': instance.allKegiatan,
};
KegiatanModel _$KegiatanModelFromJson(Map<String, dynamic> json) {
return KegiatanModel(
id: json['id'] as int,
placeId: json['place_id'] as String,
creator: json['creator'] as String,
namaKegiatan: json['nama_kegiatan'] as String,
penyelenggara: json['penyelenggara'] as String,
narahubung: json['narahubung'] as String,
deskripsi: json['deskripsi'] as String,
timeStart: CustomSerializer.stringToDateTime(json['time_start'] as String),
timeEnd: CustomSerializer.stringToDateTime(json['time_end'] as String),
image: (json['image'] as List)?.map((e) => e as String)?.toList(),
);
}
Map<String, dynamic> _$KegiatanModelToJson(KegiatanModel instance) =>
<String, dynamic>{
'id': instance.id,
'place_id': instance.placeId,
'creator': instance.creator,
'nama_kegiatan': instance.namaKegiatan,
'penyelenggara': instance.penyelenggara,
'narahubung': instance.narahubung,
'deskripsi': instance.deskripsi,
'time_start': instance.timeStart?.toIso8601String(),
'time_end': instance.timeEnd?.toIso8601String(),
'image': instance.image,
};
import 'package:json_annotation/json_annotation.dart';
import 'package:bisaGo/config/custom_serializer.dart';
part 'komentar_posting_kegiatan.g.dart';
@JsonSerializable()
class KomentarPostingKegiatanList {
final List<KomentarPostingKegiatanModel> allKomentarKegiatan;
KomentarPostingKegiatanList(this.allKomentarKegiatan);
}
@JsonSerializable()
class KomentarPostingKegiatanModel {
final int id;
final String creator;
final String deskripsi;
@JsonKey(name: 'created', fromJson: CustomSerializer.stringToDateTime)
final DateTime created;
KomentarPostingKegiatanModel(
{this.id,
this.creator,
this.deskripsi,
this.created}
);
factory KomentarPostingKegiatanModel.fromJson(Map<String, dynamic> json) =>
_$KomentarPostingKegiatanModelFromJson(json);
Map<String, dynamic> toJson() => _$KomentarPostingKegiatanModelToJson(this);
}
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'komentar_posting_kegiatan.dart';
// **************************************************************************
// JsonSerializableGenerator
// **************************************************************************
KomentarPostingKegiatanList _$KomentarPostingKegiatanListFromJson(
Map<String, dynamic> json) {
return KomentarPostingKegiatanList(
(json['allKomentarKegiatan'] as List)
?.map((e) => e == null
? null
: KomentarPostingKegiatanModel.fromJson(e as Map<String, dynamic>))
?.toList(),
);
}
Map<String, dynamic> _$KomentarPostingKegiatanListToJson(
KomentarPostingKegiatanList instance) =>
<String, dynamic>{
'allKomentarKegiatan': instance.allKomentarKegiatan,
};
KomentarPostingKegiatanModel _$KomentarPostingKegiatanModelFromJson(
Map<String, dynamic> json) {
return KomentarPostingKegiatanModel(
id: json['id'] as int,
creator: json['creator'] as String,
deskripsi: json['deskripsi'] as String,
created: CustomSerializer.stringToDateTime(json['created'] as String),
);
}
Map<String, dynamic> _$KomentarPostingKegiatanModelToJson(
KomentarPostingKegiatanModel instance) =>
<String, dynamic>{
'id': instance.id,
'creator': instance.creator,
'deskripsi': instance.deskripsi,
'created': instance.created?.toIso8601String(),
};
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/page/filter_fasilitas/postingan/detail_post_kegiatan.dart';
import 'package:bisaGo/repository/kegiatan_repository.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 +36,7 @@ class DashboardState extends State<Dashboard> {
Set<Marker> markers = {};
LokasiResponseBloc bloc = LokasiResponseBloc();
KegiatanTerdekatBloc blocKegiatanTerdekat = KegiatanTerdekatBloc();
@override
void initState() {
......@@ -84,102 +90,154 @@ 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: 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)),
),
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(
child: const Center(
child: LinearProgressIndicator(
valueColor: AlwaysStoppedAnimation<Color>(
greenPrimary),
)));
break;
case Status.completed:
final kegiatanTerdekat = snapshot.data.data;
return _buildKegiatanTerdekatWidget(
kegiatanTerdekat);
break;
case Status.error:
return Container(
child: const Center(
child: Text(
'Tidak ada kegiatan dalam waktu dekat',
style: TextStyle(
color: greenPrimary,
fontSize: 16,
fontFamily: 'Muli',
)),
));
break;
}
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(
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,
fontSize: 20,
fontFamily: 'Muli',
fontWeight: FontWeight.w700),
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: 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),