From a845c9e6158b1dc2930fac3f71267f99e8cff7c4 Mon Sep 17 00:00:00 2001 From: Julian Steenbakker Date: Mon, 1 Nov 2021 12:08:47 +0100 Subject: [PATCH] imp: apply flutter_lints suggestions --- analysis_options.yaml | 2 +- example/analysis_options.yaml | 2 +- example/lib/main.dart | 30 +++++++++++++++++------------- lib/src/qr_code_scanner.dart | 6 +++--- lib/src/web/flutter_qr_web.dart | 15 +++++++++------ 5 files changed, 31 insertions(+), 24 deletions(-) diff --git a/analysis_options.yaml b/analysis_options.yaml index 12a44df..a3be6b8 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -1 +1 @@ -include: package:flutter_lints/flutter.dart \ No newline at end of file +include: package:flutter_lints/flutter.yaml \ No newline at end of file diff --git a/example/analysis_options.yaml b/example/analysis_options.yaml index 12a44df..a3be6b8 100644 --- a/example/analysis_options.yaml +++ b/example/analysis_options.yaml @@ -1 +1 @@ -include: package:flutter_lints/flutter.dart \ No newline at end of file +include: package:flutter_lints/flutter.yaml \ No newline at end of file diff --git a/example/lib/main.dart b/example/lib/main.dart index abf6ed0..477b8d3 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -5,7 +5,7 @@ import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:qr_code_scanner/qr_code_scanner.dart'; -void main() => runApp(MaterialApp(home: MyHome())); +void main() => runApp(const MaterialApp(home: MyHome())); class MyHome extends StatelessWidget { const MyHome({Key? key}) : super(key: key); @@ -13,15 +13,15 @@ class MyHome extends StatelessWidget { @override Widget build(BuildContext context) { return Scaffold( - appBar: AppBar(title: Text('Flutter Demo Home Page')), + appBar: AppBar(title: const Text('Flutter Demo Home Page')), body: Center( child: ElevatedButton( onPressed: () { Navigator.of(context).push(MaterialPageRoute( - builder: (context) => QRViewExample(), + builder: (context) => const QRViewExample(), )); }, - child: Text('qrView'), + child: const Text('qrView'), ), ), ); @@ -29,6 +29,8 @@ class MyHome extends StatelessWidget { } class QRViewExample extends StatefulWidget { + const QRViewExample({Key? key}) : super(key: key); + @override State createState() => _QRViewExampleState(); } @@ -66,13 +68,13 @@ class _QRViewExampleState extends State { Text( 'Barcode Type: ${describeEnum(result!.format)} Data: ${result!.code}') else - Text('Scan a code'), + const Text('Scan a code'), Row( mainAxisAlignment: MainAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center, children: [ Container( - margin: EdgeInsets.all(8), + margin: const EdgeInsets.all(8), child: ElevatedButton( onPressed: () async { await controller?.toggleFlash(); @@ -86,7 +88,7 @@ class _QRViewExampleState extends State { )), ), Container( - margin: EdgeInsets.all(8), + margin: const EdgeInsets.all(8), child: ElevatedButton( onPressed: () async { await controller?.flipCamera(); @@ -99,7 +101,7 @@ class _QRViewExampleState extends State { return Text( 'Camera facing ${describeEnum(snapshot.data!)}'); } else { - return Text('loading'); + return const Text('loading'); } }, )), @@ -111,21 +113,23 @@ class _QRViewExampleState extends State { crossAxisAlignment: CrossAxisAlignment.center, children: [ Container( - margin: EdgeInsets.all(8), + margin: const EdgeInsets.all(8), child: ElevatedButton( onPressed: () async { await controller?.pauseCamera(); }, - child: Text('pause', style: TextStyle(fontSize: 20)), + child: const Text('pause', + style: TextStyle(fontSize: 20)), ), ), Container( - margin: EdgeInsets.all(8), + margin: const EdgeInsets.all(8), child: ElevatedButton( onPressed: () async { await controller?.resumeCamera(); }, - child: Text('resume', style: TextStyle(fontSize: 20)), + child: const Text('resume', + style: TextStyle(fontSize: 20)), ), ) ], @@ -175,7 +179,7 @@ class _QRViewExampleState extends State { log('${DateTime.now().toIso8601String()}_onPermissionSet $p'); if (!p) { ScaffoldMessenger.of(context).showSnackBar( - SnackBar(content: Text('no Permission')), + const SnackBar(content: Text('no Permission')), ); } } diff --git a/lib/src/qr_code_scanner.dart b/lib/src/qr_code_scanner.dart index 238529c..776d83a 100644 --- a/lib/src/qr_code_scanner.dart +++ b/lib/src/qr_code_scanner.dart @@ -126,7 +126,7 @@ class _QRViewState extends State { onPlatformViewCreated: _onPlatformViewCreated, creationParams: _QrCameraSettings(cameraFacing: widget.cameraFacing).toMap(), - creationParamsCodec: StandardMessageCodec(), + creationParamsCodec: const StandardMessageCodec(), ); break; case TargetPlatform.iOS: @@ -135,7 +135,7 @@ class _QRViewState extends State { onPlatformViewCreated: _onPlatformViewCreated, creationParams: _QrCameraSettings(cameraFacing: widget.cameraFacing).toMap(), - creationParamsCodec: StandardMessageCodec(), + creationParamsCodec: const StandardMessageCodec(), ); break; default: @@ -327,7 +327,7 @@ class QRViewController { {QrScannerOverlayShape? overlay}) async { if (defaultTargetPlatform == TargetPlatform.iOS) { // Add small delay to ensure the render box is loaded - await Future.delayed(Duration(milliseconds: 300)); + await Future.delayed(const Duration(milliseconds: 300)); if (key.currentContext == null) return false; final renderBox = key.currentContext!.findRenderObject() as RenderBox; try { diff --git a/lib/src/web/flutter_qr_web.dart b/lib/src/web/flutter_qr_web.dart index f062248..1da3407 100644 --- a/lib/src/web/flutter_qr_web.dart +++ b/lib/src/web/flutter_qr_web.dart @@ -1,3 +1,5 @@ +// ignore_for_file: avoid_web_libraries_in_flutter + import 'dart:async'; import 'dart:core'; import 'dart:html' as html; @@ -59,11 +61,11 @@ class _WebQrViewState extends State { QRViewControllerWeb? _controller; - late Size _size = Size(0, 0); + late Size _size = const Size(0, 0); Timer? timer; String? code; String? _errorMsg; - var video; + html.VideoElement video = html.VideoElement(); String viewID = 'QRVIEW-' + DateTime.now().millisecondsSinceEpoch.toString(); final StreamController _scanUpdateController = @@ -78,13 +80,13 @@ class _WebQrViewState extends State { facing = widget.cameraFacing ?? CameraFacing.front; - video = html.VideoElement(); + // video = html.VideoElement(); WebQrView.vidDiv.children = [video]; // ignore: UNDEFINED_PREFIXED_NAME ui.platformViewRegistry .registerViewFactory(viewID, (int id) => WebQrView.vidDiv); // giving JavaScipt some time to process the DOM changes - Timer(Duration(milliseconds: 500), () { + Timer(const Duration(milliseconds: 500), () { start(); }); } @@ -92,7 +94,8 @@ class _WebQrViewState extends State { Future start() async { await _makeCall(); _frameIntervall?.cancel(); - _frameIntervall = Timer.periodic(Duration(milliseconds: 200), (timer) { + _frameIntervall = + Timer.periodic(const Duration(milliseconds: 200), (timer) { _captureFrame2(); }); } @@ -202,7 +205,7 @@ class _WebQrViewState extends State { return Center(child: Text(_errorMsg!)); } if (_localStream == null) { - return Center(child: CircularProgressIndicator()); + return const Center(child: CircularProgressIndicator()); } return LayoutBuilder( builder: (context, constraints) {