You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
119 lines
3.6 KiB
Dart
119 lines
3.6 KiB
Dart
|
1 year ago
|
import 'dart:io';
|
||
|
|
|
||
|
|
import 'package:flutter/material.dart';
|
||
|
1 year ago
|
import 'package:provider/provider.dart';
|
||
|
1 year ago
|
import 'package:qr_code_scanner/qr_code_scanner.dart';
|
||
|
|
import 'package:test_sa/extensions/context_extension.dart';
|
||
|
|
import 'package:test_sa/extensions/int_extensions.dart';
|
||
|
|
import 'package:test_sa/extensions/text_extensions.dart';
|
||
|
|
|
||
|
1 year ago
|
import '../../../controllers/providers/api/devices_provider.dart';
|
||
|
|
import '../../../models/device/asset_search.dart';
|
||
|
1 year ago
|
import '../../../new_views/common_widgets/app_filled_button.dart';
|
||
|
|
import '../../../new_views/common_widgets/custom_app_bar.dart';
|
||
|
1 year ago
|
import '../../pages/device_transfer/search_asset_page.dart';
|
||
|
1 year ago
|
|
||
|
1 year ago
|
class AssetScanQr extends StatefulWidget {
|
||
|
|
static const String id = "/asset-scan-qr";
|
||
|
|
|
||
|
|
const AssetScanQr({Key key, this.title}) : super(key: key);
|
||
|
1 year ago
|
final String title;
|
||
|
|
|
||
|
|
@override
|
||
|
1 year ago
|
_AssetScanQrState createState() => _AssetScanQrState();
|
||
|
1 year ago
|
}
|
||
|
|
|
||
|
1 year ago
|
class _AssetScanQrState extends State<AssetScanQr> {
|
||
|
1 year ago
|
Barcode result;
|
||
|
|
QRViewController _controller;
|
||
|
|
bool _scanDone = false;
|
||
|
|
final GlobalKey qrKey = GlobalKey(debugLabel: 'QR_scanner');
|
||
|
1 year ago
|
AssetProvider _devicesProvider;
|
||
|
1 year ago
|
|
||
|
|
// In order to get hot reload to work we need to pause the camera if the platform
|
||
|
|
// is android, or resume the camera if the platform is iOS.
|
||
|
|
@override
|
||
|
|
void reassemble() {
|
||
|
|
super.reassemble();
|
||
|
|
if (Platform.isAndroid) {
|
||
|
|
_controller?.pauseCamera();
|
||
|
|
} else if (Platform.isIOS) {
|
||
|
|
_controller?.resumeCamera();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
@override
|
||
|
|
void dispose() {
|
||
|
|
super.dispose();
|
||
|
|
_controller?.dispose();
|
||
|
|
}
|
||
|
|
|
||
|
|
_pickManually() async {
|
||
|
1 year ago
|
await Navigator.push(context, MaterialPageRoute(builder: (context) => const SearchAssetPage()));
|
||
|
|
}
|
||
|
1 year ago
|
|
||
|
1 year ago
|
_getDevice(String result, {bool isQr = false}) async {
|
||
|
|
if (result == null) return;
|
||
|
|
_devicesProvider.reset();
|
||
|
|
await _devicesProvider.getAssets(
|
||
|
|
search: AssetSearch(assetNo: result, assetSerialNumber: ""),
|
||
|
|
isQr: isQr,
|
||
|
|
);
|
||
|
|
return _devicesProvider.devices;
|
||
|
1 year ago
|
}
|
||
|
|
|
||
|
|
@override
|
||
|
|
Widget build(BuildContext context) {
|
||
|
1 year ago
|
_devicesProvider = Provider.of<AssetProvider>(context);
|
||
|
1 year ago
|
return Scaffold(
|
||
|
|
body: SafeArea(
|
||
|
|
child: Stack(
|
||
|
|
children: [
|
||
|
|
QRView(
|
||
|
|
key: qrKey,
|
||
|
|
onQRViewCreated: (QRViewController controller) {
|
||
|
|
setState(() {
|
||
|
|
_controller = controller;
|
||
|
|
});
|
||
|
1 year ago
|
controller.scannedDataStream.listen((scanData) async {
|
||
|
1 year ago
|
if (!_scanDone) {
|
||
|
|
_scanDone = true;
|
||
|
1 year ago
|
final result = await _getDevice(scanData.code, isQr: true);
|
||
|
|
Navigator.of(context).pop(result[0]);
|
||
|
1 year ago
|
}
|
||
|
|
});
|
||
|
|
},
|
||
|
|
),
|
||
|
|
Center(
|
||
|
|
child: 'scan'.toSvgAsset(
|
||
|
|
height: 283.toScreenHeight.toInt(),
|
||
|
|
width: 283.toScreenWidth.toInt(),
|
||
|
|
fit: BoxFit.fitHeight,
|
||
|
|
),
|
||
|
|
),
|
||
|
|
SizedBox(
|
||
|
|
height: 60.toScreenHeight,
|
||
|
|
child: CustomAppBar(
|
||
|
1 year ago
|
title: widget.title,
|
||
|
1 year ago
|
)),
|
||
|
|
],
|
||
|
|
),
|
||
|
|
),
|
||
|
|
bottomSheet: Container(
|
||
|
|
height: 82.toScreenHeight,
|
||
|
|
color: Colors.white,
|
||
|
|
width: MediaQuery.of(context).size.width,
|
||
|
|
child: Center(
|
||
|
|
child: SizedBox(
|
||
|
|
height: 50.toScreenHeight,
|
||
|
|
width: 358.toScreenWidth,
|
||
|
|
child: AppFilledButton(
|
||
|
|
label: context.translation.pickManually,
|
||
|
|
onPressed: _pickManually,
|
||
|
|
),
|
||
|
|
),
|
||
|
|
),
|
||
|
|
));
|
||
|
|
}
|
||
|
|
}
|