Fakultas Ilmu Komputer UI

Commit fcae1899 authored by Bayukanta Iqbal Gunawan's avatar Bayukanta Iqbal Gunawan
Browse files

[GREEN] implement image picker, simpen data tag, post ke api masih wip

parent 17f73c69
Pipeline #42226 passed with stages
in 2 minutes and 54 seconds
{"_info":"// This is a generated file; do not edit or check into version control.","dependencyGraph":[{"name":"flutter_plugin_android_lifecycle","dependencies":[]},{"name":"google_maps_flutter","dependencies":["flutter_plugin_android_lifecycle"]},{"name":"location","dependencies":[]}]}
\ No newline at end of file
{"_info":"// This is a generated file; do not edit or check into version control.","dependencyGraph":[{"name":"flutter_plugin_android_lifecycle","dependencies":[]},{"name":"google_maps_flutter","dependencies":["flutter_plugin_android_lifecycle"]},{"name":"image_picker","dependencies":["flutter_plugin_android_lifecycle"]},{"name":"location","dependencies":[]}]}
\ No newline at end of file
......@@ -41,5 +41,12 @@
</array>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
<!-- image picker -->
<key>NSPhotoLibraryUsageDescription</key>
<string>Need to upload image</string>
<key>NSCameraUsageDescription</key>
<string>Need to upload image</string>
<key>NSMicrophoneUsageDescription</key>
<string>Need to upload image</string>
</dict>
</plist>
import 'package:flutter/material.dart';
import 'package:ppl_disabilitas/page/dashboard/dashboard.dart';
//import 'package:ppl_disabilitas/page/addInformasi/addInfromasi.dart';
class BisaGo extends StatelessWidget {
@override
......
import 'dart:io';
import 'package:http/http.dart' as http;
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:ppl_disabilitas/utils/customTextField.dart';
import 'package:ppl_disabilitas/utils/customDeskripsiField.dart';
import 'package:ppl_disabilitas/utils/customButton.dart';
import 'package:ppl_disabilitas/utils/validator.dart';
import 'package:smooth_star_rating/smooth_star_rating.dart';
import 'package:image_picker/image_picker.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
class AddInformasi extends StatefulWidget{
......@@ -11,6 +15,9 @@ class AddInformasi extends StatefulWidget{
}
class AddInformasiState extends State<AddInformasi> {
File _image;
var rating = 0.0;
var tag = '';
final GlobalKey<FormState> _formKey = GlobalKey<FormState>();
Map<String, bool> fasilitas = {
'Kursi Roda': false,
......@@ -19,20 +26,45 @@ class AddInformasiState extends State<AddInformasi> {
'Masjid/Mushola': false,
'Guiding Block': false,
'Bidang Miring': false,
'Teman DIsabilitas': false,
'Teman Disabilitas': false,
'Juru Bahasa Isyarat': false,
'Tongkat Disabilitas Netra':false,
'Kursi Umum Disabilitas': false,
'Tempat Parkir Disabilitas': false,
'Running Text': false,
'Tempat Parkir Biasa' : false,
};
var rating = 0.0;
Map<String, String> tags = {
'Kursi Roda': 'KD',
'Lift Disabilitas': 'LF',
'Toilet Disabilitas': 'TD',
'Masjid/Mushola': 'MM',
'Guiding Block': 'GB',
'Bidang Miring': 'BM',
'Teman Disabilitas': 'CP',
'Juru Bahasa Isyarat': 'JI',
'Tongkat Disabilitas Netra':'TN',
'Kursi Umum Disabilitas': 'KD',
'Tempat Parkir Disabilitas': 'PK',
'Running Text': 'RT',
'Tempat Parkir Biasa' : 'TB',
};
Future _getImage() async {
var image = await ImagePicker.pickImage(source: ImageSource.gallery);
setState(() {
_image = image;
print('_image : $_image');
});
}
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Tambah Informasi'),
centerTitle: true,
backgroundColor: Color(0xff3A903A),
),
......@@ -46,12 +78,40 @@ class AddInformasiState extends State<AddInformasi> {
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
SizedBox(height: 20),
CustomTextField(
Text("Foto Fasilitas",style: TextStyle(fontSize: 18),textAlign: TextAlign.left,),
GridView.count(
key: Key('Input Gambar'),
shrinkWrap: true,
primary: false,
padding: const EdgeInsets.all(10),
crossAxisSpacing: 10,
crossAxisCount: 2,
children: <Widget>[
GestureDetector(
onTap: _getImage,
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 20.0, vertical: 2.0),
decoration: const BoxDecoration(
borderRadius: BorderRadius.only(
topLeft: const Radius.circular(20.0),
topRight: const Radius.circular(20.0),
bottomLeft: const Radius.circular(20.0),
bottomRight: const Radius.circular(20.0),
),
color: Colors.black12,
),
child: _image == null ? Icon(FontAwesomeIcons.plus) : Image.file(_image),
),
)
],
),
CustomDeskripsiField(
title: 'Informasi Fasilitas',
key: Key('Text Field Informasi'),
onSaved: (input) {
},
validator: FieldValidator.validateInfo,
controller: deskripsiController,
),
SizedBox(height: 20),
Text("Tag Pencarian",style: TextStyle(fontSize: 18),textAlign: TextAlign.left,),
......@@ -88,7 +148,7 @@ class AddInformasiState extends State<AddInformasi> {
halfFilledIconData: Icons.star_half,
color: Colors.green,
borderColor: Colors.green,
spacing:0.0
spacing:0.0,
),
),
Container(
......@@ -116,10 +176,45 @@ class AddInformasiState extends State<AddInformasi> {
);
}
TextEditingController deskripsiController = TextEditingController();
addInfo(String tag, String deskripsi, String rating) async {
for(MapEntry<String, bool> me in fasilitas.entries)
if(me.value == true) tag = tag + tags[me.key] + ' ';
Map data = {
'tag': tag,
'deskripsi': deskripsi,
'rating' : rating,
};
var response = await http.post(
'http://poipole-staging.herokuapp.com/informasi-lokasi/lokasi/detail/*nama_lokasi*', body: data);
if (response.statusCode == 200) {
inputData(context);
}
else {
print(data);
inputData(context);
}
}
void inputData(BuildContext context){
var alertDialog = AlertDialog(
title: Text('Tambah Informasi berhasil'),
content: Icon(FontAwesomeIcons.checkCircle),
);
showDialog(
context: context,
builder: (BuildContext context){
return alertDialog;
}
);
}
void _validateLoginInput() async {
final FormState form = _formKey.currentState;
if(_formKey.currentState.validate()) {
form.save();
await addInfo(tag, deskripsiController.text.toString(), rating.toStringAsFixed(2));
}
}
......
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
class CustomDeskripsiField extends StatelessWidget {
CustomDeskripsiField(
{ this.title,
this.hint,
this.obsecure = false,
this.key,
this.validator,
this.controller,
this.onSaved});
final String title;
final Key key;
final FormFieldSetter<String> onSaved;
final String hint;
final bool obsecure;
final FormFieldValidator<String> validator;
final TextEditingController controller;
@override
Widget build(BuildContext context) {
return Container(
margin: EdgeInsets.symmetric(vertical: 10),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
title,
style: TextStyle(fontSize: 18),
),
SizedBox(
height: 10,
),
TextFormField(
keyboardType: TextInputType.multiline,
maxLines: null,
onSaved: onSaved,
validator: validator,
controller: controller,
autofocus: true,
obscureText: obsecure,
style: TextStyle(
fontSize: 15,
),
decoration: InputDecoration(
hintStyle: TextStyle(fontWeight: FontWeight.bold, fontSize: 15),
hintText: hint,
contentPadding: EdgeInsets.all(8.0),
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
borderSide: BorderSide(
color: Theme.of(context).primaryColor,
width: 1,
),
),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
borderSide: BorderSide(
color: Theme.of(context).primaryColor,
width: 1,
),
),
),
),
],
),
);
}
}
......@@ -61,9 +61,8 @@ class CustomTextField extends StatelessWidget {
),
),
),
],
),
);
}
}
\ No newline at end of file
}
......@@ -31,6 +31,8 @@ dependencies:
google_maps_flutter: ^0.5.24+1
flutter_dotenv: ^2.1.0
smooth_star_rating: ^1.0.4+2
image_picker: ^0.6.5
font_awesome_flutter: ^8.8.1
dev_dependencies:
flutter_test:
......
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