first commit

This commit is contained in:
Sas Andy
2025-01-31 10:12:08 +07:00
commit 6554441a4b
180 changed files with 8490 additions and 0 deletions

View File

@@ -0,0 +1,63 @@
import 'package:equatable/equatable.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:ticket_booth/model/booth.dart';
import 'package:ticket_booth/provider/dio_provider.dart';
import 'package:ticket_booth/repository/base_repository.dart';
import 'package:ticket_booth/repository/booth_repository.dart';
abstract class BoothListState extends Equatable {
final DateTime date;
const BoothListState(this.date);
@override
List<Object?> get props => [date];
}
class BoothListStateInit extends BoothListState {
BoothListStateInit() : super(DateTime.now());
}
class BoothListStateLoading extends BoothListState {
BoothListStateLoading() : super(DateTime.now());
}
class BoothListStateError extends BoothListState {
final String message;
BoothListStateError({
required this.message,
}) : super(DateTime.now());
}
class BoothListStateDone extends BoothListState {
final List<Booth> model;
BoothListStateDone({
required this.model,
}) : super(DateTime.now());
}
//notifier
class BoothListNotifier extends StateNotifier<BoothListState> {
final Ref ref;
BoothListNotifier({
required this.ref,
}) : super(BoothListStateInit());
void list({required hostIp}) async {
try {
state = BoothListStateLoading();
final dio = ref.read(dioProvider);
final resp = await BoothRepository(dio: dio).getData(hostIP: hostIp);
state = BoothListStateDone(model: resp);
} catch (e) {
if (e is BaseRepositoryException) {
state = BoothListStateError(message: e.message);
} else {
state = BoothListStateError(message: e.toString());
}
}
}
}
//provider
final BoothListProvider =
StateNotifierProvider<BoothListNotifier, BoothListState>(
(ref) => BoothListNotifier(ref: ref));

View File

@@ -0,0 +1,63 @@
import 'package:equatable/equatable.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:ticket_booth/model/branch_model.dart';
import 'package:ticket_booth/provider/dio_provider.dart';
import 'package:ticket_booth/repository/base_repository.dart';
import 'package:ticket_booth/repository/booth_repository.dart';
abstract class BranchListState extends Equatable {
final DateTime date;
const BranchListState(this.date);
@override
List<Object?> get props => [date];
}
class BranchListStateInit extends BranchListState {
BranchListStateInit() : super(DateTime.now());
}
class BranchListStateLoading extends BranchListState {
BranchListStateLoading() : super(DateTime.now());
}
class BranchListStateError extends BranchListState {
final String message;
BranchListStateError({
required this.message,
}) : super(DateTime.now());
}
class BranchListStateDone extends BranchListState {
final List<BranchModel> model;
BranchListStateDone({
required this.model,
}) : super(DateTime.now());
}
//notifier
class BranchListNotifier extends StateNotifier<BranchListState> {
final Ref ref;
BranchListNotifier({
required this.ref,
}) : super(BranchListStateInit());
void list({required hostIp}) async {
try {
state = BranchListStateLoading();
final dio = ref.read(dioProvider);
final resp = await BoothRepository(dio: dio).getBranch(hostIP: hostIp);
state = BranchListStateDone(model: resp);
} catch (e) {
if (e is BaseRepositoryException) {
state = BranchListStateError(message: e.message);
} else {
state = BranchListStateError(message: e.toString());
}
}
}
}
//provider
final BranchListProvider =
StateNotifierProvider<BranchListNotifier, BranchListState>(
(ref) => BranchListNotifier(ref: ref));

View File

