mirror of
https://github.com/Yubico/yubioath-flutter.git
synced 2024-11-25 23:14:18 +03:00
semi transparent background
This commit is contained in:
parent
31b308e6be
commit
db62e124ef
@ -4,45 +4,71 @@ import 'package:mobile_scanner/mobile_scanner.dart';
|
||||
import '../../app/navigation_service.dart';
|
||||
import '../../oath/models.dart';
|
||||
|
||||
class MobileScannerWrapper extends StatefulWidget {
|
||||
class OverlayClipper extends CustomClipper<Path> {
|
||||
@override
|
||||
Path getClip(Size size) {
|
||||
const r = 40.0;
|
||||
var w = size.width - 40;
|
||||
return Path()
|
||||
..addRect(Rect.fromLTWH(0, 0, size.width, size.height))
|
||||
..addRRect(RRect.fromRectXY(
|
||||
Rect.fromPoints(
|
||||
const Offset(32, 32), Offset(size.width - 32, 32 + w)),
|
||||
r,
|
||||
r))
|
||||
..fillType = PathFillType.evenOdd;
|
||||
}
|
||||
|
||||
@override
|
||||
bool shouldReclip(covariant CustomClipper<Path> oldClipper) => true;
|
||||
}
|
||||
|
||||
class MobileScannerWrapper extends StatelessWidget {
|
||||
final MobileScannerController controller;
|
||||
final Function(Barcode barcode, MobileScannerArguments? args)? onDetect;
|
||||
final double dimension;
|
||||
final Color frameColor;
|
||||
|
||||
const MobileScannerWrapper({
|
||||
Key? key,
|
||||
required this.controller,
|
||||
required this.dimension,
|
||||
required this.frameColor,
|
||||
this.onDetect,
|
||||
required this.onDetect,
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<StatefulWidget> createState() => _MobileScannerWrapperState();
|
||||
}
|
||||
|
||||
class _MobileScannerWrapperState extends State<MobileScannerWrapper> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
const radius = 40.0;
|
||||
var dimension = MediaQuery.of(context).size.width - 64;
|
||||
return Stack(children: [
|
||||
ClipRRect(
|
||||
borderRadius: BorderRadius.circular(radius),
|
||||
child: SizedBox.square(
|
||||
dimension: widget.dimension,
|
||||
child: MobileScanner(
|
||||
controller: widget.controller,
|
||||
onDetect: (barcode, args) {
|
||||
widget.onDetect?.call(barcode, args);
|
||||
}))),
|
||||
DecoratedBox(
|
||||
child: SizedBox(
|
||||
width: widget.dimension,
|
||||
height: widget.dimension,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
border: Border.all(color: widget.frameColor, width: 5),
|
||||
borderRadius: const BorderRadius.all(Radius.circular(radius))))
|
||||
MobileScanner(
|
||||
controller: controller,
|
||||
onDetect: (barcode, args) {
|
||||
onDetect?.call(barcode, args);
|
||||
}),
|
||||
ClipPath(
|
||||
clipper: OverlayClipper(),
|
||||
child: Opacity(
|
||||
opacity: 0.5,
|
||||
child: ColoredBox(
|
||||
color: Colors.white,
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: const [Spacer()],
|
||||
)))),
|
||||
Positioned.fromRect(
|
||||
rect: Rect.fromPoints(
|
||||
const Offset(32, 32), Offset(dimension + 32, 60 + dimension)),
|
||||
child: DecoratedBox(
|
||||
child: SizedBox(
|
||||
width: dimension,
|
||||
height: dimension,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
border: Border.all(color: frameColor, width: 5),
|
||||
borderRadius:
|
||||
const BorderRadius.all(Radius.circular(radius)))))
|
||||
]);
|
||||
}
|
||||
}
|
||||
@ -100,160 +126,155 @@ class _QrScannerViewState extends State<QrScannerView> {
|
||||
},
|
||||
),
|
||||
),
|
||||
body: Padding(
|
||||
padding: const EdgeInsets.all(32),
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
MobileScannerWrapper(
|
||||
controller: _controller,
|
||||
dimension: MediaQuery.of(context).size.width - 64,
|
||||
frameColor: _frameColor,
|
||||
onDetect: (barcode, _) =>
|
||||
handleResult(barcode.rawValue),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(
|
||||
height: 32,
|
||||
),
|
||||
if (_credentialData == null && _scanningError == null)
|
||||
Card(
|
||||
elevation: 10,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
// mainAxisAlignment: MainAxisAlignment.start,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
Text('Scan QR code',
|
||||
style: Theme.of(context)
|
||||
.textTheme
|
||||
.headline5),
|
||||
const SizedBox(height: 16),
|
||||
Text('or',
|
||||
style: Theme.of(context)
|
||||
.textTheme
|
||||
.bodyLarge),
|
||||
const SizedBox(height: 16),
|
||||
Row(
|
||||
mainAxisAlignment:
|
||||
MainAxisAlignment.spaceEvenly,
|
||||
children: [
|
||||
OutlinedButton(
|
||||
onPressed: () {
|
||||
Navigator.of(dialogContext).pop('');
|
||||
},
|
||||
child: const Text('Add manually'),
|
||||
),
|
||||
],
|
||||
)
|
||||
],
|
||||
))),
|
||||
if (_credentialData != null)
|
||||
Card(
|
||||
elevation: 10,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text('Successfully scanned',
|
||||
style: Theme.of(context)
|
||||
.textTheme
|
||||
.headline5),
|
||||
const SizedBox(
|
||||
height: 16,
|
||||
),
|
||||
Text('Name',
|
||||
style: Theme.of(context)
|
||||
.textTheme
|
||||
.bodySmall),
|
||||
Text(_credentialData?.name ?? '',
|
||||
style: Theme.of(context)
|
||||
.textTheme
|
||||
.headline6),
|
||||
if (_credentialData?.issuer != null)
|
||||
Column(
|
||||
crossAxisAlignment:
|
||||
CrossAxisAlignment.start,
|
||||
body: Stack(children: [
|
||||
MobileScannerWrapper(
|
||||
controller: _controller,
|
||||
frameColor: _frameColor,
|
||||
onDetect: (barcode, _) => handleResult(barcode.rawValue),
|
||||
),
|
||||
Padding(
|
||||
padding:
|
||||
const EdgeInsets.symmetric(vertical: 32, horizontal: 32),
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
const SizedBox(
|
||||
height: 32,
|
||||
),
|
||||
if (_credentialData == null && _scanningError == null)
|
||||
Card(
|
||||
elevation: 10,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
// mainAxisAlignment: MainAxisAlignment.start,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
Text('Scan QR code',
|
||||
style: Theme.of(context)
|
||||
.textTheme
|
||||
.headline5),
|
||||
const SizedBox(height: 16),
|
||||
Text('or',
|
||||
style: Theme.of(context)
|
||||
.textTheme
|
||||
.bodyLarge),
|
||||
const SizedBox(height: 16),
|
||||
Row(
|
||||
mainAxisAlignment:
|
||||
MainAxisAlignment.spaceEvenly,
|
||||
children: [
|
||||
const SizedBox(
|
||||
height: 16,
|
||||
),
|
||||
Text('Issuer',
|
||||
style: Theme.of(context)
|
||||
.textTheme
|
||||
.bodySmall),
|
||||
Text(_credentialData?.issuer ?? '',
|
||||
style: Theme.of(context)
|
||||
.textTheme
|
||||
.headline6),
|
||||
const SizedBox(
|
||||
height: 32,
|
||||
OutlinedButton(
|
||||
onPressed: () {
|
||||
Navigator.of(dialogContext).pop('');
|
||||
},
|
||||
child: const Text('Add manually'),
|
||||
),
|
||||
],
|
||||
)
|
||||
],
|
||||
))),
|
||||
if (_credentialData != null)
|
||||
Card(
|
||||
elevation: 10,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text('Successfully scanned',
|
||||
style: Theme.of(context)
|
||||
.textTheme
|
||||
.headline5),
|
||||
const SizedBox(
|
||||
height: 16,
|
||||
),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
children: [
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
if (Navigator.of(dialogContext)
|
||||
.canPop()) {
|
||||
// prevent several callbacks
|
||||
Navigator.of(dialogContext)
|
||||
.pop(_scannedString);
|
||||
}
|
||||
},
|
||||
child: const Text('Add this'),
|
||||
)
|
||||
],
|
||||
)
|
||||
],
|
||||
))),
|
||||
if (_scanningError != null)
|
||||
Card(
|
||||
elevation: 10,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
Text('Scan failed, try again',
|
||||
style: Theme.of(context)
|
||||
.textTheme
|
||||
.headline5),
|
||||
const SizedBox(height: 16),
|
||||
Text('or',
|
||||
style: Theme.of(context)
|
||||
.textTheme
|
||||
.bodyLarge),
|
||||
const SizedBox(height: 16),
|
||||
Row(
|
||||
mainAxisAlignment:
|
||||
MainAxisAlignment.spaceEvenly,
|
||||
children: [
|
||||
OutlinedButton(
|
||||
onPressed: () {
|
||||
Navigator.of(dialogContext).pop('');
|
||||
},
|
||||
child: const Text('Add manually'),
|
||||
Text('Name',
|
||||
style: Theme.of(context)
|
||||
.textTheme
|
||||
.bodySmall),
|
||||
Text(_credentialData?.name ?? '',
|
||||
style: Theme.of(context)
|
||||
.textTheme
|
||||
.headline6),
|
||||
if (_credentialData?.issuer != null)
|
||||
Column(
|
||||
crossAxisAlignment:
|
||||
CrossAxisAlignment.start,
|
||||
children: [
|
||||
const SizedBox(
|
||||
height: 16,
|
||||
),
|
||||
Text('Issuer',
|
||||
style: Theme.of(context)
|
||||
.textTheme
|
||||
.bodySmall),
|
||||
Text(_credentialData?.issuer ?? '',
|
||||
style: Theme.of(context)
|
||||
.textTheme
|
||||
.headline6),
|
||||
const SizedBox(
|
||||
height: 32,
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
)
|
||||
],
|
||||
))),
|
||||
],
|
||||
))));
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
children: [
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
if (Navigator.of(dialogContext)
|
||||
.canPop()) {
|
||||
// prevent several callbacks
|
||||
Navigator.of(dialogContext)
|
||||
.pop(_scannedString);
|
||||
}
|
||||
},
|
||||
child: const Text('Add this'),
|
||||
)
|
||||
],
|
||||
)
|
||||
],
|
||||
))),
|
||||
if (_scanningError != null)
|
||||
Card(
|
||||
elevation: 10,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
Text('Scan failed, try again',
|
||||
style: Theme.of(context)
|
||||
.textTheme
|
||||
.headline5),
|
||||
const SizedBox(height: 16),
|
||||
Text('or',
|
||||
style: Theme.of(context)
|
||||
.textTheme
|
||||
.bodyLarge),
|
||||
const SizedBox(height: 16),
|
||||
Row(
|
||||
mainAxisAlignment:
|
||||
MainAxisAlignment.spaceEvenly,
|
||||
children: [
|
||||
OutlinedButton(
|
||||
onPressed: () {
|
||||
Navigator.of(dialogContext).pop('');
|
||||
},
|
||||
child: const Text('Add manually'),
|
||||
),
|
||||
],
|
||||
)
|
||||
],
|
||||
))),
|
||||
],
|
||||
)),
|
||||
])));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user