Fakultas Ilmu Komputer UI

Commit e019f2b8 authored by jovi_013's avatar jovi_013
Browse files

[GREEN] Implement update image

parent 3cf2abbf
......@@ -11,12 +11,12 @@ import 'package:bisaGo/utils/custom_button.dart';
import 'package:bisaGo/utils/custom_text_field.dart';
import 'package:bisaGo/utils/validator.dart';
import 'package:carousel_slider/carousel_slider.dart';
// import 'package:dio/dio.dart';
import 'package:dio/dio.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_datetime_picker/flutter_datetime_picker.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
// import 'package:http_parser/http_parser.dart';
import 'package:http_parser/http_parser.dart';
import 'package:image_picker/image_picker.dart';
import 'package:intl/intl.dart';
import 'package:material_design_icons_flutter/material_design_icons_flutter.dart';
......@@ -46,7 +46,9 @@ class _UpdateKegiatanState extends State<UpdateKegiatan> {
TextEditingController namaKontakController = TextEditingController();
TextEditingController nomorKontakController = TextEditingController();
TextEditingController linkController = TextEditingController();
List<String> oldKegiatanImages;
List<String> newKegiatanImages;
List<dynamic> allKegiatanImages = [];
String tanggalKegiatan =
'${DateFormat('yyyy-MM-dd HH:mm').format(DateTime.now())}';
String zonaCurrent = 'WIB';
......@@ -65,6 +67,8 @@ class _UpdateKegiatanState extends State<UpdateKegiatan> {
tanggalKegiatan = '${DateFormat('yyyy-MM-dd HH:mm').format(widget.kegiatan.timeStart)}';
zonaCurrent = widget.kegiatan.zonaWaktu;
// TODO: write init images
oldKegiatanImages = widget.kegiatan.images;
allKegiatanImages.addAll(oldKegiatanImages);
// images = MultiImagePicker.pickImages(widget.kegiatan.images) as List<Asset>;
// images = widget.kegiatan.images as List<Asset>;
// images = images.map<Asset>(widget.kegiatan.images).toList();
......@@ -141,23 +145,25 @@ class _UpdateKegiatanState extends State<UpdateKegiatan> {
);
var newKegiatanData = newKegiatan.toJson();
newKegiatanData['place_id'] = widget.lokasi;
// var multipartImageList = <MultipartFile>[];
// if (images != null) {
// for (var asset in images) {
// var byteData = await asset.getByteData();
// var imageData = byteData.buffer.asUint8List();
// var multipartFile = MultipartFile.fromBytes(
// imageData,
// filename: asset.name,
// contentType: MediaType('image', 'jpeg'),
// );
// multipartImageList.add(multipartFile);
// }
// newKegiatanData['images'] = multipartImageList;
// }
newKegiatanData['images'] = [];
newKegiatanData['place_id'] = widget.lokasi.placeId;
var multipartImageList = <MultipartFile>[];
if (images != null) {
for (var asset in images) {
var byteData = await asset.getByteData();
var imageData = byteData.buffer.asUint8List();
var multipartFile = MultipartFile.fromBytes(
imageData,
filename: asset.name,
contentType: MediaType('image', 'jpeg'),
);
multipartImageList.add(multipartFile);
}
allKegiatanImages.addAll(multipartImageList);
newKegiatanData['images'] = multipartImageList;
}
newKegiatanData['images'] ??= [];
if (newKegiatanData['zona_waktu'] == 'WIT') {
newKegiatanData['time_start'] = newKegiatanData['time_start']+'+0900';
......@@ -244,6 +250,7 @@ class _UpdateKegiatanState extends State<UpdateKegiatan> {
);
setState(() {
images = resultList;
allKegiatanImages.addAll(images);
});
} else {
await openAppSettings();
......@@ -546,10 +553,32 @@ class _UpdateKegiatanState extends State<UpdateKegiatan> {
}
Widget _showImagePreview() {
return images.isEmpty ? const SizedBox(height: 0) : carousel();
if (oldKegiatanImages.isEmpty) {
return SizedBox(height: 0);
} else {
return carousel(allKegiatanImages);
}
}
Widget carousel() {
Widget _showImage(dynamic item) {
print('------------------');
print(item);
print('------------------');
if (item is Asset) {
print(item.runtimeType);
return AssetThumb(
asset: item,
width: MediaQuery.of(context).size.height.toInt(),
height: MediaQuery.of(context).size.width.toInt(),
);
} else if (item is String) {
return Image.network(item, fit: BoxFit.cover, width: 1000.0);
} else {
return SizedBox(height: 0);
}
}
Widget carousel(List<dynamic> _images) {
return SizedBox(
width: MediaQuery.of(context).size.width,
height: 160,
......@@ -561,18 +590,14 @@ class _UpdateKegiatanState extends State<UpdateKegiatan> {
initialPage: 0,
autoPlay: true,
),
items: images
items: _images
.map(
(item) => Container(
child: ClipRRect(
borderRadius: BorderRadius.all(Radius.circular(20)),
child: Stack(
children: <Widget>[
AssetThumb(
asset: item,
width: MediaQuery.of(context).size.height.toInt(),
height: MediaQuery.of(context).size.width.toInt(),
),
_showImage(item),
Positioned(
bottom: 0.0,
left: 0.0,
......@@ -591,7 +616,7 @@ class _UpdateKegiatanState extends State<UpdateKegiatan> {
padding: EdgeInsets.symmetric(
vertical: 10.0, horizontal: 20.0),
child: Text(
'#${images.indexOf(item) + 1}',
'#${_images.indexOf(item) + 1}',
style: TextStyle(
color: Colors.white,
fontSize: 20.0,
......
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