Skip to content

Commit

Permalink
Lapor Pangkalan almost done
Browse files Browse the repository at this point in the history
  • Loading branch information
mdaffailhami committed Jun 28, 2024
1 parent 36f5717 commit 7703cb8
Show file tree
Hide file tree
Showing 3 changed files with 205 additions and 2 deletions.
176 changes: 176 additions & 0 deletions lib/components/laporan_modal_bottom_sheet.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
import 'dart:convert';

import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_dotenv/flutter_dotenv.dart';
import 'package:gasku/cubits/pengguna_masuk.dart';
import 'package:gasku/models/pangkalan.dart';
import 'package:gasku/models/pengguna.dart';
import 'package:gasku/utils/show_loading_screen.dart';
import 'package:http/http.dart' as http;
import 'package:intl/intl.dart';

enum JenisLaporan {
penjualanDiAtasHET('Penjualan di atas HET'),
penyelewenganPenyaluran('Penyelewengan penyaluran'),
pengoplosan('Pengoplosan'),
lainnya('Lainnya');

const JenisLaporan(this.value);
final String value;
}

class MyLaporanModalBottomSheet extends StatefulWidget {
const MyLaporanModalBottomSheet({super.key, required this.pangkalan});

final Pangkalan pangkalan;

@override
State<MyLaporanModalBottomSheet> createState() =>
_MyLaporanModalBottomSheetState();
}

class _MyLaporanModalBottomSheetState extends State<MyLaporanModalBottomSheet> {
JenisLaporan? _jenisLaporan;
String _deskripsi = '';

Future<void> _onSubmit() async {
showLoadingScreen(context);

final Pengguna pengguna = context.read<PenggunaMasukCubit>().state!;

final url = '${dotenv.env['SERVER_URL']}/lapor-pangkalan/';

final reqBody = {
"nim_pelapor": pengguna.nik,
"nama_pelapor": pengguna.nama,
"id_pangkalan": widget.pangkalan.id,
"nama_pangkalan": widget.pangkalan.nama,
"tanggal": DateFormat('dd-MM-yyyy').format(DateTime.now()).toString(),
"deskripsi": _deskripsi
};

try {
final Map<String, dynamic> resBody = jsonDecode((await http.post(
Uri.parse(url),
headers: <String, String>{
'Content-Type': 'application/json; charset=UTF-8',
},
body: jsonEncode(reqBody),
))
.body);

Navigator.of(context).pop();
Navigator.of(context).pop();

if (resBody['status'] == 'failed') {
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text(resBody['message']),
backgroundColor: Theme.of(context).colorScheme.primary,
action: SnackBarAction(
label: 'Tutup',
onPressed: () =>
ScaffoldMessenger.of(context).hideCurrentSnackBar(),
),
));
} else {
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text('Laporan terkirim'),
backgroundColor: Theme.of(context).colorScheme.primary,
action: SnackBarAction(
label: 'Tutup',
onPressed: () =>
ScaffoldMessenger.of(context).hideCurrentSnackBar(),
),
));
}
} catch (e) {
Navigator.of(context).pop();
Navigator.of(context).pop();

ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text(e.toString()),
backgroundColor: Theme.of(context).colorScheme.primary,
action: SnackBarAction(
label: 'Tutup',
onPressed: () => ScaffoldMessenger.of(context).hideCurrentSnackBar(),
),
));
}
}

