another commit
This commit is contained in:
97
lib/controller/after_login/beforeEnterController.dart
Normal file
97
lib/controller/after_login/beforeEnterController.dart
Normal file
@ -0,0 +1,97 @@
|
||||
// ignore_for_file: file_names, non_constant_identifier_names
|
||||
|
||||
import 'dart:developer';
|
||||
|
||||
import 'package:flutter_easyloading/flutter_easyloading.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:get_storage/get_storage.dart';
|
||||
|
||||
import '../../api/beforeLoginAPI.dart';
|
||||
|
||||
class BeforeEnterController extends GetxController {
|
||||
final storage = GetStorage();
|
||||
|
||||
@override
|
||||
void onInit() async {
|
||||
await EasyLoading.show(
|
||||
status: 'Loading...',
|
||||
maskType: EasyLoadingMaskType.black,
|
||||
);
|
||||
// wait 3 sec
|
||||
// await Future.delayed(const Duration(seconds: 3));
|
||||
// await EasyLoading.dismiss();
|
||||
log("sini on init before enter");
|
||||
cek_login();
|
||||
|
||||
// log(storage.read('role') + "ini role nya");
|
||||
super.onInit();
|
||||
}
|
||||
|
||||
void cek_login() async {
|
||||
final _username =
|
||||
(storage.read('username') != null) ? storage.read('username') : "";
|
||||
final _password =
|
||||
(storage.read('password') != null) ? storage.read('password') : "";
|
||||
final _role = (storage.read('role') != null) ? storage.read('role') : "";
|
||||
|
||||
final _id = (storage.read('id') != null) ? storage.read('id') : "";
|
||||
|
||||
late bool _wrongPassword;
|
||||
|
||||
Map<String, dynamic> _data = await BeforeLoginApi.log_in_user(
|
||||
_username, _password, _role.toLowerCase());
|
||||
|
||||
switch (_data['status']) {
|
||||
case 200:
|
||||
_wrongPassword = true;
|
||||
break;
|
||||
case 400:
|
||||
_wrongPassword = false;
|
||||
break;
|
||||
default:
|
||||
_wrongPassword = false;
|
||||
break;
|
||||
}
|
||||
|
||||
log(_username.toString() + " ini usernamenya");
|
||||
log(_password.toString() + " ini passwordnya");
|
||||
log(_role.toString() + " ini role nya");
|
||||
log(_id.toString() + " ini id nya");
|
||||
|
||||
// await Future.delayed(const Duration(seconds: 3));
|
||||
await EasyLoading.dismiss();
|
||||
|
||||
if (!_wrongPassword) {
|
||||
storage.remove('username');
|
||||
storage.remove('password');
|
||||
storage.remove('role');
|
||||
|
||||
Get.offAllNamed(
|
||||
'/index',
|
||||
arguments: {
|
||||
"tap": 0,
|
||||
"history": [0],
|
||||
},
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
if (_role.toLowerCase() == "kurir") {
|
||||
Get.offAllNamed(
|
||||
'/kurirIndex',
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
if (_role.toLowerCase() == "pengirim") {
|
||||
Get.offAllNamed(
|
||||
'pengirimIndex',
|
||||
arguments: {
|
||||
"tap": 1,
|
||||
// "history": _historyIndex.value,
|
||||
},
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
115
lib/controller/after_login/kurir/indexController.dart
Normal file
115
lib/controller/after_login/kurir/indexController.dart
Normal file
@ -0,0 +1,115 @@
|
||||
// ignore_for_file: file_names
|
||||
|
||||
import 'dart:developer';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:kurir/controller/after_login/kurir/pengaturanController.dart';
|
||||
|
||||
import 'package:socket_io_client/socket_io_client.dart';
|
||||
|
||||
class KurirIndexController extends GetxController {
|
||||
late Socket socket;
|
||||
|
||||
final Rx<int> _indexTap = 0.obs; // bottom navigation index tap
|
||||
|
||||
PageController pageController =
|
||||
PageController(initialPage: 0, keepPage: true);
|
||||
|
||||
pageChanged(int index) async {
|
||||
_indexTap.value = index;
|
||||
switch (index) {
|
||||
case 0:
|
||||
final ctrl = Get.put<PengaturanKurirController>(
|
||||
PengaturanKurirController(),
|
||||
);
|
||||
ctrl.onInit();
|
||||
|
||||
// Get.put(PengaturanKurirController());
|
||||
|
||||
break;
|
||||
default:
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
log('KurirIndexController onInit');
|
||||
// final ctrl = Get.put(PengaturanKurirController());
|
||||
// ctrl.onInit();
|
||||
connectToServer();
|
||||
super.onInit();
|
||||
}
|
||||
|
||||
BottomNavigationBar bottomNavigationBar(context) {
|
||||
return BottomNavigationBar(
|
||||
type: BottomNavigationBarType.fixed,
|
||||
items: const [
|
||||
BottomNavigationBarItem(
|
||||
icon: Icon(Icons.home),
|
||||
label: 'Pengaturan',
|
||||
),
|
||||
BottomNavigationBarItem(
|
||||
icon: Icon(Icons.login),
|
||||
label: 'Pengiriman',
|
||||
),
|
||||
BottomNavigationBarItem(
|
||||
icon: Icon(Icons.app_registration),
|
||||
label: 'Log History',
|
||||
),
|
||||
BottomNavigationBarItem(
|
||||
icon: Icon(Icons.account_circle),
|
||||
label: 'Profile',
|
||||
),
|
||||
],
|
||||
currentIndex: _indexTap.value,
|
||||
selectedItemColor: const Color.fromARGB(255, 148, 183, 229),
|
||||
onTap: (index) => _onItemTapped(index, context),
|
||||
);
|
||||
}
|
||||
|
||||
_onItemTapped(int index, BuildContext context) {
|
||||
log("sini on item tapped");
|
||||
_indexTap.value = index;
|
||||
if (index == 3) {
|
||||
Get.offAllNamed('/profileKurir');
|
||||
}
|
||||
FocusScope.of(context).unfocus();
|
||||
// Get.delete<PengaturanKurirController>();
|
||||
|
||||
pageController.animateToPage(index,
|
||||
duration: const Duration(milliseconds: 300), curve: Curves.ease);
|
||||
}
|
||||
|
||||
void connectToServer() async {
|
||||
log("sini connect to socket io");
|
||||
try {
|
||||
// Configure socket transports must be sepecified
|
||||
socket = io('http://192.168.43.125:3001/', <String, dynamic>{
|
||||
'transports': ['websocket'],
|
||||
'autoConnect': true,
|
||||
});
|
||||
|
||||
// Connect to websocket
|
||||
socket.connect();
|
||||
socket.onConnect((_) {
|
||||
log("sini connected");
|
||||
// socket.emit('join', 'kurir');
|
||||
});
|
||||
// Connect to websocket
|
||||
// socket.connect();
|
||||
socket.on('connect', (_) => log('connect asdasdsad: ${socket.id}'));
|
||||
socket.on('coba1', (_) => log(_.toString() + " ini coba2"));
|
||||
|
||||
log(socket.connected.toString());
|
||||
} catch (e) {
|
||||
log(e.toString());
|
||||
log('tidak connect');
|
||||
}
|
||||
}
|
||||
|
||||
// onWillpop() async {
|
||||
// log("ini onWillpop");
|
||||
// return false;
|
||||
// }
|
||||
}
|
||||
114
lib/controller/after_login/kurir/pengaturanController.dart
Normal file
114
lib/controller/after_login/kurir/pengaturanController.dart
Normal file
@ -0,0 +1,114 @@
|
||||
// ignore_for_file: file_names, non_constant_identifier_names
|
||||
|
||||
import 'dart:developer';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:get_storage/get_storage.dart';
|
||||
import 'package:kurir/api/kurirApi.dart';
|
||||
|
||||
import 'package:flutter_easyloading/flutter_easyloading.dart';
|
||||
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:kurir/models/kurirModel.dart';
|
||||
|
||||
class PengaturanKurirController extends GetxController {
|
||||
final storage = GetStorage();
|
||||
|
||||
var formKey = GlobalKey<FormState>(); // for form validation
|
||||
|
||||
Rx<String> status = ''.obs;
|
||||
|
||||
final minimalBiayaPengirimanController = TextEditingController();
|
||||
final maksimalBiayaPengirimanController = TextEditingController();
|
||||
final biayaPerKiloController = TextEditingController();
|
||||
|
||||
final FocusNode minimalBiayaPengirimanFocusNode = FocusNode();
|
||||
final FocusNode maksimalBiayaPengirimanFocusNode = FocusNode();
|
||||
final FocusNode biayaPerKiloFocusNode = FocusNode();
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
log("sini pengaturan controller");
|
||||
minimalBiayaPengirimanController.clear();
|
||||
|
||||
maksimalBiayaPengirimanController.clear();
|
||||
biayaPerKiloController.clear();
|
||||
log('ini idnya ' + storage.read('id'));
|
||||
super.onInit();
|
||||
}
|
||||
|
||||
@override
|
||||
void onReady() {
|
||||
cek_datanya();
|
||||
super.onReady();
|
||||
}
|
||||
|
||||
cek_datanya() async {
|
||||
await EasyLoading.show(
|
||||
status: 'Loading Data...',
|
||||
maskType: EasyLoadingMaskType.black,
|
||||
);
|
||||
final result = await KurirApi.cekPengaturanKurir();
|
||||
|
||||
log(result.toString());
|
||||
if (result['status'] == 200 && result['data'] != null) {
|
||||
final PengaturanBiayaKurirModel pengaturanBiayaKurir =
|
||||
PengaturanBiayaKurirModel.fromJson(result['data']);
|
||||
minimalBiayaPengirimanController.text =
|
||||
thousandsSeperator(pengaturanBiayaKurir.minimalBiayaPengiriman!);
|
||||
maksimalBiayaPengirimanController.text =
|
||||
thousandsSeperator(pengaturanBiayaKurir.maksimalBiayaPengiriman!);
|
||||
biayaPerKiloController.text =
|
||||
thousandsSeperator(pengaturanBiayaKurir.biayaPerKilo!);
|
||||
|
||||
status.value = 'Ubah';
|
||||
} else {
|
||||
status.value = 'Simpan';
|
||||
}
|
||||
|
||||
await EasyLoading.dismiss();
|
||||
}
|
||||
|
||||
simpan() async {
|
||||
// remove "," from text
|
||||
//get alert dialog
|
||||
|
||||
final minimalBiayaPengiriman =
|
||||
minimalBiayaPengirimanController.text.replaceAll(RegExp(r','), '');
|
||||
final maksimalBiayaPengiriman =
|
||||
maksimalBiayaPengirimanController.text.replaceAll(RegExp(r','), '');
|
||||
final biayaPerKilo =
|
||||
biayaPerKiloController.text.replaceAll(RegExp(r','), '');
|
||||
|
||||
// log(minimalBiayaPengiriman + " ini minimal biaya pengiriman");
|
||||
// log(maksimalBiayaPengiriman + " ini maksimal biaya pengiriman");
|
||||
// log(biayaPerKilo + " ini biaya per kilo");
|
||||
await EasyLoading.show(
|
||||
status: 'Pengaturan Biaya...',
|
||||
maskType: EasyLoadingMaskType.black,
|
||||
);
|
||||
final result = await KurirApi.pengaturanKurir(
|
||||
minimalBiayaPengiriman, maksimalBiayaPengiriman, biayaPerKilo);
|
||||
|
||||
log(result.toString());
|
||||
onInit();
|
||||
await EasyLoading.dismiss();
|
||||
}
|
||||
|
||||
coba() {
|
||||
log("sini coba terjadi");
|
||||
}
|
||||
|
||||
thousandsSeperator(int number) {
|
||||
final formatter = NumberFormat('#,###');
|
||||
final numbernya = formatter.format(number);
|
||||
// log(numbernya + " ini numbernya");
|
||||
return numbernya;
|
||||
}
|
||||
|
||||
removeComma(String number) {
|
||||
final numbernya = number.replaceAll(RegExp(r','), '');
|
||||
return int.parse(numbernya);
|
||||
}
|
||||
}
|
||||
32
lib/controller/after_login/kurir/profileController.dart
Normal file
32
lib/controller/after_login/kurir/profileController.dart
Normal file
@ -0,0 +1,32 @@
|
||||
// ignore_for_file: file_names
|
||||
|
||||
import 'package:get/get.dart';
|
||||
import 'dart:developer';
|
||||
|
||||
import 'package:flutter_easyloading/flutter_easyloading.dart';
|
||||
import 'package:kurir/api/beforeLoginAPI.dart';
|
||||
|
||||
class KurirProfileController extends GetxController {
|
||||
@override
|
||||
void onInit() {
|
||||
log("sini profile kurir controller oninit");
|
||||
super.onInit();
|
||||
}
|
||||
|
||||
logout() async {
|
||||
await EasyLoading.show(
|
||||
status: 'Pengaturan Biaya...',
|
||||
maskType: EasyLoadingMaskType.black,
|
||||
);
|
||||
|
||||
await BeforeLoginApi.logout();
|
||||
await EasyLoading.dismiss();
|
||||
Get.offAllNamed(
|
||||
'/index',
|
||||
arguments: {
|
||||
"tap": 0,
|
||||
"history": [0],
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
82
lib/controller/after_login/pengirim/indexController.dart
Normal file
82
lib/controller/after_login/pengirim/indexController.dart
Normal file
@ -0,0 +1,82 @@
|
||||
// ignore_for_file: file_names
|
||||
|
||||
import 'dart:developer';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:kurir/controller/after_login/pengirim/kirimBarangController.dart';
|
||||
import 'package:kurir/controller/after_login/pengirim/logKirimanController.dart';
|
||||
|
||||
class PengirimIndexController extends GetxController {
|
||||
dynamic argumicData = Get.arguments;
|
||||
|
||||
final Rx<int> _indexTap = 0.obs; // bottom navigation index tap
|
||||
|
||||
late PageController pageController;
|
||||
|
||||
pageChanged(int index) async {
|
||||
// Get.delete<KirimBarangController>();
|
||||
if (index == 0) {
|
||||
var _init = Get.put(KirimBarangController());
|
||||
_init.onInit();
|
||||
// Get.lazyPut<KirimBarangController>(() => KirimBarangController());
|
||||
}
|
||||
if (index == 1) {
|
||||
var _init = Get.put(LogKirimanController());
|
||||
_init.onInit();
|
||||
}
|
||||
|
||||
_indexTap.value = index;
|
||||
}
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
log("sini on init pengirim index");
|
||||
_indexTap.value = argumicData['tap'] ?? 0;
|
||||
pageController =
|
||||
PageController(initialPage: _indexTap.value, keepPage: true);
|
||||
super.onInit();
|
||||
}
|
||||
|
||||
BottomNavigationBar bottomNavigationBar(context) {
|
||||
return BottomNavigationBar(
|
||||
type: BottomNavigationBarType.fixed,
|
||||
items: const [
|
||||
BottomNavigationBarItem(
|
||||
icon: Icon(Icons.motorcycle_rounded),
|
||||
label: 'Kirim Barang',
|
||||
),
|
||||
BottomNavigationBarItem(
|
||||
icon: Icon(Icons.list_alt_rounded),
|
||||
label: 'Log Kiriman',
|
||||
),
|
||||
BottomNavigationBarItem(
|
||||
icon: Icon(Icons.people_alt_rounded),
|
||||
label: 'List Kurir',
|
||||
),
|
||||
BottomNavigationBarItem(
|
||||
icon: Icon(Icons.account_circle),
|
||||
label: 'Profile',
|
||||
),
|
||||
],
|
||||
currentIndex: _indexTap.value,
|
||||
selectedItemColor: const Color.fromARGB(255, 148, 183, 229),
|
||||
onTap: (index) => _onItemTapped(index, context),
|
||||
);
|
||||
}
|
||||
|
||||
_onItemTapped(int index, BuildContext context) {
|
||||
log("sini on item tapped");
|
||||
if (index == 3) {
|
||||
Get.offAllNamed('/profilePengirim');
|
||||
}
|
||||
|
||||
_indexTap.value = index;
|
||||
|
||||
FocusScope.of(context).unfocus();
|
||||
// Get.delete<PengaturanKurirController>();
|
||||
|
||||
pageController.animateToPage(index,
|
||||
duration: const Duration(milliseconds: 300), curve: Curves.ease);
|
||||
}
|
||||
}
|
||||
2264
lib/controller/after_login/pengirim/kirimBarangController.dart
Normal file
2264
lib/controller/after_login/pengirim/kirimBarangController.dart
Normal file
File diff suppressed because it is too large
Load Diff
414
lib/controller/after_login/pengirim/logKirimanController.dart
Normal file
414
lib/controller/after_login/pengirim/logKirimanController.dart
Normal file
@ -0,0 +1,414 @@
|
||||
// ignore_for_file: file_names, non_constant_identifier_names
|
||||
|
||||
import 'dart:developer';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_polyline_points/flutter_polyline_points.dart';
|
||||
import 'package:flutter_slidable/flutter_slidable.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:google_maps_flutter/google_maps_flutter.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:kurir/api/pengirimApi.dart';
|
||||
import 'package:kurir/function/allFunction.dart';
|
||||
import 'package:kurir/models/pengirimimanModel.dart';
|
||||
|
||||
import 'package:kurir/globals.dart' as globals;
|
||||
|
||||
class LogKirimanController extends GetxController {
|
||||
Rx<Widget> widgetLogKiriman = const Center(
|
||||
child: CircularProgressIndicator(),
|
||||
).obs;
|
||||
|
||||
RxBool isPortrait = true.obs;
|
||||
|
||||
late GoogleMapController mapController;
|
||||
Set<Marker> _markers = {};
|
||||
Set<Polyline> _polylines = {};
|
||||
List<LatLng> _polylineCoordinates = [];
|
||||
PolylinePoints _polylinePoints = PolylinePoints();
|
||||
String _googleAPiKey = globals.api_key;
|
||||
|
||||
List<LatLng>? _listLatLng;
|
||||
|
||||
// late GoogleMapController mapController;
|
||||
final _initialCameraPosition = const CameraPosition(
|
||||
target: LatLng(-3.5621854706823193, 119.7612856634139),
|
||||
zoom: 12.5,
|
||||
);
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
// ignore: todo
|
||||
// TODO: implement onInit
|
||||
log("sini on init log kiriman");
|
||||
|
||||
checkAllLogKiriman();
|
||||
// BuildContext? context;
|
||||
log(Get.context!.isLandscape.toString() + " is landscape");
|
||||
log(Get.context!.isPortrait.toString() + " is potret");
|
||||
super.onInit();
|
||||
}
|
||||
|
||||
checkScreenOrientation() {
|
||||
if (Get.context!.isLandscape) {
|
||||
isPortrait.value = false;
|
||||
} else {
|
||||
isPortrait.value = true;
|
||||
}
|
||||
}
|
||||
|
||||
checkAllLogKiriman() async {
|
||||
Map<String, dynamic> _data = await PengirimApi.getLogKiriman();
|
||||
log(_data.toString());
|
||||
// await 4 sec
|
||||
widgetLogKiriman.value = const Center(
|
||||
child: CircularProgressIndicator(),
|
||||
);
|
||||
|
||||
if (_data['data'].length > 0) {
|
||||
List<Widget> _listWidget = [];
|
||||
|
||||
for (var item in _data['data']) {
|
||||
PengirimanModel? _pengirimanModel = PengirimanModel.fromJson(item);
|
||||
// log(_pengiriman.kurir!.id.toString());
|
||||
_listWidget.add(_widgetLogKiriman(_pengirimanModel));
|
||||
|
||||
// _listWidget.add(_widgetLogKiriman());
|
||||
}
|
||||
Widget _listview = Column(
|
||||
children: [
|
||||
..._listWidget,
|
||||
],
|
||||
);
|
||||
|
||||
widgetLogKiriman.value = Center(
|
||||
child: Obx(
|
||||
() => Container(
|
||||
constraints: BoxConstraints(
|
||||
// maxHeight: Get.height * 0.65,
|
||||
maxHeight:
|
||||
(isPortrait.value) ? Get.height * 0.62 : Get.height * 0.42,
|
||||
|
||||
minHeight: Get.context!.height * 0.42,
|
||||
),
|
||||
child: SingleChildScrollView(child: _listview),
|
||||
),
|
||||
),
|
||||
);
|
||||
} else {
|
||||
widgetLogKiriman.value = const Center(
|
||||
child: Text("Tidak ada log kiriman"),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
_widgetLogKiriman(PengirimanModel? _pengirimanModel) {
|
||||
var _createdAtPlus8 = DateTime.parse(_pengirimanModel!.createdAt!)
|
||||
.add(const Duration(hours: 8));
|
||||
|
||||
String _tanggal = DateFormat('dd-MM-yyyy').format(_createdAtPlus8);
|
||||
|
||||
// add am/pm to jam
|
||||
String _jam = DateFormat('HH:mm:ss').format(_createdAtPlus8);
|
||||
|
||||
String _nama_kurir = _pengirimanModel.kurir!.nama!;
|
||||
|
||||
String _status = _pengirimanModel.statusPengiriman!;
|
||||
|
||||
String _foto_pengiriman = _pengirimanModel.fotoPengiriman!;
|
||||
// log(_foto_pengiriman + " foto pengiriman");
|
||||
|
||||
var _kordinat_pengiriman = _pengirimanModel.kordinatPengiriman!;
|
||||
var _kordinat_permulaan = _pengirimanModel.kordinatPermulaan!;
|
||||
|
||||
Widget _listTilenya = Card(
|
||||
elevation: 2,
|
||||
child: Slidable(
|
||||
key: const ValueKey(1),
|
||||
startActionPane: ActionPane(
|
||||
motion: const DrawerMotion(),
|
||||
extentRatio: 0.80,
|
||||
// dismissible: DismissiblePane(onDismissed: () {}),
|
||||
children: [
|
||||
SlidableAction(
|
||||
flex: 2,
|
||||
onPressed: (context) {},
|
||||
backgroundColor: const Color.fromARGB(255, 70, 192, 232),
|
||||
foregroundColor: Colors.white,
|
||||
icon: Icons.info_outline_rounded,
|
||||
label: 'Info',
|
||||
),
|
||||
SlidableAction(
|
||||
flex: 3,
|
||||
onPressed: (context) {
|
||||
_lihat_foto_kiriman(context, _foto_pengiriman);
|
||||
},
|
||||
backgroundColor: const Color.fromARGB(255, 71, 92, 250),
|
||||
foregroundColor: Colors.white,
|
||||
icon: Icons.photo_rounded,
|
||||
label: 'Barang Kiriman',
|
||||
),
|
||||
],
|
||||
),
|
||||
endActionPane: ActionPane(
|
||||
motion: const DrawerMotion(),
|
||||
extentRatio: 0.5,
|
||||
children: [
|
||||
SlidableAction(
|
||||
onPressed: (context) {
|
||||
_lihat_rute_pengiriman(
|
||||
context, _kordinat_pengiriman, _kordinat_permulaan);
|
||||
},
|
||||
backgroundColor: Color.fromARGB(255, 242, 78, 23),
|
||||
foregroundColor: Colors.white,
|
||||
icon: Icons.maps_home_work_rounded,
|
||||
label: "Rute Pengiriman",
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
vertical: 10,
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
flex: 3,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
" $_tanggal",
|
||||
style: const TextStyle(
|
||||
fontSize: 15,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
Text(
|
||||
" $_jam",
|
||||
style: const TextStyle(
|
||||
fontSize: 15,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
flex: 3,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
Text(
|
||||
_nama_kurir,
|
||||
style: const TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
flex: 3,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
children: [
|
||||
Text(
|
||||
_status,
|
||||
style: const TextStyle(
|
||||
fontSize: 15,
|
||||
// fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
return _listTilenya;
|
||||
}
|
||||
|
||||
_lihat_foto_kiriman(BuildContext context, String foto_pengiriman) {
|
||||
log(foto_pengiriman);
|
||||
if (foto_pengiriman != null && foto_pengiriman != "") {
|
||||
Get.dialog(
|
||||
AlertDialog(
|
||||
title: const Text("Foto Pengiriman"),
|
||||
content: Container(
|
||||
height: Get.height * 0.5,
|
||||
width: Get.width * 0.6,
|
||||
decoration: const BoxDecoration(
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.grey,
|
||||
spreadRadius: 1,
|
||||
blurRadius: 10,
|
||||
),
|
||||
],
|
||||
),
|
||||
child: ClipRRect(
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
image: DecorationImage(
|
||||
image: AssetImage('assets/loading.gif'),
|
||||
fit: BoxFit.cover,
|
||||
),
|
||||
),
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
image: DecorationImage(
|
||||
image: NetworkImage(foto_pengiriman),
|
||||
fit: BoxFit.cover,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
} else {
|
||||
Get.snackbar(
|
||||
"Info",
|
||||
"Foto Barang Pengiriman Masih Dalam Proses Upload",
|
||||
icon: Icon(
|
||||
Icons.info_outline_rounded,
|
||||
color: Colors.white,
|
||||
),
|
||||
backgroundColor: Color.fromARGB(255, 71, 203, 240),
|
||||
duration: Duration(seconds: 3),
|
||||
snackPosition: SnackPosition.TOP,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
_lihat_rute_pengiriman(
|
||||
BuildContext context,
|
||||
KordinatPengiriman kordinat_pengiriman,
|
||||
KordinatPermulaan kordinat_permulaan) async {
|
||||
_markers.clear();
|
||||
_polylines.clear();
|
||||
_polylineCoordinates = [];
|
||||
_listLatLng = null;
|
||||
// _polylinePoints.clear();
|
||||
|
||||
LatLng _latLng_pengiriman = LatLng(
|
||||
double.parse(kordinat_pengiriman.lat!),
|
||||
double.parse(kordinat_pengiriman.lng!),
|
||||
);
|
||||
|
||||
LatLng _latLng_permulaan = LatLng(
|
||||
double.parse(kordinat_permulaan.lat!),
|
||||
double.parse(kordinat_permulaan.lng!),
|
||||
);
|
||||
_listLatLng = [
|
||||
LatLng(
|
||||
double.parse(kordinat_permulaan.lat!),
|
||||
double.parse(kordinat_permulaan.lng!),
|
||||
),
|
||||
LatLng(
|
||||
double.parse(kordinat_pengiriman.lat!),
|
||||
double.parse(kordinat_pengiriman.lng!),
|
||||
),
|
||||
];
|
||||
|
||||
await setPolylines(
|
||||
_latLng_pengiriman,
|
||||
_latLng_permulaan,
|
||||
);
|
||||
|
||||
_markers.add(
|
||||
Marker(
|
||||
markerId: const MarkerId("permulaan"),
|
||||
position: LatLng(double.parse(kordinat_permulaan.lat!),
|
||||
double.parse(kordinat_permulaan.lng!)),
|
||||
infoWindow: InfoWindow(
|
||||
title: "Lokasi Permulaan",
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
_markers.add(
|
||||
Marker(
|
||||
markerId: const MarkerId("pengiriman"),
|
||||
position: LatLng(double.parse(kordinat_pengiriman.lat!),
|
||||
double.parse(kordinat_pengiriman.lng!)),
|
||||
infoWindow: InfoWindow(
|
||||
title: "LokasiPengiriman",
|
||||
),
|
||||
),
|
||||
);
|
||||
// await 1 sec
|
||||
await Future.delayed(Duration(seconds: 1));
|
||||
Get.dialog(
|
||||
AlertDialog(
|
||||
content: Container(
|
||||
height: Get.height * 0.5,
|
||||
child: GoogleMap(
|
||||
mapType: MapType.hybrid,
|
||||
mapToolbarEnabled: true,
|
||||
rotateGesturesEnabled: true,
|
||||
myLocationButtonEnabled: true,
|
||||
markers: _markers,
|
||||
polylines: _polylines,
|
||||
// liteModeEnabled: true,
|
||||
initialCameraPosition: _initialCameraPosition,
|
||||
onMapCreated: _onBounds,
|
||||
// onCameraMove: _onCameraMove,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
setPolylines(LatLng latLng_pengiriman, LatLng latLng_permulaan) async {
|
||||
log("sini dia berlaku");
|
||||
PolylineResult _result = await _polylinePoints.getRouteBetweenCoordinates(
|
||||
_googleAPiKey,
|
||||
PointLatLng(latLng_permulaan.latitude, latLng_permulaan.longitude),
|
||||
PointLatLng(latLng_pengiriman.latitude, latLng_pengiriman.longitude),
|
||||
travelMode: TravelMode.driving,
|
||||
// travelMode: TravelMode.driving,
|
||||
);
|
||||
// log(_result.points.toString() + "ini dia");
|
||||
if (_result.points.isNotEmpty) {
|
||||
// loop through all PointLatLng points and convert them
|
||||
// to a list of LatLng, required by the Polyline
|
||||
_result.points.forEach((PointLatLng point) {
|
||||
_polylineCoordinates.add(LatLng(point.latitude, point.longitude));
|
||||
});
|
||||
|
||||
Polyline polyline = Polyline(
|
||||
polylineId: PolylineId("poly"),
|
||||
color: Color.fromARGB(255, 40, 122, 198),
|
||||
points: _polylineCoordinates,
|
||||
width: 3,
|
||||
);
|
||||
_polylines.add(polyline);
|
||||
|
||||
double distance = await PengirimApi.jarak_route(
|
||||
latLng_permulaan.latitude,
|
||||
latLng_permulaan.longitude,
|
||||
latLng_pengiriman.latitude,
|
||||
latLng_pengiriman.longitude,
|
||||
);
|
||||
|
||||
log(distance.toString() + "ini dia");
|
||||
}
|
||||
}
|
||||
|
||||
void _onBounds(GoogleMapController controller) {
|
||||
mapController = controller;
|
||||
mapController.animateCamera(
|
||||
CameraUpdate.newLatLngBounds(
|
||||
AllFunction.computeBounds(_listLatLng!),
|
||||
15,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
228
lib/controller/before_login/loginController.dart
Normal file
228
lib/controller/before_login/loginController.dart
Normal file
@ -0,0 +1,228 @@
|
||||
// ignore_for_file: file_names, invalid_use_of_protected_member
|
||||
|
||||
import 'dart:convert';
|
||||
import 'dart:developer';
|
||||
|
||||
import 'package:crypto/crypto.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_easyloading/flutter_easyloading.dart';
|
||||
import 'package:get/get.dart';
|
||||
|
||||
import '../../api/beforeLoginAPI.dart';
|
||||
|
||||
class LoginController extends GetxController {
|
||||
var formKey = GlobalKey<FormState>();
|
||||
|
||||
dynamic argumicData = Get.arguments; // get argument from routes.
|
||||
final Rx<int> _indexTap = 0.obs; // bottom navigation index tap
|
||||
late final RxList _historyIndex = [].obs; // navigation history
|
||||
|
||||
// for login page
|
||||
List<String> role = ['Kurir', 'Pengirim'];
|
||||
final Rx<String> selectedRole = 'Kurir'.obs;
|
||||
final usernameController = TextEditingController();
|
||||
final passwordController = TextEditingController();
|
||||
final RxBool passwordVisible = false.obs;
|
||||
final FocusNode usernameFocusNode = FocusNode();
|
||||
final FocusNode passwordFocusNode = FocusNode();
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
log("sini on init");
|
||||
// print(argumicData);
|
||||
_indexTap.value = argumicData['tap'];
|
||||
// push to _historyIndex
|
||||
_historyIndex.value = argumicData['history'];
|
||||
log(_historyIndex.value.toString() + " ini history");
|
||||
// print(_historyIndex.length.toString() + " ini panjangnya di oninit");
|
||||
|
||||
// BackButtonInterceptor.add(myInterceptor);
|
||||
super.onInit();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
formKey.currentState!.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
// back button history navigation
|
||||
Future<bool> willPopScopeWidget() async {
|
||||
log('sini willpopscope');
|
||||
log(_historyIndex.toString() + ' ini history listnya');
|
||||
final int lastIndex = _historyIndex[_historyIndex.length - 2];
|
||||
log("sini last index " + lastIndex.toString());
|
||||
late String _routeName;
|
||||
switch (lastIndex) {
|
||||
case 0:
|
||||
_routeName = '/index';
|
||||
break;
|
||||
case 1:
|
||||
_routeName = '/login';
|
||||
break;
|
||||
case 2:
|
||||
_routeName = '/daftar';
|
||||
break;
|
||||
}
|
||||
// log("ini route name " + _routeName);
|
||||
_historyIndex.removeLast();
|
||||
selectedRole.value = role[0];
|
||||
usernameController.clear();
|
||||
passwordController.clear();
|
||||
_indexTap.value = lastIndex;
|
||||
// Get.back();
|
||||
// await Get.delete<LoginController>();
|
||||
Get.offAllNamed(
|
||||
_routeName,
|
||||
arguments: {
|
||||
"tap": lastIndex,
|
||||
"history": _historyIndex.value,
|
||||
},
|
||||
);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// bottom navigation index tapping
|
||||
void _onItemTapped(int index) async {
|
||||
if (index == _indexTap.value) return;
|
||||
_indexTap.value = index;
|
||||
late String _routeName;
|
||||
switch (index) {
|
||||
case 0:
|
||||
_routeName = '/index';
|
||||
break;
|
||||
case 1:
|
||||
_routeName = '/login';
|
||||
break;
|
||||
case 2:
|
||||
_routeName = '/daftar';
|
||||
break;
|
||||
}
|
||||
|
||||
// Get.delete<LoginController>();
|
||||
log("sini on item tapped");
|
||||
if (index == 0) {
|
||||
_historyIndex.clear();
|
||||
_historyIndex.add(0);
|
||||
} else {
|
||||
_historyIndex.add(index);
|
||||
}
|
||||
|
||||
//clear all the input in login before navigate to another page
|
||||
selectedRole.value = role[0];
|
||||
usernameController.clear();
|
||||
passwordController.clear();
|
||||
|
||||
// await Get.delete<LoginController>();
|
||||
await Get.offAllNamed(
|
||||
_routeName,
|
||||
arguments: {
|
||||
"tap": index,
|
||||
"history": _historyIndex.value,
|
||||
},
|
||||
);
|
||||
// Get.toNamed('/second');
|
||||
}
|
||||
|
||||
void login() async {
|
||||
await EasyLoading.show(
|
||||
status: 'Loading...',
|
||||
maskType: EasyLoadingMaskType.black,
|
||||
);
|
||||
log("sini proses login");
|
||||
late bool _wrongPassword;
|
||||
late String _message;
|
||||
|
||||
String _username = usernameController.text;
|
||||
String _password = passwordController.text;
|
||||
String _role = selectedRole.value;
|
||||
|
||||
log(_username.toString() + " ini usernamenya");
|
||||
log(_password.toString() + " ini passwordnya");
|
||||
log(_role.toString() + " ini role nya");
|
||||
|
||||
Map<String, dynamic> _data = await BeforeLoginApi.log_in_user(
|
||||
_username, generateMd5(_password), _role.toLowerCase());
|
||||
|
||||
await EasyLoading.dismiss();
|
||||
|
||||
// log(_data.toString() + " ini data");
|
||||
switch (_data['status']) {
|
||||
case 200:
|
||||
_wrongPassword = true;
|
||||
_message = _data['message'];
|
||||
break;
|
||||
case 400:
|
||||
_wrongPassword = false;
|
||||
_message = _data['message'];
|
||||
usernameFocusNode.requestFocus();
|
||||
break;
|
||||
default:
|
||||
_wrongPassword = false;
|
||||
_message = _data['message'];
|
||||
break;
|
||||
}
|
||||
|
||||
if (!_wrongPassword) {
|
||||
// focus to username
|
||||
// usernameFocusNode.requestFocus();
|
||||
// put validator in username
|
||||
|
||||
Get.snackbar(
|
||||
"Error",
|
||||
_message,
|
||||
icon: const Icon(
|
||||
Icons.error,
|
||||
color: Colors.red,
|
||||
),
|
||||
backgroundColor: Colors.white,
|
||||
colorText: Colors.black,
|
||||
);
|
||||
} else {
|
||||
Get.snackbar(
|
||||
"Sukses Login",
|
||||
_message,
|
||||
icon: const Icon(
|
||||
Icons.check,
|
||||
color: Colors.green,
|
||||
),
|
||||
backgroundColor: Colors.white,
|
||||
colorText: Colors.black,
|
||||
);
|
||||
|
||||
// await 2 second then navigate to index page
|
||||
await Future.delayed(const Duration(milliseconds: 1500));
|
||||
Get.offAllNamed('/beforeEnter');
|
||||
}
|
||||
}
|
||||
|
||||
// for input checker
|
||||
String generateMd5(String input) {
|
||||
return md5.convert(utf8.encode(input)).toString();
|
||||
}
|
||||
|
||||
// bottom navigation bar
|
||||
BottomNavigationBar bottomNavigationBar() {
|
||||
return BottomNavigationBar(
|
||||
type: BottomNavigationBarType.fixed,
|
||||
items: const [
|
||||
BottomNavigationBarItem(
|
||||
icon: Icon(Icons.home),
|
||||
label: 'Home',
|
||||
),
|
||||
BottomNavigationBarItem(
|
||||
icon: Icon(Icons.login),
|
||||
label: 'Login',
|
||||
),
|
||||
BottomNavigationBarItem(
|
||||
icon: Icon(Icons.app_registration),
|
||||
label: 'Daftar',
|
||||
),
|
||||
],
|
||||
currentIndex: _indexTap.value,
|
||||
selectedItemColor: const Color.fromARGB(255, 148, 183, 229),
|
||||
onTap: _onItemTapped,
|
||||
);
|
||||
}
|
||||
}
|
||||
499
lib/controller/before_login/pendaftaranKurirController.dart
Normal file
499
lib/controller/before_login/pendaftaranKurirController.dart
Normal file
@ -0,0 +1,499 @@
|
||||
// ignore_for_file: file_names, non_constant_identifier_names
|
||||
|
||||
import 'dart:developer';
|
||||
import 'dart:typed_data';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter_easyloading/flutter_easyloading.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:image_picker/image_picker.dart';
|
||||
import 'package:kurir/api/beforeLoginAPI.dart';
|
||||
|
||||
// sini coba
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
|
||||
import 'dart:convert';
|
||||
import 'package:crypto/crypto.dart';
|
||||
|
||||
class PendaftaranKurirController extends GetxController {
|
||||
final formKey = GlobalKey<FormState>();
|
||||
|
||||
// ini untuk detail login
|
||||
final usernameController = TextEditingController();
|
||||
final passwordController = TextEditingController();
|
||||
final konfirmasiPasswordController = TextEditingController();
|
||||
RxBool passwordVisible = true.obs;
|
||||
RxBool konfirmasiPasswordVisible = true.obs;
|
||||
final FocusNode usernameFocusNode = FocusNode();
|
||||
final FocusNode passwordFocusNode = FocusNode();
|
||||
final FocusNode konfirmasiPasswordFocusNode = FocusNode();
|
||||
|
||||
// ini untuk detail kurir
|
||||
final nikController = TextEditingController();
|
||||
final namaController = TextEditingController();
|
||||
final emailController = TextEditingController();
|
||||
final noTelpController = TextEditingController();
|
||||
final alamatController = TextEditingController();
|
||||
final noPlatController = TextEditingController();
|
||||
final FocusNode nikFocusNode = FocusNode();
|
||||
final FocusNode namaFocusNode = FocusNode();
|
||||
final FocusNode emailFocusNode = FocusNode();
|
||||
final FocusNode noTelpFocusNode = FocusNode();
|
||||
final FocusNode alamatFocusNode = FocusNode();
|
||||
final FocusNode noPlatFocusNode = FocusNode();
|
||||
final FocusNode fotoProfilFocusNode = FocusNode();
|
||||
final FocusNode fotoKTPFocusNode = FocusNode();
|
||||
final FocusNode fotoKendaraanFocusNode = FocusNode();
|
||||
final FocusNode fotoHoldingKTPFocusNode = FocusNode();
|
||||
|
||||
// ini untuk foto
|
||||
RxBool isAdaFotoProfil = false.obs;
|
||||
RxBool isAdaFotoKTP = false.obs;
|
||||
RxBool isAdaFotoKTPHolding = false.obs;
|
||||
RxBool isAdaKenderaan = false.obs;
|
||||
|
||||
// storing image path
|
||||
String? imgProfil;
|
||||
String? imgKTP;
|
||||
String? imgKendaraan;
|
||||
String? imgHoldingKTP;
|
||||
|
||||
final ImagePicker _picker = ImagePicker();
|
||||
|
||||
XFile? _imageFile;
|
||||
|
||||
// create onimagebuttonpressed
|
||||
Future<void> _onImageButtonPressed(ImageSource source, String option) async {
|
||||
log('sini on image button pressed + $option');
|
||||
try {
|
||||
final XFile? pickedFile = await _picker.pickImage(source: source);
|
||||
_imageFile = pickedFile;
|
||||
// log("ini dia ");
|
||||
log(_imageFile!.path.toString());
|
||||
switch (option) {
|
||||
case "profil":
|
||||
imgProfil = _imageFile!.path.toString();
|
||||
isAdaFotoProfil.value = true;
|
||||
break;
|
||||
case "ktp":
|
||||
imgKTP = _imageFile!.path.toString();
|
||||
isAdaFotoKTP.value = true;
|
||||
|
||||
break;
|
||||
case "kendaraan":
|
||||
imgKendaraan = _imageFile!.path.toString();
|
||||
isAdaKenderaan.value = true;
|
||||
break;
|
||||
case "ktp_holding":
|
||||
imgHoldingKTP = _imageFile!.path.toString();
|
||||
isAdaFotoKTPHolding.value = true;
|
||||
break;
|
||||
}
|
||||
// log("ini dia " + imgKTP!);
|
||||
} catch (e) {
|
||||
log(e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
// show foto
|
||||
Future showFoto(String option) async {
|
||||
Uint8List? _bytes;
|
||||
// log("ini dia img ktp" + imgKTP!);
|
||||
// final appStorage = await getTemporaryDirectory();
|
||||
late String _initialPath;
|
||||
switch (option) {
|
||||
case "profil":
|
||||
_initialPath = imgProfil!;
|
||||
break;
|
||||
case "ktp":
|
||||
_initialPath = imgKTP!;
|
||||
break;
|
||||
case "kendaraan":
|
||||
_initialPath = imgKendaraan!;
|
||||
break;
|
||||
case "ktp_holding":
|
||||
_initialPath = imgHoldingKTP!;
|
||||
break;
|
||||
}
|
||||
final _file = File(_initialPath);
|
||||
if (_file.existsSync()) {
|
||||
log("ada");
|
||||
Uint8List bytes = await _file.readAsBytes();
|
||||
_bytes = bytes;
|
||||
//
|
||||
return await Get.bottomSheet(
|
||||
Container(
|
||||
height: MediaQuery.of(Get.context!).size.height / 2,
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
image: DecorationImage(
|
||||
image: MemoryImage(_bytes),
|
||||
fit: BoxFit.fill,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
} else {
|
||||
log("tidak ada");
|
||||
}
|
||||
|
||||
// show getx bottom sheet
|
||||
}
|
||||
|
||||
//delete foto on cache and storage
|
||||
Future _cek_and_delete() async {
|
||||
final appStorage = await getTemporaryDirectory();
|
||||
// // if (appStorage.existsSync()) {
|
||||
// // log("ada file");
|
||||
// // print all filename in directory
|
||||
final fileList = appStorage.listSync();
|
||||
log(fileList.toString() + "ini file list");
|
||||
if (fileList.isNotEmpty) {
|
||||
log("ada file");
|
||||
// print(fileList);
|
||||
for (var i = 0; i < fileList.length; i++) {
|
||||
final file = fileList[i];
|
||||
log(file.path);
|
||||
if (file.toString().contains(".jpg") ||
|
||||
file.toString().contains(".png") ||
|
||||
file.toString().contains(".jpeg") ||
|
||||
file.toString().contains(".JPG") ||
|
||||
file.toString().contains(".PNG") ||
|
||||
file.toString().contains(".JPEG")) {
|
||||
log("delete");
|
||||
await file.delete(recursive: true);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
log("tidak ada file");
|
||||
// print(fileList);
|
||||
}
|
||||
}
|
||||
|
||||
// choose option of photo
|
||||
Future<void> onChooseOption(String option) async {
|
||||
return Get.dialog(
|
||||
AlertDialog(
|
||||
// title: Text('Pilih'),
|
||||
content: const Text(
|
||||
"Pilih",
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
actions: <Widget>[
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
const SizedBox(),
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
_onImageButtonPressed(ImageSource.camera, option);
|
||||
Get.back();
|
||||
},
|
||||
child: const Text("Camera"),
|
||||
),
|
||||
const SizedBox(),
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
_onImageButtonPressed(ImageSource.gallery, option);
|
||||
Get.back();
|
||||
},
|
||||
child: const Text("Galeri"),
|
||||
),
|
||||
const SizedBox(),
|
||||
],
|
||||
)
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
log('Sini contoller pendaftaran kurir');
|
||||
// intro_message();
|
||||
super.onInit();
|
||||
}
|
||||
|
||||
@override
|
||||
void onReady() {
|
||||
// log('Sini contoller pendaftaran kurir');
|
||||
intro_message();
|
||||
super.onReady();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
// dispose formKey
|
||||
// ignore: invalid_use_of_protected_member
|
||||
formKey.currentState?.dispose();
|
||||
// dispose controller
|
||||
usernameController.dispose();
|
||||
passwordController.dispose();
|
||||
konfirmasiPasswordController.dispose();
|
||||
nikController.dispose();
|
||||
namaController.dispose();
|
||||
emailController.dispose();
|
||||
noTelpController.dispose();
|
||||
alamatController.dispose();
|
||||
noPlatController.dispose();
|
||||
|
||||
// dispose focusNode
|
||||
usernameFocusNode.dispose();
|
||||
passwordFocusNode.dispose();
|
||||
konfirmasiPasswordFocusNode.dispose();
|
||||
nikFocusNode.dispose();
|
||||
namaFocusNode.dispose();
|
||||
emailFocusNode.dispose();
|
||||
noTelpFocusNode.dispose();
|
||||
alamatFocusNode.dispose();
|
||||
noPlatFocusNode.dispose();
|
||||
fotoProfilFocusNode.dispose();
|
||||
fotoKTPFocusNode.dispose();
|
||||
fotoHoldingKTPFocusNode.dispose();
|
||||
fotoKendaraanFocusNode.dispose();
|
||||
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
// intro message
|
||||
Future intro_message() {
|
||||
return Get.dialog(
|
||||
WillPopScope(
|
||||
onWillPop: () async => false,
|
||||
child: AlertDialog(
|
||||
title: const Text('Info Penting', textAlign: TextAlign.center),
|
||||
content: const Text(
|
||||
"Silahkan isi data diri anda dengan benar\nData anda akan dievaluasi oleh admin sebelum anda dapat mendaftar ke dalam sistem",
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
actions: <Widget>[
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
const SizedBox(),
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
Get.back();
|
||||
},
|
||||
child: const Text("OK"),
|
||||
),
|
||||
const SizedBox(),
|
||||
],
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// before sign up and sign up process
|
||||
before_sign_up() {
|
||||
log("ini before sign up");
|
||||
// show get dialog
|
||||
return Get.dialog(AlertDialog(
|
||||
title: const Text("Pendaftaran Kurir", textAlign: TextAlign.center),
|
||||
content: const Text(
|
||||
"Yakin dengan data yang anda masukkan benar?\nAdmin akan mengevaluasi data yang anda masukkan sebelum menerima pendaftaran",
|
||||
textAlign: TextAlign.center),
|
||||
actions: [
|
||||
ElevatedButton(
|
||||
child: const Text('Tidak'),
|
||||
onPressed: () {
|
||||
Get.back();
|
||||
},
|
||||
),
|
||||
ElevatedButton(
|
||||
child: const Text('Ya'),
|
||||
style: ElevatedButton.styleFrom(
|
||||
primary: Colors.red,
|
||||
),
|
||||
onPressed: () {
|
||||
sign_up();
|
||||
// await _cek_and_delete();
|
||||
// await Get.offAllNamed(
|
||||
// '/index',
|
||||
// arguments: {"tap": 0},
|
||||
// );
|
||||
},
|
||||
),
|
||||
],
|
||||
));
|
||||
}
|
||||
|
||||
void sign_up() async {
|
||||
Get.back();
|
||||
String username = usernameController.text;
|
||||
String password = passwordController.text;
|
||||
String nik = nikController.text;
|
||||
String nama = namaController.text;
|
||||
String email = emailController.text;
|
||||
String noTelp = noTelpController.text;
|
||||
String alamat = alamatController.text;
|
||||
String noPlat = noPlatController.text;
|
||||
String fotoProfil = imgProfil!;
|
||||
String fotoKTP = imgKTP!;
|
||||
String fotoHoldingKTP = imgHoldingKTP!;
|
||||
String fotoKendaraan = imgKendaraan!;
|
||||
|
||||
Map<String, dynamic> data = {
|
||||
"username": username,
|
||||
"password": generateMd5(password),
|
||||
"nik": nik,
|
||||
"nama": nama,
|
||||
"email": email,
|
||||
"no_telp": noTelp,
|
||||
"alamat": alamat,
|
||||
"no_kenderaan": noPlat,
|
||||
"role": "kurir",
|
||||
};
|
||||
|
||||
try {
|
||||
await EasyLoading.show(
|
||||
status: 'Loading...',
|
||||
maskType: EasyLoadingMaskType.black,
|
||||
);
|
||||
Map<String, dynamic> inidia = await BeforeLoginApi.sign_up_kurir(
|
||||
data, fotoKTP, fotoHoldingKTP, fotoKendaraan, fotoProfil);
|
||||
|
||||
late String title, content;
|
||||
// ignore: prefer_typing_uninitialized_variables
|
||||
late var color, icon;
|
||||
|
||||
switch (inidia['status']) {
|
||||
case 200:
|
||||
title = "Pendaftaran Berhasil ";
|
||||
content = inidia['message'];
|
||||
color = Colors.green;
|
||||
icon = Icons.check;
|
||||
|
||||
break;
|
||||
case 400:
|
||||
title = "Pendaftaran Gagal ";
|
||||
content = inidia['message'];
|
||||
color = Colors.orange[400];
|
||||
icon = Icons.error;
|
||||
break;
|
||||
case 500:
|
||||
title = "Koneksi Bermasalah ";
|
||||
content = inidia['message'];
|
||||
color = Colors.red;
|
||||
icon = Icons.error;
|
||||
break;
|
||||
}
|
||||
Get.snackbar(
|
||||
title,
|
||||
content,
|
||||
icon: Icon(icon, color: Colors.white),
|
||||
backgroundColor: color,
|
||||
colorText: Colors.white,
|
||||
duration: const Duration(seconds: 3),
|
||||
);
|
||||
Get.dialog(
|
||||
WillPopScope(
|
||||
onWillPop: () {
|
||||
// Get.back();
|
||||
return Future.value(false);
|
||||
},
|
||||
child: AlertDialog(
|
||||
title: Text(title, textAlign: TextAlign.center),
|
||||
content: Text(content, textAlign: TextAlign.justify),
|
||||
actions: [
|
||||
ElevatedButton(
|
||||
child: const Text('OK'),
|
||||
onPressed: () async {
|
||||
if (inidia['status'] == 200) {
|
||||
await _cek_and_delete();
|
||||
await Get.offAllNamed(
|
||||
'/index',
|
||||
arguments: {
|
||||
"tap": 0,
|
||||
'history': [0]
|
||||
},
|
||||
);
|
||||
} else {
|
||||
Get.back();
|
||||
switch (inidia['focus']) {
|
||||
case 'nik':
|
||||
nikFocusNode.requestFocus();
|
||||
break;
|
||||
case 'no_telp':
|
||||
noTelpFocusNode.requestFocus();
|
||||
break;
|
||||
case 'email':
|
||||
emailFocusNode.requestFocus();
|
||||
break;
|
||||
}
|
||||
}
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
//
|
||||
await EasyLoading.dismiss();
|
||||
} catch (e) {
|
||||
log(e.toString());
|
||||
}
|
||||
|
||||
// return BeforeLoginApi.sign_up(
|
||||
// data, fotoKTP, fotoHoldingKTP, fotoKendaraan, fotoProfil)
|
||||
// .then((response) {
|
||||
// log(response.toString());
|
||||
// }).catchError((e) {
|
||||
// log(e.toString());
|
||||
// }).whenComplete(() {
|
||||
// log("complete");
|
||||
// });
|
||||
|
||||
// log("sini berlaku proses sign up");
|
||||
}
|
||||
|
||||
// for input checker
|
||||
String generateMd5(String input) {
|
||||
return md5.convert(utf8.encode(input)).toString();
|
||||
}
|
||||
|
||||
bool email_checker(String email) {
|
||||
RegExp regex = RegExp(
|
||||
r'^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$');
|
||||
return regex.hasMatch(email);
|
||||
// return false;
|
||||
}
|
||||
|
||||
// back button alert box
|
||||
willPopScopeWidget() {
|
||||
// create get dialog
|
||||
return Get.dialog(
|
||||
AlertDialog(
|
||||
title: const Text('Konfirmasi'),
|
||||
content: const Text('Anda yakin ingin keluar dari halaman ini?'),
|
||||
actions: [
|
||||
ElevatedButton(
|
||||
child: const Text('Tidak'),
|
||||
onPressed: () {
|
||||
Get.back();
|
||||
},
|
||||
),
|
||||
ElevatedButton(
|
||||
child: const Text('Ya'),
|
||||
style: ElevatedButton.styleFrom(
|
||||
primary: Colors.red,
|
||||
),
|
||||
onPressed: () async {
|
||||
await _cek_and_delete();
|
||||
await Get.offAllNamed(
|
||||
'/index',
|
||||
arguments: {
|
||||
"tap": 0,
|
||||
'history': [0]
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
427
lib/controller/before_login/pendaftaranPengirimController.dart
Normal file
427
lib/controller/before_login/pendaftaranPengirimController.dart
Normal file
@ -0,0 +1,427 @@
|
||||
// ignore_for_file: file_names, non_constant_identifier_names
|
||||
|
||||
import 'dart:convert';
|
||||
import 'dart:developer';
|
||||
import 'dart:io';
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:crypto/crypto.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_easyloading/flutter_easyloading.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:image_picker/image_picker.dart';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
// import 'package:provider/provider.dart';
|
||||
|
||||
import '../../api/beforeLoginAPI.dart';
|
||||
|
||||
class PendaftaranPengirimController extends GetxController {
|
||||
final formKey = GlobalKey<FormState>(); // form key
|
||||
|
||||
// ini untuk detail login
|
||||
final usernameController = TextEditingController();
|
||||
final passwordController = TextEditingController();
|
||||
final konfirmasiPasswordController = TextEditingController();
|
||||
RxBool passwordVisible = false.obs;
|
||||
RxBool konfirmasiPasswordVisible = false.obs;
|
||||
final FocusNode usernameFocusNode = FocusNode();
|
||||
final FocusNode passwordFocusNode = FocusNode();
|
||||
final FocusNode konfirmasiPasswordFocusNode = FocusNode();
|
||||
|
||||
// ini untuk detail pengirim
|
||||
final namaController = TextEditingController();
|
||||
final emailController = TextEditingController();
|
||||
final noTelpController = TextEditingController();
|
||||
final alamatController = TextEditingController();
|
||||
final FocusNode namaFocusNode = FocusNode();
|
||||
final FocusNode emailFocusNode = FocusNode();
|
||||
final FocusNode noTelpFocusNode = FocusNode();
|
||||
final FocusNode alamatFocusNode = FocusNode();
|
||||
|
||||
// ini untuk foto
|
||||
RxBool isAdaFotoProfil = false.obs;
|
||||
|
||||
// stroing image path
|
||||
String? imgProfil;
|
||||
|
||||
final ImagePicker _picker = ImagePicker();
|
||||
XFile? _imageFile;
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
log('sini init controller pendaftran pengirim');
|
||||
super.onInit();
|
||||
}
|
||||
|
||||
@override
|
||||
void onReady() {
|
||||
intro_message();
|
||||
super.onReady();
|
||||
}
|
||||
|
||||
// intro message
|
||||
Future intro_message() {
|
||||
return Get.dialog(
|
||||
WillPopScope(
|
||||
onWillPop: () async => false,
|
||||
child: AlertDialog(
|
||||
title: const Text('Info Penting', textAlign: TextAlign.center),
|
||||
content: const Text(
|
||||
"Silahkan isi data diri anda dengan benar\nData anda akan dievaluasi oleh admin sebelum anda dapat mendaftar ke dalam sistem",
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
actions: <Widget>[
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
const SizedBox(),
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
Get.back();
|
||||
},
|
||||
child: const Text("OK"),
|
||||
),
|
||||
const SizedBox(),
|
||||
],
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// choose option of photo
|
||||
Future<void> onChooseOption(String option) async {
|
||||
return Get.dialog(
|
||||
AlertDialog(
|
||||
// title: Text('Pilih'),
|
||||
content: const Text(
|
||||
"Pilih",
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
actions: <Widget>[
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
const SizedBox(),
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
_onImageButtonPressed(ImageSource.camera, option);
|
||||
Get.back();
|
||||
},
|
||||
child: const Text("Camera"),
|
||||
),
|
||||
const SizedBox(),
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
_onImageButtonPressed(ImageSource.gallery, option);
|
||||
Get.back();
|
||||
},
|
||||
child: const Text("Galeri"),
|
||||
),
|
||||
const SizedBox(),
|
||||
],
|
||||
)
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// create onimagebuttonpressed
|
||||
Future<void> _onImageButtonPressed(ImageSource source, String option) async {
|
||||
log('sini on image button pressed + $option');
|
||||
try {
|
||||
final XFile? pickedFile = await _picker.pickImage(source: source);
|
||||
_imageFile = pickedFile;
|
||||
// log("ini dia ");
|
||||
log(_imageFile!.path.toString());
|
||||
switch (option) {
|
||||
case "profil":
|
||||
imgProfil = _imageFile!.path.toString();
|
||||
isAdaFotoProfil.value = true;
|
||||
break;
|
||||
}
|
||||
// log("ini dia " + imgKTP!);
|
||||
} catch (e) {
|
||||
log(e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
// show foto
|
||||
Future showFoto(String option) async {
|
||||
Uint8List? _bytes;
|
||||
// log("ini dia img ktp" + imgKTP!);
|
||||
// final appStorage = await getTemporaryDirectory();
|
||||
late String _initialPath;
|
||||
switch (option) {
|
||||
case "profil":
|
||||
_initialPath = imgProfil!;
|
||||
break;
|
||||
}
|
||||
final _file = File(_initialPath);
|
||||
if (_file.existsSync()) {
|
||||
log("ada");
|
||||
Uint8List bytes = await _file.readAsBytes();
|
||||
_bytes = bytes;
|
||||
//
|
||||
return await Get.bottomSheet(
|
||||
Container(
|
||||
height: MediaQuery.of(Get.context!).size.height / 2,
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
image: DecorationImage(
|
||||
image: MemoryImage(_bytes),
|
||||
fit: BoxFit.fill,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
} else {
|
||||
log("tidak ada");
|
||||
}
|
||||
|
||||
// show getx bottom sheet
|
||||
}
|
||||
|
||||
//delete foto on cache and storage
|
||||
Future _cek_and_delete() async {
|
||||
final appStorage = await getTemporaryDirectory();
|
||||
// // if (appStorage.existsSync()) {
|
||||
// // log("ada file");
|
||||
// // print all filename in directory
|
||||
final fileList = appStorage.listSync();
|
||||
log(fileList.toString() + "ini file list");
|
||||
if (fileList.isNotEmpty) {
|
||||
log("ada file");
|
||||
// print(fileList);
|
||||
for (var i = 0; i < fileList.length; i++) {
|
||||
final file = fileList[i];
|
||||
log(file.path);
|
||||
if (file.toString().contains(".jpg") ||
|
||||
file.toString().contains(".png") ||
|
||||
file.toString().contains(".jpeg") ||
|
||||
file.toString().contains(".JPG") ||
|
||||
file.toString().contains(".PNG") ||
|
||||
file.toString().contains(".JPEG")) {
|
||||
log("delete");
|
||||
await file.delete(recursive: true);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
log("tidak ada file");
|
||||
// print(fileList);
|
||||
}
|
||||
}
|
||||
|
||||
// before sign up and sign up process
|
||||
before_sign_up(BuildContext context) async {
|
||||
log("ini before sign up");
|
||||
// show get dialog
|
||||
return Get.dialog(AlertDialog(
|
||||
title: const Text("Pendaftaran Kurir", textAlign: TextAlign.center),
|
||||
content: const Text(
|
||||
"Yakin dengan data yang anda masukkan benar?\nAdmin akan mengevaluasi data yang anda masukkan sebelum menerima pendaftaran",
|
||||
textAlign: TextAlign.center),
|
||||
actions: [
|
||||
ElevatedButton(
|
||||
child: const Text('Tidak'),
|
||||
onPressed: () {
|
||||
Get.back();
|
||||
},
|
||||
),
|
||||
ElevatedButton(
|
||||
child: const Text('Ya'),
|
||||
style: ElevatedButton.styleFrom(
|
||||
primary: Colors.red,
|
||||
),
|
||||
onPressed: () {
|
||||
// log("sini sign up");
|
||||
_sign_up(context);
|
||||
// await _cek_and_delete();
|
||||
// await Get.offAllNamed(
|
||||
// '/index',
|
||||
// arguments: {"tap": 0},
|
||||
// );
|
||||
},
|
||||
),
|
||||
],
|
||||
));
|
||||
}
|
||||
|
||||
void _sign_up(BuildContext context) async {
|
||||
Get.back();
|
||||
String username = usernameController.text;
|
||||
String password = passwordController.text;
|
||||
String nama = namaController.text;
|
||||
String email = emailController.text;
|
||||
String noTelp = noTelpController.text;
|
||||
String alamat = alamatController.text;
|
||||
String fotoProfil = imgProfil!;
|
||||
|
||||
Map<String, dynamic> data = {
|
||||
"username": username,
|
||||
"password": generateMd5(password),
|
||||
"nama": nama,
|
||||
"email": email,
|
||||
"no_telp": noTelp,
|
||||
"alamat": alamat,
|
||||
"role": "pengirim",
|
||||
};
|
||||
|
||||
// final BeforeLoginApi _api =
|
||||
// Provider.of<BeforeLoginApi>(context, listen: false);
|
||||
|
||||
try {
|
||||
await EasyLoading.show(
|
||||
status: 'Cek Koneksi...',
|
||||
maskType: EasyLoadingMaskType.black,
|
||||
);
|
||||
Map<String, dynamic> _inidia =
|
||||
await BeforeLoginApi.sign_up_pengirim(data, fotoProfil);
|
||||
|
||||
// final Map<String, dynamic> _inidia = await _api.sign_up_pengirim(
|
||||
// data,
|
||||
// fotoProfil,
|
||||
// );
|
||||
await EasyLoading.dismiss();
|
||||
|
||||
log(_inidia.toString());
|
||||
late String title, content;
|
||||
// ignore: prefer_typing_uninitialized_variables
|
||||
late var color, icon;
|
||||
|
||||
switch (_inidia['status']) {
|
||||
case 200:
|
||||
title = "Pendaftaran Berhasil ";
|
||||
content = _inidia['message'];
|
||||
color = Colors.green;
|
||||
icon = Icons.check;
|
||||
|
||||
break;
|
||||
case 400:
|
||||
title = "Pendaftaran Gagal ";
|
||||
content = _inidia['message'];
|
||||
color = Colors.orange[400];
|
||||
icon = Icons.error;
|
||||
break;
|
||||
case 500:
|
||||
title = "Koneksi Bermasalah ";
|
||||
content = _inidia['message'];
|
||||
color = Colors.red;
|
||||
icon = Icons.error;
|
||||
break;
|
||||
}
|
||||
Get.snackbar(
|
||||
title,
|
||||
content,
|
||||
icon: Icon(icon, color: Colors.white),
|
||||
backgroundColor: color,
|
||||
colorText: Colors.white,
|
||||
duration: const Duration(seconds: 3),
|
||||
);
|
||||
Get.dialog(
|
||||
WillPopScope(
|
||||
onWillPop: () {
|
||||
// Get.back();
|
||||
return Future.value(false);
|
||||
},
|
||||
child: AlertDialog(
|
||||
title: Text(title, textAlign: TextAlign.center),
|
||||
content: Text(content, textAlign: TextAlign.justify),
|
||||
actions: [
|
||||
ElevatedButton(
|
||||
child: const Text('OK'),
|
||||
onPressed: () async {
|
||||
if (_inidia['status'] == 200) {
|
||||
// Get.back();
|
||||
await _cek_and_delete();
|
||||
await Get.offAllNamed(
|
||||
'/index',
|
||||
arguments: {
|
||||
"tap": 0,
|
||||
'history': [0]
|
||||
},
|
||||
);
|
||||
} else {
|
||||
Get.back();
|
||||
switch (_inidia['focus']) {
|
||||
case 'no_telp':
|
||||
noTelpFocusNode.requestFocus();
|
||||
break;
|
||||
case 'email':
|
||||
emailFocusNode.requestFocus();
|
||||
break;
|
||||
}
|
||||
}
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
//
|
||||
await EasyLoading.dismiss();
|
||||
} catch (e) {
|
||||
log(e.toString());
|
||||
}
|
||||
|
||||
// return BeforeLoginApi.sign_up(
|
||||
// data, fotoKTP, fotoHoldingKTP, fotoKendaraan, fotoProfil)
|
||||
// .then((response) {
|
||||
// log(response.toString());
|
||||
// }).catchError((e) {
|
||||
// log(e.toString());
|
||||
// }).whenComplete(() {
|
||||
// log("complete");
|
||||
// });
|
||||
|
||||
// log("sini berlaku proses sign up");
|
||||
}
|
||||
|
||||
// for input checker
|
||||
String generateMd5(String input) {
|
||||
return md5.convert(utf8.encode(input)).toString();
|
||||
}
|
||||
|
||||
bool email_checker(String email) {
|
||||
RegExp regex = RegExp(
|
||||
r'^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$');
|
||||
return regex.hasMatch(email);
|
||||
// return false;
|
||||
}
|
||||
|
||||
willPopScopeWidget() {
|
||||
// create get dialog
|
||||
return Get.dialog(
|
||||
AlertDialog(
|
||||
title: const Text('Konfirmasi'),
|
||||
content: const Text(
|
||||
'Anda yakin ingin keluar dari halaman ini?\nPendaftran anda akan dibatalkan'),
|
||||
actions: [
|
||||
ElevatedButton(
|
||||
child: const Text('Tidak'),
|
||||
onPressed: () {
|
||||
Get.back();
|
||||
},
|
||||
),
|
||||
ElevatedButton(
|
||||
child: const Text('Ya'),
|
||||
style: ElevatedButton.styleFrom(
|
||||
primary: Colors.red,
|
||||
),
|
||||
onPressed: () async {
|
||||
// await _cek_and_delete();
|
||||
await Get.offAllNamed(
|
||||
'/index',
|
||||
arguments: {
|
||||
"tap": 0,
|
||||
'history': [0]
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
33
lib/controller/splashController.dart
Normal file
33
lib/controller/splashController.dart
Normal file
@ -0,0 +1,33 @@
|
||||
// ignore_for_file: file_names
|
||||
|
||||
import 'dart:developer';
|
||||
|
||||
import 'package:get/get.dart';
|
||||
import 'package:get_storage/get_storage.dart';
|
||||
|
||||
class SplashController extends GetxController {
|
||||
final storage = GetStorage();
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
Future.delayed(const Duration(milliseconds: 2500), () {
|
||||
log('SplashController onInit');
|
||||
// Get.offAllNamed('/index');
|
||||
// goto to /index with argument tap : 0
|
||||
final _role = (storage.read('role') != null) ? storage.read('role') : '';
|
||||
|
||||
if (_role == 'pengirim' || _role == 'kurir') {
|
||||
Get.offAllNamed('/beforeEnter');
|
||||
} else {
|
||||
Get.offAllNamed(
|
||||
'/index',
|
||||
arguments: {
|
||||
"tap": 0,
|
||||
"history": [0],
|
||||
},
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user