apskel-pos-flutter-v2/lib/presentation/components/dialog/printer_bluetooth_dialog.dart

88 lines
3.0 KiB
Dart
Raw Normal View History

2025-11-04 14:58:51 +07:00
part of 'dialog.dart';
class PrinterBluetoothDialog extends StatefulWidget {
final Function(String) onSelected;
const PrinterBluetoothDialog({super.key, required this.onSelected});
@override
State<PrinterBluetoothDialog> createState() => _PrinterBluetoothDialogState();
}
class _PrinterBluetoothDialogState extends State<PrinterBluetoothDialog> {
@override
void initState() {
2025-11-04 22:13:15 +07:00
loadPermissionBluetooth();
2025-11-04 14:58:51 +07:00
context.read<BluetoothLoaderBloc>().add(BluetoothLoaderEvent.fetched());
super.initState();
}
@override
Widget build(BuildContext context) {
return CustomModalDialog(
title: 'Bluetooth',
contentPadding: EdgeInsets.all(16),
minHeight: context.deviceHeight * 0.6,
minWidth: context.deviceWidth * 0.4,
child: BlocBuilder<BluetoothLoaderBloc, BluetoothLoaderState>(
builder: (context, state) {
if (state.isFetching) {
return Center(child: LoaderWithText());
}
if (state.bluetoothDevices.isEmpty) {
return const Center(child: Text('No bluetooth printer found'));
}
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.start,
children: state.bluetoothDevices
.map(
2025-11-04 22:13:15 +07:00
(item) => GestureDetector(
onTap: () {
context.read<BluetoothConnectBloc>().add(
BluetoothConnectEvent.connect(item.macAdress),
);
widget.onSelected(item.macAdress);
context.router.maybePop();
},
child: Container(
width: double.infinity,
padding: const EdgeInsets.symmetric(vertical: 12),
decoration: BoxDecoration(
border: Border(
bottom: BorderSide(color: AppColor.border, width: 1),
),
2025-11-04 14:58:51 +07:00
),
2025-11-04 22:13:15 +07:00
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.start,
children: [
Text(
item.name,
style: AppStyle.lg.copyWith(
fontWeight: FontWeight.w600,
color: AppColor.primary,
),
2025-11-04 14:58:51 +07:00
),
2025-11-04 22:13:15 +07:00
SpaceHeight(4),
Text(
item.macAdress,
style: AppStyle.sm.copyWith(
color: AppColor.textSecondary,
),
2025-11-04 14:58:51 +07:00
),
2025-11-04 22:13:15 +07:00
],
),
2025-11-04 14:58:51 +07:00
),
),
)
.toList(),
);
},
),
);
}
}