Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SDK improvements #332

Merged
merged 15 commits into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions example/integration_test/app_real_data_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ void main() {
await widgetTester
.tap(find.byKey(CustomWidgetsKeys.authScreenButtonConnect));
await widgetTester.pumpAndSettle();

key.currentState?.pop(iden3Message);
await widgetTester.pumpAndSettle();

Expand Down
2 changes: 1 addition & 1 deletion example/ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@
97C146E61CF9000F007C117D /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 1300;
LastUpgradeCheck = 1430;
ORGANIZATIONNAME = "";
TargetAttributes = {
97C146ED1CF9000F007C117D = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1300"
LastUpgradeVersion = "1430"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
2 changes: 1 addition & 1 deletion example/lib/src/presentation/navigations/routes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class Routes {

///
static WidgetBuilder _qrCodeScannerRoute() {
return (BuildContext context) => const QRCodeScannerPage();
return (BuildContext context) => const QRViewExample();
}

///
Expand Down
1 change: 1 addition & 0 deletions example/lib/src/presentation/ui/home/home_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class HomeBloc extends Bloc<HomeEvent, HomeState> {
try {
PrivateIdentityEntity identity =
await _polygonIdSdk.identity.addIdentity();
print("identity: ${identity.privateKey}");
await SecureStorage.write(
key: SecureStorageKeys.privateKey, value: identity.privateKey);
emit(HomeState.loaded(identifier: identity.did));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/*
import 'dart:math';
import 'dart:ui';
import 'dart:ui' as ui;
Expand Down Expand Up @@ -96,3 +97,4 @@ class BarcodeDetectorPainter extends CustomPainter {
oldDelegate.barcodes != barcodes;
}
}
*/
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/*
import 'dart:io';

import 'package:camera/camera.dart';
Expand Down Expand Up @@ -460,3 +461,4 @@ class _CameraViewState extends State<CameraView> {
});
}
}
*/
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/*
import 'dart:io';
import 'dart:ui';

Expand Down Expand Up @@ -34,3 +35,4 @@ double translateY(
return y * size.height / absoluteImageSize.height;
}
}
*/
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();
}
}
5 changes: 3 additions & 2 deletions example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ dependencies:
http: ^0.13.5
flutter_secure_storage: ^8.0.0
logger: ^2.0.1
google_mlkit_barcode_scanning: ^0.7.0
camera: ^0.10.3+2
#google_mlkit_barcode_scanning: ^0.7.0
#camera: ^0.10.3+2
qr_code_scanner: ^1.0.1
image_picker: ^1.0.0
envied: ^0.3.0+3
scan: ^1.6.0
Expand Down
9 changes: 7 additions & 2 deletions lib/common/domain/entities/env_entity.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class EnvEntity {
final String idStateContract;
final String pushUrl;
final String ipfsUrl;
final String? stacktraceEncryptionKey;

EnvEntity({
required this.blockchain,
Expand All @@ -17,6 +18,7 @@ class EnvEntity {
required this.idStateContract,
required this.pushUrl,
required this.ipfsUrl,
this.stacktraceEncryptionKey,
});

factory EnvEntity.fromJson(Map<String, dynamic> json) {
Expand All @@ -29,6 +31,7 @@ class EnvEntity {
idStateContract: json['idStateContract'],
pushUrl: json['pushUrl'],
ipfsUrl: json['ipfsUrl'],
stacktraceEncryptionKey: json['stacktraceEncryptionKey'],
);
}

Expand All @@ -42,11 +45,12 @@ class EnvEntity {
'idStateContract': idStateContract,
'pushUrl': pushUrl,
'ipfsUrl': ipfsUrl,
'stacktraceEncryptionKey': stacktraceEncryptionKey,
};

@override
String toString() =>
"[EnvEntity] {blockchain: $blockchain, network: $network, web3Url: $web3Url, web3RdpUrl: $web3RdpUrl, web3ApiKey: $web3ApiKey, idStateContract: $idStateContract, pushUrl: $pushUrl, ipfsUrl: $ipfsUrl}";
"[EnvEntity] {blockchain: $blockchain, network: $network, web3Url: $web3Url, web3RdpUrl: $web3RdpUrl, web3ApiKey: $web3ApiKey, idStateContract: $idStateContract, pushUrl: $pushUrl, ipfsUrl: $ipfsUrl, stacktraceEncryptionKey: $stacktraceEncryptionKey}";

@override
bool operator ==(Object other) =>
Expand All @@ -59,7 +63,8 @@ class EnvEntity {
web3ApiKey == other.web3ApiKey &&
idStateContract == other.idStateContract &&
pushUrl == other.pushUrl &&
ipfsUrl == other.ipfsUrl;
ipfsUrl == other.ipfsUrl &&
stacktraceEncryptionKey == other.stacktraceEncryptionKey;

@override
int get hashCode => runtimeType.hashCode;
Expand Down
Loading
Loading