part of 'dialog.dart'; class PrinterBluetoothDialog extends StatefulWidget { final Function(String) onSelected; const PrinterBluetoothDialog({super.key, required this.onSelected}); @override State createState() => _PrinterBluetoothDialogState(); } class _PrinterBluetoothDialogState extends State { @override void initState() { loadPermissionBluetooth(); context.read().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( 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) => GestureDetector( onTap: () { context.read().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), ), ), 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(), ); }, ), ); } }