-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* parallelization and execution time tracking in debug mode * fixed bug with new version of encrypt library * removed caching of DB * closing database after a transaction * profiles storing * profiles did connections storing * hotfix bug with sembast [2] codec signature error * Removed the possibility of exposing sensitive data if stacktrace is enabled * Moved stacktrace and error to dedicated class * fix errorHandling dependency injection, get the method sync instead of async
- Loading branch information
Showing
56 changed files
with
2,406 additions
and
1,119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
239 changes: 166 additions & 73 deletions
239
example/lib/src/presentation/ui/qrcode_scanner/widgets/qrcode_scanner.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,99 +1,192 @@ | ||
import 'package:camera/camera.dart'; | ||
import 'dart:developer'; | ||
import 'dart:io'; | ||
|
||
import 'package:flutter/foundation.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:google_mlkit_barcode_scanning/google_mlkit_barcode_scanning.dart'; | ||
import 'package:polygonid_flutter_sdk_example/src/presentation/ui/qrcode_scanner/widgets/barcode_detector_painter.dart'; | ||
import 'package:polygonid_flutter_sdk_example/src/presentation/ui/qrcode_scanner/widgets/camera_view.dart'; | ||
import 'package:polygonid_flutter_sdk_example/src/presentation/ui/qrcode_scanner/widgets/qrcode_scanner_overlay_shape.dart'; | ||
import 'package:polygonid_flutter_sdk_example/utils/custom_button_style.dart'; | ||
import 'package:polygonid_flutter_sdk_example/utils/custom_colors.dart'; | ||
import 'package:qr_code_scanner/qr_code_scanner.dart'; | ||
|
||
void main() => runApp(const MaterialApp(home: MyHome())); | ||
|
||
class QRCodeScannerPage extends StatefulWidget { | ||
const QRCodeScannerPage({Key? key}) : super(key: key); | ||
class MyHome extends StatelessWidget { | ||
const MyHome({Key? key}) : super(key: key); | ||
|
||
@override | ||
State<QRCodeScannerPage> createState() => _QRCodeScannerPageState(); | ||
Widget build(BuildContext context) { | ||
return Scaffold( | ||
appBar: AppBar(title: const Text('Flutter Demo Home Page')), | ||
body: Center( | ||
child: ElevatedButton( | ||
onPressed: () { | ||
Navigator.of(context).push(MaterialPageRoute( | ||
builder: (context) => const QRViewExample(), | ||
)); | ||
}, | ||
child: const Text('qrView'), | ||
), | ||
), | ||
); | ||
} | ||
} | ||
|
||
class _QRCodeScannerPageState extends State<QRCodeScannerPage> { | ||
final BarcodeScanner _barcodeScanner = | ||
BarcodeScanner(formats: [BarcodeFormat.qrCode]); | ||
class QRViewExample extends StatefulWidget { | ||
const QRViewExample({Key? key}) : super(key: key); | ||
|
||
bool _canProcess = true; | ||
bool _isBusy = false; | ||
bool _resultFound = false; | ||
CustomPaint? _customPaint; | ||
@override | ||
State<StatefulWidget> createState() => _QRViewExampleState(); | ||
} | ||
|
||
class _QRViewExampleState extends State<QRViewExample> { | ||
Barcode? result; | ||
QRViewController? controller; | ||
final GlobalKey qrKey = GlobalKey(debugLabel: 'QR'); | ||
|
||
// 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 dispose() { | ||
_barcodeScanner.close(); | ||
super.dispose(); | ||
void reassemble() { | ||
super.reassemble(); | ||
if (Platform.isAndroid) { | ||
controller!.pauseCamera(); | ||
} | ||
controller!.resumeCamera(); | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Scaffold( | ||
body: _buildBody(), | ||
body: Column( | ||
children: <Widget>[ | ||
Expanded(flex: 4, child: _buildQrView(context)), | ||
Expanded( | ||
flex: 1, | ||
child: FittedBox( | ||
fit: BoxFit.contain, | ||
child: Column( | ||
mainAxisAlignment: MainAxisAlignment.spaceEvenly, | ||
children: <Widget>[ | ||
if (result != null) | ||
Text( | ||
'Barcode Type: ${describeEnum(result!.format)} Data: ${result!.code}') | ||
else | ||
const Text('Scan a code'), | ||
Row( | ||
mainAxisAlignment: MainAxisAlignment.center, | ||
crossAxisAlignment: CrossAxisAlignment.center, | ||
children: <Widget>[ | ||
Container( | ||
margin: const EdgeInsets.all(8), | ||
child: ElevatedButton( | ||
onPressed: () async { | ||
await controller?.toggleFlash(); | ||
setState(() {}); | ||
}, | ||
child: FutureBuilder( | ||
future: controller?.getFlashStatus(), | ||
builder: (context, snapshot) { | ||
return Text('Flash: ${snapshot.data}'); | ||
}, | ||
)), | ||
), | ||
Container( | ||
margin: const EdgeInsets.all(8), | ||
child: ElevatedButton( | ||
onPressed: () async { | ||
await controller?.flipCamera(); | ||
setState(() {}); | ||
}, | ||
child: FutureBuilder( | ||
future: controller?.getCameraInfo(), | ||
builder: (context, snapshot) { | ||
if (snapshot.data != null) { | ||
return Text( | ||
'Camera facing ${describeEnum(snapshot.data!)}'); | ||
} else { | ||
return const Text('loading'); | ||
} | ||
}, | ||
)), | ||
) | ||
], | ||
), | ||
Row( | ||
mainAxisAlignment: MainAxisAlignment.center, | ||
crossAxisAlignment: CrossAxisAlignment.center, | ||
children: <Widget>[ | ||
Container( | ||
margin: const EdgeInsets.all(8), | ||
child: ElevatedButton( | ||
onPressed: () async { | ||
await controller?.pauseCamera(); | ||
}, | ||
child: const Text('pause', | ||
style: TextStyle(fontSize: 20)), | ||
), | ||
), | ||
Container( | ||
margin: const EdgeInsets.all(8), | ||
child: ElevatedButton( | ||
onPressed: () async { | ||
await controller?.resumeCamera(); | ||
}, | ||
child: const Text('resume', | ||
style: TextStyle(fontSize: 20)), | ||
), | ||
) | ||
], | ||
), | ||
], | ||
), | ||
), | ||
) | ||
], | ||
), | ||
); | ||
} | ||
|
||
/// | ||
Widget _buildBody() { | ||
return FutureBuilder( | ||
future: availableCameras(), | ||
builder: ( | ||
context, | ||
AsyncSnapshot<List<CameraDescription>> snapshot, | ||
) { | ||
if (snapshot.hasData) { | ||
snapshot.data; | ||
return CameraView( | ||
cameras: snapshot.data!, | ||
onImage: (inputImage) { | ||
processImage(inputImage); | ||
}, | ||
onQrCodeScanned: (code) { | ||
_resultCallback(code); | ||
}, | ||
); | ||
} else { | ||
return const Center( | ||
child: CircularProgressIndicator(), | ||
); | ||
} | ||
}, | ||
Widget _buildQrView(BuildContext context) { | ||
// For this example we check how width or tall the device is and change the scanArea and overlay accordingly. | ||
var scanArea = (MediaQuery.of(context).size.width < 400 || | ||
MediaQuery.of(context).size.height < 400) | ||
? 150.0 | ||
: 300.0; | ||
// To ensure the Scanner view is properly sizes after rotation | ||
// we need to listen for Flutter SizeChanged notification and update controller | ||
return QRView( | ||
key: qrKey, | ||
onQRViewCreated: _onQRViewCreated, | ||
overlay: QrScannerOverlayShape( | ||
borderColor: Colors.red, | ||
borderRadius: 10, | ||
borderLength: 30, | ||
borderWidth: 10, | ||
cutOutSize: scanArea), | ||
onPermissionSet: (ctrl, p) => _onPermissionSet(context, ctrl, p), | ||
); | ||
} | ||
|
||
/// | ||
void _resultCallback(String? rawValue) { | ||
_resultFound = true; | ||
_barcodeScanner.close(); | ||
Navigator.pop(context, rawValue); | ||
void _onQRViewCreated(QRViewController controller) { | ||
setState(() { | ||
this.controller = controller; | ||
}); | ||
controller.scannedDataStream.listen((scanData) { | ||
setState(() { | ||
result = scanData; | ||
}); | ||
}); | ||
} | ||
|
||
/// | ||
Future<void> processImage(InputImage inputImage) async { | ||
if (!_canProcess) return; | ||
if (_isBusy) return; | ||
_isBusy = true; | ||
|
||
final barcodes = await _barcodeScanner.processImage(inputImage); | ||
|
||
if (barcodes.isEmpty) { | ||
_isBusy = false; | ||
return; | ||
} | ||
|
||
// To avoid multiple scans of the same barcode | ||
if (_resultFound) { | ||
return; | ||
} | ||
|
||
_isBusy = false; | ||
if (mounted) { | ||
setState(() {}); | ||
void _onPermissionSet(BuildContext context, QRViewController ctrl, bool p) { | ||
log('${DateTime.now().toIso8601String()}_onPermissionSet $p'); | ||
if (!p) { | ||
ScaffoldMessenger.of(context).showSnackBar( | ||
const SnackBar(content: Text('no Permission')), | ||
); | ||
} | ||
} | ||
|
||
_resultCallback(barcodes.first.rawValue); | ||
@override | ||
void dispose() { | ||
controller?.dispose(); | ||
super.dispose(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.