В пользовательском интерфейсе есть кнопка, которая запускает открытие камеры в зависимости от состояния
затем при открытии qr-сканера появляется небольшой всплывающий экран камеры, который отсканируйте qr-код, который позволяет пользователю войти.
код можно продемонстрировать следующим образом:
Код: Выделить всё
class _QRClockUIState extends State {
@override
Widget build(BuildContext context) {
return Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
ElevatedButton.icon(
icon: Icon(widget.clockedIn ? Icons.stop : Icons.play_arrow,
size: 30),
label: Text(
widget.clockedIn ? 'STOP SHIFT' : 'START SHIFT',
style: TextStyle(
fontSize: 24,
fontWeight: FontWeight.bold,
),
),
onPressed: () {
if (widget.clockedIn) {
widget.handleShift(Map());
} else {
_showQRScanner();
}
},
),
],
),
);
}
void _showQRScanner() {
showDialog(
context: context,
builder: (BuildContext context) {
double dialogWidth = MediaQuery.of(context).size.width * 0.6;
double dialogHeight = MediaQuery.of(context).size.height * 0.5;
return Dialog(
child: Container(
width: dialogWidth,
height: dialogHeight,
child: MobileScanner(
fit: BoxFit.none,
onDetect: (barcodes) {
if (barcodes.barcodes[0].rawValue != null) {
print('QR Code: ${barcodes.barcodes[0].rawValue}');
// Parse the JSON from the rawValue
Map data =
jsonDecode(barcodes.barcodes[0].rawValue ?? '{}');
print('data: $data');
widget.handleShift(data);
Navigator.pop(context);
}
},
),
),
);
},
);
}
}
Подробнее здесь: https://stackoverflow.com/questions/793 ... -ios-issue
Мобильная версия