@@ -0,0 +1,496 @@
import 'dart:convert';
import 'package:clippy_flutter/ticket.dart';
import 'package:esc_pos_utils/esc_pos_utils.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:flutter_pos_printer_platform_image_3/flutter_pos_printer_platform_image_3.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:ticket_booth/app/print_ticket.dart';
import 'package:ticket_booth/model/branch_model.dart';
import 'package:ticket_booth/model/cabapility_model.dart';
import 'package:ticket_booth/screen/widgets/error_dialog.dart';
import '../../app/constant.dart';
import '../../model/booth.dart';
import '../../model/printer_device.dart';
class FormInput extends HookConsumerWidget {
FormInput(
{Key? key,
required this.selected_booth,
required this.pm,
required this.booth,
required this.selected_printer,
required this.prnt,
required this.hostIpController,
required this.hostQrController,
required this.headerDisplayController,
required this.footerDisplayController,
required this.headerTicketController,
required this.footerTicketController,
required this.isLoading,
required this.capabilityList,
required this.selectedCapability,
required this.getServiceBooth,
required this.branch,
required this.selected_branch})
: super(key: key);
final ValueNotifier<Booth> selected_booth;
final ValueNotifier<List<Booth>> booth;
final ValueNotifier<List<BranchModel>> branch;
final ValueNotifier<BranchModel> selected_branch;
final ValueNotifier<PrinterDev?> selected_printer;
final ValueNotifier<List<PrinterDev>> prnt;
final ValueNotifier<List<CapabilityProfileModel>> capabilityList;
final ValueNotifier<CapabilityProfileModel?> selectedCapability;
final TextEditingController hostIpController;
final TextEditingController hostQrController;
final TextEditingController headerDisplayController;
final TextEditingController footerDisplayController;
final TextEditingController headerTicketController;
final TextEditingController footerTicketController;
final PrinterManager pm;
final Function getServiceBooth;
final bool isLoading;
@override
Widget build(BuildContext context, WidgetRef ref) {
final hostIpError = useState(false);
final hostQrError = useState(false);
;
final usbStream =
useStream<USBStatus>(pm.stateUSB, initialData: USBStatus.none);
_connectDevice(PrinterDev selectedPrinter, PrinterType type,
{bool reconnect = true, String? ipAddress = null}) async {
try {
await pm.connect(
type: type,
model: UsbPrinterInput(
name: selectedPrinter.deviceName,
productId: selectedPrinter.productId,
vendorId: selectedPrinter.vendorId));
} catch (e) {
print(e);
}
}
return Row(
children: [
SizedBox(
width: Constant.getActualX(context: context, x: 625),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
SizedBox(
child: Tooltip(
message: "Pilih salah satu cabang ",
child: Text(
'Cabang*',
style: Constant.label(context: context),
),
),
),
SizedBox(
height: Constant.getActualY(context: context, y: 60),
child: DropdownButtonFormField<BranchModel>(
style: Constant.normal(context: context)
.copyWith(color: Colors.black),
decoration: const InputDecoration(
border: OutlineInputBorder(
borderRadius: BorderRadius.all(
Radius.circular(8),
),
),
),
menuMaxHeight: Constant.getActualY(context: context, y: 500),
hint: Text(selected_branch.value.mBranchName ?? ''),
items: branch.value
.map((e) => DropdownMenuItem<BranchModel>(
value: e, child: Text(e.mBranchName ?? '')))
.toList(),
onChanged: (BranchModel? e) {
// print(e);
selected_branch.value = e!;
},
),
),
SizedBox(
height: Constant.getActualY(context: context, y: 20),
),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
SizedBox(
width: Constant.getActualX(context: context, x: 170),
child: Tooltip(
message:
"Pilih salah satu capability profile yang akan digunakan",
child: Text(
'Printer*',
style: Constant.label(context: context),
),
),
),
SizedBox(
width: Constant.getActualX(context: context, x: 170),
child: Tooltip(
message:
"Pilih salah satu printer yang akan digunakan",
child: Text(
'Capability Profile*',
style: Constant.label(context: context),
),
),
),
SizedBox(
width: Constant.getActualX(context: context, x: 100),
),
SizedBox(
width: Constant.getActualX(context: context, x: 100),
)
],
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
SizedBox(
width: Constant.getActualX(context: context, x: 170),
height: Constant.getActualY(context: context, y: 60),
child: DropdownButtonFormField<PrinterDev>(
value: selected_printer.value,
isExpanded: true,
style: Constant.normal(context: context)
.copyWith(color: Colors.black),
decoration: InputDecoration(
border: OutlineInputBorder(
borderRadius: BorderRadius.all(
Radius.circular(8),
),
),
),
menuMaxHeight:
Constant.getActualY(context: context, y: 500),
hint: Text(
selected_printer.value?.deviceName
.replaceAll(' ', '\u00A0') ??
'',
// softWrap: true,
overflow: TextOverflow.ellipsis,
),
items: prnt.value
.map((e) => DropdownMenuItem<PrinterDev>(
value: e,
child: Text(
e.deviceName.replaceAll(' ', '\u00A0'),
// softWrap: true,
overflow: TextOverflow.ellipsis,
)))
.toList(),
onChanged: (PrinterDev? e) {
selected_printer.value = e!;
},
)),
SizedBox(
width: Constant.getActualX(context: context, x: 170),
height: Constant.getActualY(context: context, y: 60),
child:
DropdownButtonFormField<CapabilityProfileModel>(
value: selectedCapability.value,
isExpanded: true,
style: Constant.normal(context: context)
.copyWith(color: Colors.black),
decoration: InputDecoration(
border: OutlineInputBorder(
borderRadius: BorderRadius.all(
Radius.circular(8),
),
),
),
menuMaxHeight:
Constant.getActualY(context: context, y: 500),
hint: Text(
selectedCapability.value?.key
?.replaceAll(' ', '\u00A0') ??
'',
// softWrap: true,
overflow: TextOverflow.ellipsis,
),
items: capabilityList.value
.map((e) =>
DropdownMenuItem<CapabilityProfileModel>(
value: e,
child: Text(
e.key!.replaceAll(' ', '\u00A0'),
// softWrap: true,
overflow: TextOverflow.ellipsis,
)))
.toList(),
onChanged: (CapabilityProfileModel? e) {
selectedCapability.value = e!;
},
)),
SizedBox(
// width: Constant.getActualX(context: context, x: 100),
height: Constant.getActualY(context: context, y: 60),
child: ElevatedButton(
style: ElevatedButton.styleFrom(
backgroundColor: Colors.red),
onPressed: () {
try {
if (selected_printer.value != null) {
_connectDevice(
selected_printer.value!, PrinterType.usb);
} else {
throw Exception("Printer tidak dipilih");
}
} catch (e) {
ErrorDialog(context, e.toString(), 'ERROR');
print(e);
}
},
child: Tooltip(
message:
"Tombol untuk menyambungkan printer yang elah dipilih",
child: Text(
"Connect",
style: Constant.label(context: context)
.copyWith(color: Colors.white),
),
)),
),
SizedBox(
// width: Constant.getActualX(context: context, x: 100),
height: Constant.getActualY(context: context, y: 60),
child: ElevatedButton(
style: ElevatedButton.styleFrom(
backgroundColor: Colors.green),
onPressed: () {
try {
PrintTicket().printTest();
} catch (e) {
ErrorDialog(context, e.toString(), 'ERROR');
print(e);
}
},
child: Tooltip(
message:
"Tombol untuk tes print, setelah terhubung akan mencetak teks tes print",
child: Text(
"Test Print",
style: Constant.label(context: context)
.copyWith(color: Colors.white),
),
)),
),
],
),
],
),
SizedBox(
height: Constant.getActualY(context: context, y: 20),
),
Tooltip(
message:
"Domain yang akan digunakan untuk mendapatkan daftar layanan dan nomor antrian",
child: Text(
'Host IP*',
style: Constant.label(context: context),
),
),
SizedBox(
height: Constant.getActualY(context: context, y: 60),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
SizedBox(
width: Constant.getActualX(context: context, x: 500),
child: TextField(
controller: hostIpController,
onChanged: (value) {
if (value.trim() == "") {
hostIpError.value = true;
}
if (value.trim() != "") {
hostIpError.value = false;
}
},
decoration: InputDecoration(
errorText:
hostIpError.value ? "Tidak boleh kosong" : null,
border: const OutlineInputBorder(),
focusedBorder: const OutlineInputBorder(
borderSide:
BorderSide(color: Colors.blue, width: 2)),
hintText: "http://devone.aplikasi.web.id",
hintStyle: Constant.label(context: context)),
),
),
SizedBox(
// width: Constant.getActualX(context: context, x: 200),
height: Constant.getActualY(context: context, y: 60),
child: ElevatedButton(
style: ElevatedButton.styleFrom(
backgroundColor: Colors.green),
onPressed: hostIpController.text == ""
? null
: () {
getServiceBooth();
},
child: Tooltip(
message:
"Tombol untuk menampilkan daftar layanan apabila tidak muncul",
child: isLoading
? CircularProgressIndicator(
color: Colors.white,
)
: Text(
"Layanan ",
style: Constant.label(context: context)
.copyWith(color: Colors.white),
),
)),
),
],
),
),
SizedBox(
height: Constant.getActualY(context: context, y: 20),
),
Tooltip(
message:
"Teks yang akan di cetak dibagian atas tiket. Maksimal 2 baris",
child: Text(
'Header Ticket',
style: Constant.label(context: context),
),
),
SizedBox(
height: Constant.getActualY(context: context, y: 80),
child: TextField(
controller: headerTicketController,
maxLines: 2,
decoration: InputDecoration(
border: const OutlineInputBorder(),
hintText: "Masukkan header ticket",
hintStyle: Constant.label(context: context)),
),
),
],
),
),
SizedBox(
width: Constant.getActualX(context: context, x: 50),
),
SizedBox(
width: Constant.getActualX(context: context, x: 625),
child:
Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
Tooltip(
message: "Teks yang akan di tampilkan di display bagian atas",
child: Text(
'Header Display',
style: Constant.label(context: context),
),
),
SizedBox(
height: Constant.getActualY(context: context, y: 60),
child: TextField(
controller: headerDisplayController,
decoration: InputDecoration(
border: OutlineInputBorder(),
hintText: "Masukkan header display",
hintStyle: Constant.label(context: context)),
),
),
SizedBox(
height: Constant.getActualY(context: context, y: 20),
),
Tooltip(
message: "Teks yang akan di tampilkan di bagian bawah display",
child: Text(
'Footer Display',
style: Constant.label(context: context),
),
),
SizedBox(
height: Constant.getActualY(context: context, y: 60),
child: TextField(
controller: footerDisplayController,
decoration: InputDecoration(
border: OutlineInputBorder(),
hintText: "Masukkan footer display",
hintStyle: Constant.label(context: context)),
),
),
SizedBox(
height: Constant.getActualY(context: context, y: 20),
),
SizedBox(
child: Tooltip(
message: "Pilih salah satu booth ",
child: Text(
'Booth*',
style: Constant.label(context: context),
),
),
),
SizedBox(
height: Constant.getActualY(context: context, y: 60),
child: DropdownButtonFormField<Booth>(
style: Constant.normal(context: context)
.copyWith(color: Colors.black),
decoration: const InputDecoration(
border: OutlineInputBorder(
borderRadius: BorderRadius.all(
Radius.circular(8),
),
),
),
menuMaxHeight: Constant.getActualY(context: context, y: 500),
hint: Text(selected_booth.value.name),
items: booth.value
.map((e) => DropdownMenuItem<Booth>(
value: e, child: Text(e.name)))
.toList(),
onChanged: (Booth? e) {
// print(e);
selected_booth.value = e!;
},
),
),
SizedBox(
height: Constant.getActualY(context: context, y: 20),
),
Tooltip(
message:
"Teks yang akan di cetak di bagian bawah tiket. Maksimal 2 baris",
child: Text(
'Footer Ticket',
style: Constant.label(context: context),
),
),
SizedBox(
height: Constant.getActualY(context: context, y: 80),
child: TextField(
maxLines: 2,
controller: footerTicketController,
decoration: InputDecoration(
border: const OutlineInputBorder(),
hintText: "Masukkan footer ticket",
hintStyle: Constant.label(context: context)),
),
),
]))
],
);
}
}

