Fakultas Ilmu Komputer UI

Commit 6549e425 authored by jovi_013's avatar jovi_013
Browse files

[GREEN] Implement carousel for kegiatan & bug fix

parent 667b0d72
Pipeline #77152 failed with stages
in 2 minutes and 20 seconds
...@@ -2,6 +2,6 @@ import 'package:intl/intl.dart'; ...@@ -2,6 +2,6 @@ import 'package:intl/intl.dart';
class CustomSerializer { class CustomSerializer {
static DateTime stringToDateTime(String date) { static DateTime stringToDateTime(String date) {
return DateFormat('dd-MM-yyyy hh:mm:ss').parse(date); return DateFormat('yyyy-MM-dd hh:mm').parse(date);
} }
} }
...@@ -20,10 +20,11 @@ class KegiatanModel { ...@@ -20,10 +20,11 @@ class KegiatanModel {
final String penyelenggara; final String penyelenggara;
final String narahubung; final String narahubung;
final String deskripsi; final String deskripsi;
// @JsonKey(name: 'time_start', fromJson: CustomSerializer.stringToDateTime) @JsonKey(name: 'time_start', fromJson: CustomSerializer.stringToDateTime)
// final DateTime timeStart; final DateTime timeStart;
// @JsonKey(name: 'time_end', fromJson: CustomSerializer.stringToDateTime) @JsonKey(name: 'time_end', fromJson: CustomSerializer.stringToDateTime)
// final DateTime timeEnd; final DateTime timeEnd;
List<String> image;
KegiatanModel( KegiatanModel(
{ {
...@@ -34,8 +35,9 @@ class KegiatanModel { ...@@ -34,8 +35,9 @@ class KegiatanModel {
this.penyelenggara, this.penyelenggara,
this.narahubung, this.narahubung,
this.deskripsi, this.deskripsi,
// this.timeStart, this.timeStart,
// this.timeEnd this.timeEnd,
this.image,
} }
); );
......
...@@ -30,6 +30,9 @@ KegiatanModel _$KegiatanModelFromJson(Map<String, dynamic> json) { ...@@ -30,6 +30,9 @@ KegiatanModel _$KegiatanModelFromJson(Map<String, dynamic> json) {
penyelenggara: json['penyelenggara'] as String, penyelenggara: json['penyelenggara'] as String,
narahubung: json['narahubung'] as String, narahubung: json['narahubung'] as String,
deskripsi: json['deskripsi'] 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(),
); );
} }
...@@ -42,4 +45,7 @@ Map<String, dynamic> _$KegiatanModelToJson(KegiatanModel instance) => ...@@ -42,4 +45,7 @@ Map<String, dynamic> _$KegiatanModelToJson(KegiatanModel instance) =>
'penyelenggara': instance.penyelenggara, 'penyelenggara': instance.penyelenggara,
'narahubung': instance.narahubung, 'narahubung': instance.narahubung,
'deskripsi': instance.deskripsi, 'deskripsi': instance.deskripsi,
'time_start': instance.timeStart?.toIso8601String(),
'time_end': instance.timeEnd?.toIso8601String(),
'image': instance.image,
}; };
...@@ -29,7 +29,7 @@ KomentarPostingKegiatanModel _$KomentarPostingKegiatanModelFromJson( ...@@ -29,7 +29,7 @@ KomentarPostingKegiatanModel _$KomentarPostingKegiatanModelFromJson(
id: json['id'] as int, id: json['id'] as int,
creator: json['creator'] as String, creator: json['creator'] as String,
deskripsi: json['deskripsi'] as String, deskripsi: json['deskripsi'] as String,
created: CustomSerializer.stringToDateTime(json['created'] as String) created: CustomSerializer.stringToDateTime(json['created'] as String),
); );
} }
......
...@@ -2,6 +2,7 @@ import 'package:bisaGo/config/styles.dart'; ...@@ -2,6 +2,7 @@ import 'package:bisaGo/config/styles.dart';
import 'package:bisaGo/model/lokasi.dart'; import 'package:bisaGo/model/lokasi.dart';
import 'package:bisaGo/model/kegiatan.dart'; import 'package:bisaGo/model/kegiatan.dart';
import 'package:bisaGo/page/filter_fasilitas/postingan/detail_post_kegiatan.dart'; import 'package:bisaGo/page/filter_fasilitas/postingan/detail_post_kegiatan.dart';
import 'package:carousel_slider/carousel_slider.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
// import 'package:bisaGo/component/image_holder.dart'; // import 'package:bisaGo/component/image_holder.dart';
...@@ -33,8 +34,9 @@ class _KegiatanState extends State<Kegiatan> { ...@@ -33,8 +34,9 @@ class _KegiatanState extends State<Kegiatan> {
penyelenggara: widget.kegiatan.penyelenggara, penyelenggara: widget.kegiatan.penyelenggara,
narahubung: widget.kegiatan.narahubung, narahubung: widget.kegiatan.narahubung,
deskripsi: widget.kegiatan.deskripsi, deskripsi: widget.kegiatan.deskripsi,
// timeStart: widget.kegiatan.timeStart, timeStart: widget.kegiatan.timeStart,
// timeEnd: widget.kegiatan.timeEnd, timeEnd: widget.kegiatan.timeEnd,
image: widget.kegiatan.image,
), ),
) )
)); ));
...@@ -72,12 +74,55 @@ class _KegiatanState extends State<Kegiatan> { ...@@ -72,12 +74,55 @@ class _KegiatanState extends State<Kegiatan> {
Container( Container(
margin: const EdgeInsets.only(bottom: regularSpace), margin: const EdgeInsets.only(bottom: regularSpace),
child: SizedBox( child: SizedBox(
width: MediaQuery.of(context).size.width,
height: 160, height: 160,
// child: ImageHolder( child: CarouselSlider(
// url: widget.kegiatan.image, options: CarouselOptions(
// fasilitas: widget.kegiatan.tag aspectRatio: 1.0,
// ) enlargeCenterPage: true,
child: Text('Image here'), enableInfiniteScroll: false,
initialPage: 0,
autoPlay: true,
),
items: widget.kegiatan.image.map((item) => Container(
child: Container(
child: ClipRRect(
borderRadius: BorderRadius.all(Radius.circular(20)),
child: Stack(
children: <Widget>[
Image.network(item, fit: BoxFit.cover, width: 1000.0),
Positioned(
bottom: 0.0,
left: 0.0,
right: 0.0,
child: Container(
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [
Color.fromARGB(200, 0, 0, 0),
Color.fromARGB(0, 0, 0, 0)
],
begin: Alignment.bottomCenter,
end: Alignment.topCenter,
),
),
padding: EdgeInsets.symmetric(vertical: 10.0, horizontal: 20.0),
child: Text(
'#${widget.kegiatan.image.indexOf(item)+1}',
style: TextStyle(
color: Colors.white,
fontSize: 20.0,
fontWeight: FontWeight.bold,
),
),
),
),
],
)
),
),
)).toList(),
),
) )
), ),
Row( Row(
...@@ -103,5 +148,5 @@ class _KegiatanState extends State<Kegiatan> { ...@@ -103,5 +148,5 @@ class _KegiatanState extends State<Kegiatan> {
], ],
), ),
)); ));
} }
} }
\ No newline at end of file
import 'package:bisaGo/flavor/flavor.dart';
import 'package:bisaGo/model/kegiatan.dart'; import 'package:bisaGo/model/kegiatan.dart';
import 'package:bisaGo/network/network_interface.dart'; import 'package:bisaGo/network/network_interface.dart';
abstract class BaseKegiatanRepository { abstract class BaseKegiatanRepository {
Future<KegiatanList> fetchKegiatan(String placeId); Future<KegiatanList> fetchKegiatan(String placeId);
Future<List<String>> fetchImages(String placeId, int id);
} }
class KegiatanRepository implements BaseKegiatanRepository { class KegiatanRepository implements BaseKegiatanRepository {
...@@ -13,8 +15,28 @@ class KegiatanRepository implements BaseKegiatanRepository { ...@@ -13,8 +15,28 @@ class KegiatanRepository implements BaseKegiatanRepository {
final url = '/informasi-fasilitas/lokasi/list-kegiatan/$placeId'; final url = '/informasi-fasilitas/lokasi/list-kegiatan/$placeId';
final response = await _network.get(url: url, isLogin: false); final response = await _network.get(url: url, isLogin: false);
final data = response.values.toList().reversed.toList(); final data = response.values.toList().reversed.toList();
return KegiatanList(data var allKegiatan = [];
.map<KegiatanModel>((kegiatan) => KegiatanModel.fromJson(kegiatan))
.toList()); for (var _index = 0; _index < data.length; _index++) {
var kegiatan = KegiatanModel.fromJson(data[_index]);
kegiatan.image = await fetchImages(kegiatan.placeId, kegiatan.id);
allKegiatan.add(kegiatan);
}
allKegiatan = allKegiatan.cast<KegiatanModel>();
return KegiatanList(allKegiatan);
}
@override
Future<List<String>> fetchImages(String placeId, int id) async {
final url = '/informasi-fasilitas/lokasi/list-foto-kegiatan/$placeId/$id';
final response = await _network.get(url: url, isLogin: false);
var allImages = [];
for (var _index=0; _index < response.length; _index++) {
var fotoUrl = ApiFlavor.getBaseUrl() + response.values.toList()[_index]['foto'];
allImages.add(fotoUrl);
}
allImages = allImages.cast<String>();
return allImages;
} }
} }
\ 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