apskel-pos-flutter-v2/lib/presentation/components/dialog/printer_bluetooth_dialog.dart
2025-11-04 14:58:51 +07:00

78 lines
2.5 KiB
Dart

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() {
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(
(item) => Container(
width: double.infinity,
padding: const EdgeInsets.symmetric(vertical: 12),
decoration: BoxDecoration(
border: Border(
bottom: BorderSide(color: AppColor.border, width: 1),
),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.start,
children: [
Text(
item.name,
style: AppStyle.lg.copyWith(
fontWeight: FontWeight.w600,
color: AppColor.primary,
),
),
SpaceHeight(4),
Text(
item.macAdress,
style: AppStyle.sm.copyWith(
color: AppColor.textSecondary,
),
),
],
),
),
)
.toList(),
);
},
),
);
}
}