View File

@@ -0,0 +1,63 @@
import 'package:equatable/equatable.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:ticket_booth/model/layanan.dart';
import 'package:ticket_booth/provider/dio_provider.dart';
import 'package:ticket_booth/repository/base_repository.dart';
import 'package:ticket_booth/repository/service_repository.dart';
abstract class ServiceListState extends Equatable {
final DateTime date;
const ServiceListState(this.date);
@override
List<Object?> get props => [date];
}
class ServiceListStateInit extends ServiceListState {
ServiceListStateInit() : super(DateTime.now());
}
class ServiceListStateLoading extends ServiceListState {
ServiceListStateLoading() : super(DateTime.now());
}
class ServiceListStateError extends ServiceListState {
final String message;
ServiceListStateError({
required this.message,
}) : super(DateTime.now());
}
class ServiceListStateDone extends ServiceListState {
final List<Layanan> model;
ServiceListStateDone({
required this.model,
}) : super(DateTime.now());
}
//notifier
class ServiceListNotifier extends StateNotifier<ServiceListState> {
final Ref ref;
ServiceListNotifier({
required this.ref,
}) : super(ServiceListStateInit());
void list({required hostIp}) async {
try {
state = ServiceListStateLoading();
final dio = ref.read(dioProvider);
final resp = await ServiceRepository(dio: dio).getData(hostIp: hostIp);
state = ServiceListStateDone(model: resp);
} catch (e) {
if (e is BaseRepositoryException) {
state = ServiceListStateError(message: e.message);
} else {
state = ServiceListStateError(message: e.toString());
}
}
}
}
//provider
final ServiceListProvider =
StateNotifierProvider<ServiceListNotifier, ServiceListState>(
(ref) => ServiceListNotifier(ref: ref));

