another commit
This commit is contained in:
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],
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user