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

fix: camera overlay rendering #1423

Merged
merged 1 commit into from
May 4, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,27 @@ import 'package:flutter_svg/flutter_svg.dart';

import '../../../gen/assets.gen.dart';

class QrScannerBackground extends StatelessWidget {
class QrScannerBackground extends StatefulWidget {
const QrScannerBackground({
super.key,
required this.child,
});

final Widget child;

@override
State<QrScannerBackground> createState() => _QrScannerBackgroundState();
}

class _QrScannerBackgroundState extends State<QrScannerBackground> {
late final Future<PictureInfo> _info;

@override
void initState() {
super.initState();
_info = _readFrame();
}

Future<PictureInfo> _readFrame() async {
final byteData = await rootBundle.load(Assets.images.qrFrame.path);

Expand All @@ -25,13 +38,10 @@ class QrScannerBackground extends StatelessWidget {

@override
Widget build(BuildContext context) => FutureBuilder<PictureInfo?>(
future: _readFrame(),
builder: (context, frame) => CustomPaint(
foregroundPainter: _Painter(
frame: frame.data,
dimension: 350,
),
child: child,
future: _info,
builder: (context, snapshot) => CustomPaint(
foregroundPainter: _Painter(frame: snapshot.data, dimension: 350),
child: widget.child,
),
);
}
Expand Down Expand Up @@ -91,5 +101,7 @@ class _Painter extends CustomPainter {
}

@override
bool shouldRepaint(covariant CustomPainter oldDelegate) => false;
bool shouldRepaint(covariant _Painter oldDelegate) =>
oldDelegate.dimension != dimension ||
oldDelegate.frame?.size != frame?.size;
}
Loading