View File

@@ -0,0 +1,559 @@
import 'dart:convert';
import 'package:esc_pos_utils/esc_pos_utils.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:flutter_pos_printer_platform_image_3/flutter_pos_printer_platform_image_3.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:ticket_booth/app/print_ticket.dart';
import 'package:ticket_booth/app/route.dart';
import 'package:ticket_booth/model/booth.dart';
import 'package:ticket_booth/model/branch_model.dart';
import 'package:ticket_booth/model/cabapility_model.dart';
import 'package:ticket_booth/model/layanan.dart';
import 'package:ticket_booth/model/printer_device.dart';
import 'package:ticket_booth/provider/all_service_provider.dart';
import 'package:ticket_booth/screen/settings/booth_list_provider.dart';
import 'package:ticket_booth/screen/settings/branch_list_provider.dart';
import 'package:ticket_booth/screen/settings/service_list_provider.dart';
import '../../app/constant.dart';
import '../widgets/error_dialog.dart';
import 'form_input.dart';
class SettingScreen extends HookConsumerWidget {
const SettingScreen({super.key});
@override
Widget build(BuildContext context, WidgetRef ref) {
final hostIpController = useTextEditingController(text: '');
final hostQrController = useTextEditingController(text: '');
final headerDisplayController = useTextEditingController(text: '');
final footerDisplayController = useTextEditingController(text: '');
final footerTicketController = useTextEditingController(text: '');
final headerTicketController = useTextEditingController(text: '');
final activeLayanan = useState<List>(List.empty());
final capabilityProfileList = useState<List<CapabilityProfileModel>>([]);
final selectedCapabilityProfile = useState<CapabilityProfileModel?>(null);
final isLoading = useState(false);
final data = useState('N');
final PrinterManager pm = PrinterManager.instance;
final dvcs = useState<List<PrinterDev>>([]);
var devices3 = <PrinterDev>[];
final selectedBtnSize = useState<Map<String, dynamic>>({
'name': '4',
'message': 'Tombol yang akan ditampilkan berjumlah 4 ',
'rightLeftWidth': "300",
'centerWidth': "912",
'childAspectRatio': '1.559',
'mainAxisSpacing': "10",
'crossAxisSpacing': '10',
'btnHeight': "330",
'btnWidth': '300',
'column': '2'
});
final List<Map<String, dynamic>> listBtnSize = [
{
'name': '10',
'message': 'Tombol yang akan ditampilkan berjumlah 10',
'rightLeftWidth': "40",
'centerWidth': "1432",
'childAspectRatio': '1',
'mainAxisSpacing': "20",
'crossAxisSpacing': '10',
'btnHeight': "290",
'btnWidth': '260',
'column': '5'
},
{
'name': '8',
'message': 'Tombol yang akan ditampilkan berjumlah 8 ',
'rightLeftWidth': "100",
'centerWidth': "1312",
'childAspectRatio': '1.1',
'mainAxisSpacing': "40",
'crossAxisSpacing': '10',
'btnHeight': "310",
'btnWidth': '280',
'column': '4'
},
{
'name': '6',
'message': 'Tombol yang akan ditampilkan berjumlah 6 ',
'rightLeftWidth': "200",
'centerWidth': "1112",
'childAspectRatio': '1.33',
'mainAxisSpacing': "40",
'crossAxisSpacing': '10',
'btnHeight': "310",
'btnWidth': '280',
'column': '3'
},
{
'name': '4',
'message': 'Tombol yang akan ditampilkan berjumlah 4 ',
'rightLeftWidth': "300",
'centerWidth': "912",
'childAspectRatio': '1.559',
'mainAxisSpacing': "10",
'crossAxisSpacing': '10',
'btnHeight': "330",
'btnWidth': '300',
'column': '2'
}
];
getServiceBooth() async {
activeLayanan.value = List.empty();
ref.read(BoothListProvider.notifier).list(hostIp: hostIpController.text);
ref
.read(ServiceListProvider.notifier)
.list(hostIp: hostIpController.text);
ref.read(BranchListProvider.notifier).list(hostIp: hostIpController.text);
}
_scan(PrinterType type) async {
// Find printers
pm.discovery(type: PrinterType.usb, isBle: false).listen((device) {
devices3.add(PrinterDev(
id: int.parse(device.productId ?? '0'),
deviceName: device.name,
address: device.address,
isBle: false,
vendorId: device.vendorId,
productId: device.productId,
));
});
}
full() async {
// await FullScreen.enterFullScreen(FullScreenMode.EMERSIVE_STICKY);
}
final lyn = useState<List<Layanan>>(List.empty());
final booth = useState<List<Booth>>(List.empty());
final branch = useState<List<BranchModel>>(List.empty());
final selected_printer = useState<PrinterDev?>(null);
final selected_booth =
useState<Booth>(Booth(name: 'Pilih salah satu', id: 0, code: 'b1'));
final selected_branch = useState<BranchModel>(
BranchModel(mBranchID: '0', mBranchName: 'Pilih salah satu cabang'));
Future delData() async {
// Obtain shared preferences.
try {
final prefs = await SharedPreferences.getInstance();
await prefs.remove('tb-westerindo');
} catch (e) {
print(e);
}
}
Future getData() async {
try {
final prefs = await SharedPreferences.getInstance();
var raw_data = prefs.getString('tb-westerindo') ?? 'a';
data.value = raw_data;
print(raw_data);
if (raw_data != 'a') {
lyn.value = ref.read(allServiceProvider);
var data = json.decode(raw_data);
selected_booth.value = Booth.fromJson(data['selectedBooth']);
selected_branch.value = BranchModel.fromJson(data['selectedBranch']);
selected_printer.value = PrinterDev.fromJson(data['selectedPrinter']);
hostIpController.text = data['hostIp'];
hostQrController.text = data['hostQrIp'];
headerDisplayController.text = data['headerDisplay'];
footerDisplayController.text = data['footerDisplay'];
footerTicketController.text = data['footerTicket'];
headerTicketController.text = data['headerTicket'];
activeLayanan.value = data['activeLayanan'] ?? List.empty();
selectedBtnSize.value = data['buttonSize'];
selectedCapabilityProfile.value =
CapabilityProfileModel.fromJson(data['selectedCapability']);
if (activeLayanan.value.isNotEmpty) {
activeLayanan.value.forEach((e) {
lyn.value.forEach((f) {
if (e == f.id) {
f.value = true;
}
});
});
}
}
} catch (e) {
print(e);
ErrorDialog(context, e.toString(), 'ERROR');
}
}
useEffect(() {
WidgetsBinding.instance.addPostFrameCallback((timeStamp) async {
await getData();
var capabilityList = await CapabilityProfile.getAvailableProfiles();
List<CapabilityProfileModel> cl = List.empty(growable: true);
for (var i = 0; i < capabilityList.length; i++) {
var data = capabilityList[i];
final model = CapabilityProfileModel.fromJson(data);
cl.add(model);
}
capabilityProfileList.value = cl;
var stb = capabilityProfileList.value.firstWhere(
(element) => element.key == selectedCapabilityProfile.value?.key,
orElse: () => CapabilityProfileModel());
if (stb.key != null) {
selectedCapabilityProfile.value = stb;
}
_scan(PrinterType.usb);
dvcs.value = devices3;
if (data.value != 'a') {
ref
.read(BoothListProvider.notifier)
.list(hostIp: hostIpController.text);
ref
.read(BranchListProvider.notifier)
.list(hostIp: hostIpController.text);
}
});
full();
return () {};
}, []);
ref.listen(BoothListProvider, (previous, next) {
if (next is BoothListStateLoading) {
isLoading.value = true;
} else if (next is BoothListStateError) {
ErrorDialog(context, next.message, 'ERROR');
isLoading.value = false;
} else if (next is BoothListStateDone) {
booth.value = next.model;
isLoading.value = false;
}
});
ref.listen(ServiceListProvider, (previous, next) {
if (next is ServiceListStateLoading) {
isLoading.value = true;
} else if (next is ServiceListStateError) {
ErrorDialog(context, next.message, 'ERROR');
isLoading.value = false;
} else if (next is ServiceListStateDone) {
// ref.read(allServiceProvider.notifier).state = next.model;
// print(ref.read(allServiceProvider));
lyn.value = next.model;
isLoading.value = false;
}
});
ref.listen(BranchListProvider, (previous, next) {
if (next is BranchListStateLoading) {
isLoading.value = true;
} else if (next is BranchListStateError) {
ErrorDialog(context, next.message, 'ERROR');
isLoading.value = false;
} else if (next is BranchListStateDone) {
// ref.read(allServiceProvider.notifier).state = next.model;
// print(ref.read(allServiceProvider));
branch.value = next.model;
isLoading.value = false;
}
});
Future<bool> saveData() async {
try {
final prefs = await SharedPreferences.getInstance();
final Map<String, dynamic> data = {
"headerDisplay": headerDisplayController.text != ''
? headerDisplayController.text
: 'Selamat Datang Di Pramita',
"footerDisplay": footerDisplayController.text != ''
? footerDisplayController.text
: 'Sentuh Salah Satu Layanan',
"footerTicket": footerTicketController.text != ''
? footerTicketController.text
: 'SCAN QR CODE UNTUK MELIHAT STATUS ANTRIAN',
"headerTicket": headerTicketController.text != ''
? headerTicketController.text
: 'Labratorium Medis & Klinik PRAMITA',
"hostQrIp": hostQrController.text,
"hostIp": hostIpController.text,
"selectedPrinter": selected_printer.value,
"selectedBooth": selected_booth.value,
"selectedBranch": selected_branch.value,
"activeLayanan": activeLayanan.value,
'buttonSize': selectedBtnSize.value,
"selectedCapability": selectedCapabilityProfile.value
};
json.encode(data);
await prefs.setString('tb-westerindo', json.encode(data));
return true;
} catch (e) {
ErrorDialog(context, e.toString(), 'ERROR');
print(e);
return false;
}
}
Color getColor(Set<MaterialState> states) {
const Set<MaterialState> interactiveStates = <MaterialState>{
MaterialState.pressed,
MaterialState.hovered,
MaterialState.focused,
};
if (states.any(interactiveStates.contains)) {
return Colors.blue;
}
if (states.contains(MaterialState.selected)) {
return Colors.green;
}
return Colors.white;
}
return Material(
child: Container(
height: Constant.getActualY(context: context, y: 982),
width: Constant.getActualX(context: context, x: 1512),
decoration: const BoxDecoration(
image: DecorationImage(
fit: BoxFit.cover,
image: AssetImage("assets/images/new-bg-icon.png"))),
child: Center(
child: Card(
color: Colors.white,
shadowColor: Colors.white,
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(10))),
elevation: 5,
child: SizedBox(
height: Constant.getActualY(context: context, y: 880),
width: Constant.getActualX(context: context, x: 1360),
child: Padding(
padding: EdgeInsets.symmetric(
horizontal: Constant.getActualX(context: context, x: 30),
vertical: Constant.getActualY(context: context, y: 30)),
child: SingleChildScrollView(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
// TextButton(
// onPressed: () {
// Navigator.of(context)
// .popAndPushNamed(displayRoute);
// // print(pm.currentStatusUSB);
// // print(pm.currentStatusUSB);
// },
// child: const Text('back')),
Text(
'Setting',
style: Constant.subTitle(context: context),
),
// TextButton(
// onPressed: () {
// delData();
// },
// child: const Text('Delete All')),
],
),
SizedBox(
height: Constant.getActualY(context: context, y: 30),
),
FormInput(
pm: pm,
selected_booth: selected_booth,
booth: booth,
selected_printer: selected_printer,
prnt: dvcs,
branch: branch,
selected_branch: selected_branch,
hostIpController: hostIpController,
hostQrController: hostQrController,
headerDisplayController: headerDisplayController,
footerDisplayController: footerDisplayController,
headerTicketController: headerTicketController,
getServiceBooth: getServiceBooth,
isLoading: isLoading.value,
selectedCapability: selectedCapabilityProfile,
capabilityList: capabilityProfileList,
footerTicketController: footerTicketController),
SizedBox(
height: Constant.getActualY(context: context, y: 20),
),
Container(
// color: Colors.red,
height: Constant.getActualY(context: context, y: 40),
child: Row(
children: [
Tooltip(
message: "Jumlah tombol pada display",
child: Text('Button display',
style: Constant.label(context: context)),
),
SizedBox(
width: Constant.getActualX(context: context, x: 10),
),
Row(
children: [
SizedBox(
width: Constant.getActualX(
context: context, x: 10),
),
Row(
children: listBtnSize
.map(
(e) => Row(
children: [
Checkbox(
fillColor: MaterialStateProperty
.resolveWith(getColor),
value: e['name'].toString() ==
selectedBtnSize
.value['name']
? true
: false,
onChanged: ((value) {
selectedBtnSize.value = e;
})),
SizedBox(
width: Constant.getActualX(
context: context, x: 3),
),
Tooltip(
message: e['message'].toString(),
child: Text(
e['name'].toString(),
style: Constant.normal(
context: context),
),
),
SizedBox(
width: Constant.getActualX(
context: context, x: 15),
),
],
),
)
.toList(),
),
],
),
],
),
),
SizedBox(
height: Constant.getActualY(context: context, y: 190),
child: GridView.count(
childAspectRatio:
Constant.getActualY(context: context, y: 150) /
Constant.getActualX(context: context, x: 15),
crossAxisCount: 3,
children: lyn.value
.map((e) => Row(
children: [
Transform.scale(
scale: 0.8,
child: CupertinoSwitch(
value: e.value,
onChanged: (val) {
if (val) {
var rw_data = json.encode(
activeLayanan.value);
List data =
json.decode(rw_data);
List actlyn = data;
actlyn.add(e.id);
activeLayanan.value = actlyn;
}
if (!val) {
var rw_data = json.encode(
activeLayanan.value);
List data =
json.decode(rw_data);
List actlyn = data;
actlyn.remove(e.id);
activeLayanan.value = actlyn;
}
e.value = val;
}),
),
Expanded(
child: e.isConsultDoctor == 'N'
? Text(
e.name,
maxLines: 2,
overflow: TextOverflow.ellipsis,
style: Constant.normal(
context: context),
)
: Text(
"${e.name} ${e.doctorName}",
maxLines: 2,
overflow: TextOverflow.ellipsis,
style: Constant.normal(
context: context),
),
)
],
))
.toList()),
),
SizedBox(
height: Constant.getActualY(context: context, y: 20),
),
Center(
child: SizedBox(
height: Constant.getActualY(context: context, y: 60),
width: Constant.getActualX(context: context, x: 200),
child: ElevatedButton(
onPressed: () {
if (selected_booth.value != null &&
selected_booth.value.id > 0 &&
selected_printer.value != null &&
selectedCapabilityProfile.value?.key !=
null &&
selected_branch.value != null &&
selected_branch.value.mBranchID != '0' &&
hostIpController.text.isNotEmpty &&
activeLayanan.value.isNotEmpty) {
saveData();
ref.read(allServiceProvider.notifier).state =
lyn.value;
Navigator.of(context).pushNamed(queueRoute);
} else {
if (selected_booth.value == null ||
selected_printer.value == null ||
selectedCapabilityProfile.value == null ||
hostIpController.text.isEmpty) {
ErrorDialog(
context,
'Input bertanda * tidak boleh kosong',
'PERINGATAN');
} else if (activeLayanan.value.isEmpty) {
ErrorDialog(
context,
'Layanan belum ada yang aktif',
'PERINGATAN');
}
}
},
style: ElevatedButton.styleFrom(
elevation: 5, backgroundColor: Colors.blue),
child: Text(
'Save',
style: Constant.subTitle(context: context)
.copyWith(color: Colors.white),
),
)),
)
],
),
),
),
),
),
),
));
}
}