@override
Widget build(BuildContext context) {
return Padding(
padding:
EdgeInsets.only(bottom: MediaQuery.of(context).viewInsets.bottom),
child: Container(
// height: 300,
width: double.infinity,
padding: const EdgeInsets.symmetric(horizontal: 25),
decoration: BoxDecoration(
color: Theme.of(context).colorScheme.surface,
borderRadius: const BorderRadius.only(
topLeft: Radius.circular(24),
topRight: Radius.circular(24),
),
),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
const SizedBox(height: 18),
DropdownMenu(
label: const Text('Jenis Laporan'),
onSelected: (value) => setState(() => _jenisLaporan = value),
dropdownMenuEntries: [
DropdownMenuEntry(
value: JenisLaporan.penjualanDiAtasHET,
label: JenisLaporan.penjualanDiAtasHET.value,
),
DropdownMenuEntry(
value: JenisLaporan.penyelewenganPenyaluran,
label: JenisLaporan.penyelewenganPenyaluran.value,
),
DropdownMenuEntry(
value: JenisLaporan.pengoplosan,
label: JenisLaporan.pengoplosan.value,
),
DropdownMenuEntry(
value: JenisLaporan.lainnya,
label: JenisLaporan.lainnya.value,
),
],
),
const SizedBox(height: 10),
TextField(
keyboardType: TextInputType.multiline,
maxLines: 3,
onChanged: (value) => _deskripsi = value,
decoration: InputDecoration(
border:
OutlineInputBorder(borderRadius: BorderRadius.circular(12)),
label: Text(
'Masukkan Deskripsi Laporan',
style:
TextStyle(color: Theme.of(context).colorScheme.outline),
),
),
),
const SizedBox(height: 12),
SizedBox(
width: double.infinity,
child: FilledButton(
onPressed: _jenisLaporan == null ? null : () => _onSubmit(),
child: const Text(
'Kirim Laporan',
style: TextStyle(fontWeight: FontWeight.bold),
),
),
),
const SizedBox(height: 30),
],
),
),
);
}
}
5 changes: 3 additions & 2 deletions lib/components/ulasan_modal_bottom_sheet.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:gasku/cubits/daftar_pangkalan.dart';
import 'package:gasku/cubits/pengguna_masuk.dart';
import 'package:gasku/models/pangkalan.dart';
import 'package:gasku/models/pengguna.dart';
Expand Down Expand Up @@ -56,6 +55,8 @@ class _MyUlasanModalBottomSheetState extends State<MyUlasanModalBottomSheet> {
),
));
} catch (e) {
Navigator.of(context).pop();
Navigator.of(context).pop();
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text(e.toString()),
backgroundColor: Theme.of(context).colorScheme.primary,
Expand Down Expand Up @@ -133,7 +134,7 @@ class _MyUlasanModalBottomSheetState extends State<MyUlasanModalBottomSheet> {
SizedBox(
width: double.infinity,
child: FilledButton(
onPressed: () => _onSubmit(),
onPressed: _rating == 0 ? null : () => _onSubmit(),
child: const Text(
'Kirim Ulasan',
style: TextStyle(fontWeight: FontWeight.bold),
Expand Down
26 changes: 26 additions & 0 deletions lib/pages/detail_pangkalan.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'dart:convert';

import 'package:flutter/material.dart';
import 'package:flutter_carousel_widget/flutter_carousel_widget.dart';
import 'package:gasku/components/laporan_modal_bottom_sheet.dart';
import 'package:gasku/components/ulasan_modal_bottom_sheet.dart';
import 'package:gasku/models/pangkalan.dart';
import 'package:gasku/utils/format_rupiah.dart';
Expand Down Expand Up @@ -207,6 +208,31 @@ class MyDetailPangkalanPage extends StatelessWidget {
),
],
),
const SizedBox(height: 15),
OutlinedButton(
onPressed: () {
showModalBottomSheet(
context: context,
isScrollControlled: true,
builder: (context) {
return MyLaporanModalBottomSheet(
pangkalan: pangkalan,
);
},
);
},
style: OutlinedButton.styleFrom(
overlayColor: Colors.red,
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(10)),
),
side: BorderSide(color: Colors.red),
),
child: Text(
'Laporkan Pangkalan',
style: TextStyle(color: Colors.red),
),
),
const SizedBox(height: 50),
const Text(
'Komentar',
Expand Down

0 comments on commit 7703cb8

Please sign in to comment.