Skip to content

Commit

Permalink
applied logics for Approve and Decline buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
Ishad-M-I-M committed Nov 12, 2022
1 parent ac4ba0d commit b4ca7b5
Show file tree
Hide file tree
Showing 7 changed files with 108 additions and 57 deletions.
Binary file added assets/images/contract-agreement.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions lib/bloc/verify/verify_bloc.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import 'dart:async';

import 'package:bloc/bloc.dart';
import 'package:meta/meta.dart';

part 'verify_event.dart';
part 'verify_state.dart';

class VerifyBloc extends Bloc<VerifyEvent, VerifyState> {
VerifyBloc() : super(VerifyInitial()) {
on<VerifyEvent>((event, emit) {
// TODO: implement event handler
});
}
}
4 changes: 4 additions & 0 deletions lib/bloc/verify/verify_event.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
part of 'verify_bloc.dart';

@immutable
abstract class VerifyEvent {}
6 changes: 6 additions & 0 deletions lib/bloc/verify/verify_state.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
part of 'verify_bloc.dart';

@immutable
abstract class VerifyState {}

class VerifyInitial extends VerifyState {}
135 changes: 80 additions & 55 deletions lib/pages/qr_result_page.dart
Original file line number Diff line number Diff line change
@@ -1,81 +1,106 @@
import 'dart:convert';

import 'package:flutter/material.dart';
import 'package:iblock/services/secure_storage_service.dart';
import 'package:iblock/services/user_contract_service.dart';
import 'package:qr_code_scanner/qr_code_scanner.dart';

import './error_page.dart';
import '../widgets/forms/button.dart';

class QRResultPage extends StatelessWidget {
class QRResultPage extends StatefulWidget {
final Barcode result;
const QRResultPage(this.result, {Key? key}) : super(key: key);

@override
State<QRResultPage> createState() => _QRResultPageState();
}

class _QRResultPageState extends State<QRResultPage> {
Map<String, dynamic> processQR(Barcode qr) {
Map<String, dynamic> data = jsonDecode(qr.code!);
return data;
}

@override
Widget build(BuildContext context) {
try{
print((jsonDecode(result.code!) as Map<String, dynamic>)['information']
as List);
try {
return SafeArea(
child: Scaffold(
appBar: AppBar(
title: const Text('Requesting Information'),
),
body:
SizedBox(
body: SizedBox(
width: double.infinity,
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Expanded(
flex: MediaQuery.of(context).size.width > MediaQuery.of(context).size.height? 1:4,
child: SingleChildScrollView(
child: Column(
children: ((jsonDecode(result.code!)
as Map<String, dynamic>)['information']
as List<dynamic>)
.map((e) => Padding(
padding: const EdgeInsets.all(4.0),
child: Text(
e,
style: const TextStyle(fontSize: 14),
child: Column(crossAxisAlignment: CrossAxisAlignment.center,
children: [
Expanded(
flex: MediaQuery.of(context).size.width >
MediaQuery.of(context).size.height
? 1
: 4,
child: Padding(
padding: const EdgeInsets.all(8.0),
child: SingleChildScrollView(
child: SizedBox(
height: MediaQuery.of(context).size.height * 0.6,
child: Column(
mainAxisSize: MainAxisSize.max,
children: [
const Expanded(
flex: 1,
child: Text(
"Following service provider request your approval for access your personal information")),
Expanded(
flex: 1,
child: Text(
processQR(widget.result)["verifier-name"],
style: const TextStyle(
fontWeight: FontWeight.bold,
fontSize: 20),
),
),
const Expanded(
flex: 3,
child: SizedBox(
width: 300,
child: Image(
image: AssetImage(
'assets/images/contract-agreement.png')),
),
),
],
),
))
.toList(),
),
),
)),
Expanded(
flex: 1,
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Padding(
padding: const EdgeInsets.all(2.0),
child: Button(
"Approve",
onPressed: () {},
)),
Padding(
padding: const EdgeInsets.all(2.0),
child: Button(
"Decline",
onPressed: () {},
color: Colors.red,
)),
],
),
)
],
),
)
// Center(
// child: Text(result.code != null ? 'Barcode Type: ${describeEnum(result.format)} Data: ${result.code}': 'No result'),
// ),
),
Expanded(flex: 1,
child: Column(crossAxisAlignment: CrossAxisAlignment.center,
children: [
Padding(padding: const EdgeInsets.all(2.0),
child: Button("Approve", onPressed: () async{
var data = processQR(widget.result);
var contractService = UserContractService();
var contractAddress = await SecureStorageService.get("contract-address") as String;
var privateKey = await SecureStorageService.get("private-key") as String;
await contractService.verify(data['verifier-contract'], data['token'], contractAddress: contractAddress, privateKey: privateKey);
},)),
Padding(padding: const EdgeInsets.all(2.0),
child: Button("Decline", onPressed: () {
Navigator.popUntil(
context, ModalRoute.withName("/home"));
}, color: Colors.red,)),
],),)
],),)
// Center(
// child: Text(result.code != null ? 'Barcode Type: ${describeEnum(result.format)} Data: ${result.code}': 'No result'),
// ),
),);
} catch(e){
print(e);
return const ErrorPage(
message: "QR code not recognized!",
);
}
catch(e){
return const ErrorPage(message: "QR code not recognized!",);
}

}
}
4 changes: 2 additions & 2 deletions lib/widgets/qr_scanner.dart
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ class _QRScannerState extends State<QRScanner> {
setState(() {
result = scanData;
});
controller.pauseCamera();
Navigator.pushNamed(context, '/qrcode-result', arguments: scanData);
controller.pauseCamera()
.then((value) => Navigator.pushNamed(context, '/qrcode-result', arguments: scanData));
});
}

Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ flutter:
- assets/images/welcome2.png
- assets/images/welcome3.png
- assets/images/error.png
- assets/images/contract-agreement.png
# - images/a_dot_ham.jpeg

# An image asset can refer to one or more resolution-specific "variants", see
Expand Down

0 comments on commit b4ca7b5

Please sign in to comment.