Fakultas Ilmu Komputer UI

Commit 3464f6b8 authored by Putri Salsabila's avatar Putri Salsabila
Browse files

[WIP] Create Ubah Kegiatan form

parent 9e6a6916
Pipeline #81474 passed with stages
in 13 minutes and 28 seconds
...@@ -314,7 +314,7 @@ class _AddKegiatanState extends State<AddKegiatan> { ...@@ -314,7 +314,7 @@ class _AddKegiatanState extends State<AddKegiatan> {
validator: FieldValidator.validateInfo, validator: FieldValidator.validateInfo,
controller: deskripsiController, controller: deskripsiController,
style: const TextStyle( style: const TextStyle(
fontSize: 18, fontSize: 15,
), ),
decoration: InputDecoration( decoration: InputDecoration(
hintStyle: const TextStyle( hintStyle: const TextStyle(
......
...@@ -22,6 +22,7 @@ import 'package:shared_preferences/shared_preferences.dart'; ...@@ -22,6 +22,7 @@ import 'package:shared_preferences/shared_preferences.dart';
import 'package:url_launcher/url_launcher.dart'; import 'package:url_launcher/url_launcher.dart';
import '../fasilitas.dart'; import '../fasilitas.dart';
import '../update_kegiatan.dart';
class DetailPostKegiatanPage extends StatefulWidget { class DetailPostKegiatanPage extends StatefulWidget {
final Lokasi lokasi; final Lokasi lokasi;
...@@ -89,7 +90,7 @@ class _DetailPostKegiatanPageState extends State<DetailPostKegiatanPage> { ...@@ -89,7 +90,7 @@ class _DetailPostKegiatanPageState extends State<DetailPostKegiatanPage> {
mainAxisAlignment: MainAxisAlignment.spaceBetween, mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [ children: [
Container( Container(
width: MediaQuery.of(context).size.width * 0.8, width: MediaQuery.of(context).size.width * 0.7,
child: Column( child: Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[ children: <Widget>[
...@@ -111,35 +112,35 @@ class _DetailPostKegiatanPageState extends State<DetailPostKegiatanPage> { ...@@ -111,35 +112,35 @@ class _DetailPostKegiatanPageState extends State<DetailPostKegiatanPage> {
], ],
), ),
), ),
// PopupMenuButton( PopupMenuButton(
// key: const Key('Button Ubah Informasi'), key: const Key('Button Ubah Kegiatan'),
// elevation: 4.0, elevation: 4.0,
// offset: const Offset(0.0, 40.0), offset: const Offset(0.0, 40.0),
// itemBuilder: (BuildContext context) { itemBuilder: (BuildContext context) {
// final choices = ['Ubah Informasi']; final choices = ['Ubah Kegiatan'];
// return choices.map((String choice) { return choices.map((String choice) {
// return PopupMenuItem( return PopupMenuItem(
// key: Key(choice), key: Key(choice),
// child: ElevatedButton( child: ElevatedButton(
// style: ButtonStyle( style: ButtonStyle(
// padding: MaterialStateProperty.all( padding: MaterialStateProperty.all(
// EdgeInsets.symmetric( EdgeInsets.symmetric(
// vertical: 0, horizontal: 0)), vertical: 0, horizontal: 0)),
// backgroundColor: backgroundColor:
// MaterialStateProperty.all(Colors.white), MaterialStateProperty.all(Colors.white),
// foregroundColor: foregroundColor:
// MaterialStateProperty.all(Colors.black), MaterialStateProperty.all(Colors.black),
// elevation: MaterialStateProperty.all(0)), elevation: MaterialStateProperty.all(0)),
// onPressed: _updateInformasi, onPressed: updateKegiatan,
// child: SizedBox( child: SizedBox(
// width: double.infinity, width: double.infinity,
// child: Text(choice), child: Text(choice),
// ), ),
// ), ),
// ); );
// }).toList(); }).toList();
// }, },
// ), ),
], ],
), ),
), ),
...@@ -659,19 +660,20 @@ class _DetailPostKegiatanPageState extends State<DetailPostKegiatanPage> { ...@@ -659,19 +660,20 @@ class _DetailPostKegiatanPageState extends State<DetailPostKegiatanPage> {
return initials; return initials;
} }
// Future<void> _updateInformasi() async { Future<void> updateKegiatan() async {
// final sharedPreferences = await SharedPreferences.getInstance(); final sharedPreferences = await SharedPreferences.getInstance();
// if (sharedPreferences.getString('token') == null) { if (sharedPreferences.getString('token') == null) {
// await Navigator.of(context).pushAndRemoveUntil( await Navigator.of(context).pushAndRemoveUntil(
// MaterialPageRoute(builder: (BuildContext context) => const Login()), MaterialPageRoute(builder: (BuildContext context) => const Login()),
// (Route<dynamic> route) => false); (Route<dynamic> route) => false);
// } else { } else {
// await Navigator.of(context).push(MaterialPageRoute( await Navigator.of(context).push(MaterialPageRoute(
// builder: (BuildContext context) => UpdateInformasi( builder: (BuildContext context) => UpdateKegiatan(
// komentar: widget.komentar, lokasi: widget.lokasi) // ganti modelnya di update_informasi.dart kegiatan: widget.kegiatan, lokasi: widget.lokasi
// )); )
// } ));
// } }
}
@override @override
void dispose() { void dispose() {
......
import 'package:bisaGo/component/bisago_appbar.dart';
import 'package:bisaGo/config/strings.dart';
import 'package:bisaGo/config/styles.dart';
import 'package:bisaGo/model/kegiatan.dart'; import 'package:bisaGo/model/kegiatan.dart';
import 'package:bisaGo/model/lokasi.dart'; import 'package:bisaGo/model/lokasi.dart';
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:flutter/cupertino.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:image_picker/image_picker.dart';
import 'package:intl/intl.dart'; import 'package:intl/intl.dart';
import 'package:material_design_icons_flutter/material_design_icons_flutter.dart';
import 'package:multi_image_picker/multi_image_picker.dart'; import 'package:multi_image_picker/multi_image_picker.dart';
import 'package:permission_handler/permission_handler.dart';
class UpdateKegiatan extends StatefulWidget { class UpdateKegiatan extends StatefulWidget {
UpdateKegiatan({ UpdateKegiatan({
Key key, Key key,
@required this.kegiatan, @required this.kegiatan,
@required this.placeId, @required this.lokasi,
}) : super(key: key); }) : super(key: key);
final KegiatanModel kegiatan; final KegiatanModel kegiatan;
final Lokasi placeId; final Lokasi lokasi;
@override @override
_UpdateKegiatanState createState() => _UpdateKegiatanState(); _UpdateKegiatanState createState() => _UpdateKegiatanState();
} }
class _UpdateKegiatanState extends State<UpdateKegiatan> { class _UpdateKegiatanState extends State<UpdateKegiatan> {
// final GlobalKey<FormState> _formKey = GlobalKey<FormState>(); final GlobalKey<FormState> _formKey = GlobalKey<FormState>();
TextEditingController namaKegiatanController = TextEditingController(); TextEditingController namaKegiatanController = TextEditingController();
TextEditingController penyelenggaraController = TextEditingController(); TextEditingController penyelenggaraController = TextEditingController();
...@@ -38,11 +51,489 @@ class _UpdateKegiatanState extends State<UpdateKegiatan> { ...@@ -38,11 +51,489 @@ class _UpdateKegiatanState extends State<UpdateKegiatan> {
void initState() { void initState() {
super.initState(); super.initState();
// TODO: write init state i guess // TODO: write init state i guess
namaKegiatanController = TextEditingController(text: widget.kegiatan.namaKegiatan);
penyelenggaraController = TextEditingController(text: widget.kegiatan.penyelenggara);
deskripsiController = TextEditingController(text: widget.kegiatan.deskripsi);
namaKontakController = TextEditingController(text: widget.kegiatan.namaKontak);
nomorKontakController = TextEditingController(text: widget.kegiatan.nomorKontak);
linkController = TextEditingController(text: widget.kegiatan.links);
// tanggalKegiatan = '${DateFormat('${widget.kegiatan.timeStart}').format(DateTime.now())}';
tanggalKegiatan = '${widget.kegiatan.timeStart}';
zonaCurrent = widget.kegiatan.zonaWaktu;
} }
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
// TODO: implement build return Scaffold(
throw UnimplementedError(); appBar: PreferredSize(
preferredSize: const Size.fromHeight(55),
child: BisaGoAppBar(
title: 'Ubah Kegiatan',
leading: InkWell(
onTap: () => Navigator.pop(context, 'Take me back'),
child: const Icon(Icons.arrow_back_ios),
),
),
),
body: SingleChildScrollView(
child: Form(
key: _formKey,
child: Stack(
children: <Widget>[
Container(
key: const Key('Body Add Kegiatan Page'),
alignment: Alignment.topCenter,
padding: EdgeInsets.only(
top: MediaQuery.of(context).size.height * .04,
left: tripleSpace,
right: tripleSpace,
bottom: tripleSpace),
child: ListBody(
children: <Widget>[
namaLokasi(),
namaKegiatanField(),
deskripsiField(),
penyelenggaraField(),
namaKontakField(),
nomorKontakField(),
linkField(),
tanggalKegiatanField(),
fotoField(),
_showImagePreview(),
simpanButton(),
],
),
),
],
),
),
),
);
// throw UnimplementedError();
}
Future<void> _submitData() async {
// TODO: implement submit data
// final form = _formKey.currentState;
// if (_formKey.currentState.validate()) {
// form.save();
// }
}
void successDialog(BuildContext context) {
const alertDialog = AlertDialog(
title: Text('Ubah kegiatan berhasil'),
content: Icon(FontAwesomeIcons.checkCircle),
);
showDialog(
context: context,
builder: (BuildContext context) {
return alertDialog;
});
}
void failedDialog(BuildContext context, String message) {
var newMessage = message;
if (message == 'default') {
newMessage = 'Gagal mengubah kegiatan';
}
final alertDialog = AlertDialog(
title: Text(newMessage),
content: const Icon(
FontAwesomeIcons.exclamationCircle,
),
);
showDialog(
context: context,
builder: (BuildContext context) {
return alertDialog;
});
}
final picker = ImagePicker();
Future<void> pickImages() async {
var resultList = <Asset>[];
await _getStoragePermission();
await _getCameraPermission();
try {
if (permissionGranted) {
resultList = await MultiImagePicker.pickImages(
maxImages: 50,
enableCamera: true,
selectedAssets: images,
materialOptions: MaterialOptions(
actionBarTitle: widget.lokasi.name, // tdnya widget.nama
actionBarColor: '#ff3A903A',
statusBarColor: '#ff347D34',
useDetailsView: true,
startInAllView: true,
textOnNothingSelected: 'Tidak ada gambar yang dipilih',
),
);
setState(() {
images = resultList;
});
} else {
await openAppSettings();
}
} on Exception catch (e) {
print(e);
}
}
Future _getStoragePermission() async {
if (await Permission.storage.request().isGranted) {
setState(() {
permissionGranted = true;
});
} else if (await Permission.storage.request().isPermanentlyDenied) {
await openAppSettings();
} else if (await Permission.storage.request().isDenied) {
setState(() {
permissionGranted = false;
});
}
}
Future _getCameraPermission() async {
if (await Permission.camera.request().isGranted) {
setState(() {
permissionGranted = true;
});
} else if (await Permission.camera.request().isPermanentlyDenied) {
await openAppSettings();
} else if (await Permission.camera.request().isDenied) {
setState(() {
permissionGranted = false;
});
}
}
Widget namaLokasi() {
return Padding(
padding: const EdgeInsets.only(bottom: doubleSpace),
child: Text(
widget.lokasi.name,
style: const TextStyle(
fontSize: 28,
fontWeight: FontWeight.w800,
color: Colors.black,
fontFamily: 'Comfortaa',
),
),
);
}
Widget namaKegiatanField() {
return CustomTextField(
title: 'Nama Kegiatan',
hint: 'Masukkan nama kegiatan',
required: true,
key: const Key('Text Field Nama'),
validator: FieldValidator.validateName,
controller: namaKegiatanController,
);
}
Widget deskripsiField() {
return Container(
margin: const EdgeInsets.symmetric(vertical: 10),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Padding(
padding: const EdgeInsets.only(bottom: 10),
child: RichText(
key: Key('Deskripsi Kegiatan'),
text: TextSpan(
text: 'Deskripsi Kegiatan',
style: const TextStyle(
fontSize: 18, color: Colors.black, fontFamily: 'Muli'),
children: <TextSpan>[
const TextSpan(text: '*', style: TextStyle(color: red)),
],
),
),
),
TextFormField(
key: const Key('Text Field Deskripsi'),
keyboardType: TextInputType.multiline,
maxLines: null,
minLines: 3,
validator: FieldValidator.validateInfo,
controller: deskripsiController,
style: const TextStyle(
fontSize: 15,
),
decoration: InputDecoration(
hintStyle: const TextStyle(
fontWeight: FontWeight.bold, fontSize: 15),
hintText: 'Tulis deskripsi...',
contentPadding: const EdgeInsets.all(8.0),
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
borderSide: BorderSide(
color: Theme.of(context).primaryColor,
),
),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
borderSide: BorderSide(
color: Theme.of(context).primaryColor,
),
),
),
),
]));
}
Widget penyelenggaraField() {
return CustomTextField(
title: 'Penyelenggara',
hint: 'Masukkan nama penyelenggara',
required: true,
key: const Key('Text Field Penyelenggara'),
validator: FieldValidator.validateName,
controller: penyelenggaraController,
);
}
Widget namaKontakField() {
return CustomTextField(
title: 'Nama Narahubung',
hint: 'Masukkan nama narahubung',
required: false,
key: const Key('Text Field Nama Narahubung'),
controller: namaKontakController,
);
}
Widget nomorKontakField() {
return CustomTextField(
title: 'Nomor Telepon Narahubung',
hint: 'Masukkan nomor telepon narahubung',
required: true,
key: const Key('Text Field Nomor Telepon Narahubung'),
validator: FieldValidator.validateInfo,
controller: nomorKontakController,
);
}
Widget linkField() {
return CustomTextField(
title: 'Link Kegiatan',
hint: 'Masukkan link kegiatan (jika ada)',
required: false,
key: const Key('Text Field Link Kegiatan'),
controller: linkController,
);
}
Widget tanggalKegiatanField() {
return Container(
padding: const EdgeInsets.only(bottom: 16),
child: Column(
children: <Widget>[
SizedBox(height: 10.0),
Padding(
padding: const EdgeInsets.fromLTRB(0, 0, 70, 10),
child: const Text(
'Tanggal & Waktu Kegiatan',
style: TextStyle(fontSize: 18),
textAlign: TextAlign.left,
),
),
Row(children: <Widget>[
// SizedBox(
// width: 186.0,
Expanded(
child: TextButton(
key: const Key('Button Tanggal & Waktu Kegiatan'),
style: TextButton.styleFrom(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10.0)),
padding: const EdgeInsets.all(13.0),
backgroundColor: Colors.transparent,
side: BorderSide(color: greenPrimary),
),
onPressed: () {
DatePicker.showDateTimePicker(
context,
currentTime: DateTime.parse(tanggalKegiatan),
onChanged: (date) {
setState(() {
tanggalKegiatan =
'${DateFormat('yyyy-MM-dd HH:mm').format(date)}';
});
},
);
},
child: Row(children: <Widget>[
Icon(
Icons.calendar_today,
size: 20,
color: Colors.green,
),
SizedBox(width: 10.0),
Text(
tanggalKegiatan,
style:
const TextStyle(fontSize: 15.0, color: Colors.black),
),
])
),
),
SizedBox(width: 15.0),
zonaWaktuChoice(),
]),
],
),
);
}
Widget zonaWaktuChoice() {
return DropdownButton<String>(
value: zonaCurrent,
underline: Container(
height: 1,
color: Colors.green,
),
items: zonaWaktu.map((String zona) {
return DropdownMenuItem<String>(
value: zona,
child: Text(zona),
);
}).toList(),
onChanged: (String zonaSelected) {
setState(() {
zonaCurrent = zonaSelected;
});
},
);
}
Widget fotoField() {
return Padding(
padding: const EdgeInsets.only(bottom: 16),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Padding(
padding: const EdgeInsets.only(right: doubleSpace),
child: const Text(
'Foto',
style: TextStyle(fontSize: 18),
textAlign: TextAlign.left,
),
),
TextButton(
key: const Key('Button Input Foto Gallery'),
style: TextButton.styleFrom(padding: EdgeInsets.zero),
onPressed: () async {
await pickImages();
},
child: Container(
// width: MediaQuery.of(context).size.width * 0.35,
padding: const EdgeInsets.all(9.0),
alignment: Alignment.centerLeft,
decoration: BoxDecoration(
boxShadow: regularShadow,
borderRadius: BorderRadius.circular(10.0),
color: greenPrimary),