Skip to content

Commit

Permalink
Merge pull request #53 from Maruti54/main
Browse files Browse the repository at this point in the history
QR Code Scanner
  • Loading branch information
SiddhantPawar03 authored Jul 23, 2022
2 parents 9adc540 + 3125abe commit d6fe3fd
Show file tree
Hide file tree
Showing 8 changed files with 276 additions and 16 deletions.
4 changes: 2 additions & 2 deletions projects/ev_stations/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
compileSdkVersion flutter.compileSdkVersion
compileSdkVersion 32

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
Expand All @@ -44,7 +44,7 @@ android {
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.example.ev_stations"
minSdkVersion flutter.minSdkVersion
minSdkVersion 21
targetSdkVersion flutter.targetSdkVersion
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
Expand Down
1 change: 1 addition & 0 deletions projects/ev_stations/assets/lottie/torch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"v":"5.6.6","ip":0,"op":80,"fr":60,"w":28,"h":28,"layers":[{"ind":17588,"nm":"surface73409","ao":0,"ip":0,"op":80,"st":0,"ty":4,"ks":{"ty":"tr","o":{"k":100},"r":{"k":0},"p":{"a":0,"k":[0,0,0],"ix":2},"a":{"k":[0,0]},"s":{"k":[133.33,133.33]},"sk":{"k":0},"sa":{"k":0}},"shapes":[{"ty":"gr","hd":false,"nm":"surface73409","it":[{"ty":"gr","hd":false,"it":[{"ty":"sh","ks":{"k":{"i":[[0,0],[0,0],[0.11,0.06],[0.12,-0.03],[-0.05,-0.25],[0,0],[0,0],[-0.21,0],[0,0.25],[0.01,0.04]],"o":[[0,0],[-0.03,-0.12],[-0.1,-0.06],[-0.25,0.06],[0,0],[0,0],[0.04,0.21],[0.25,0],[0,-0.04],[0,0]],"v":[[7.57,3.38],[6.95,0.75],[6.74,0.47],[6.4,0.42],[6.06,0.97],[6.68,3.59],[6.68,3.59],[7.12,3.95],[7.58,3.49],[7.57,3.38]],"c":true}}},{"ty":"fl","o":{"k":100},"c":{"k":[0,0,0,1]}},{"ty":"tr","o":{"k":100},"r":{"k":0},"p":{"k":[0,0]},"a":{"k":[0,0]},"s":{"k":[100,100]},"sk":{"k":0},"sa":{"k":0},"hd":false}]},{"ty":"gr","hd":false,"it":[{"ty":"sh","ks":{"k":{"i":[[0,0],[0.1,-0.06],[0.03,-0.12],[0,0],[-0.25,-0.06],[-0.06,0.25],[0,0],[0,0],[0.25,0.06]],"o":[[-0.12,-0.03],[-0.1,0.07],[0,0],[-0.06,0.25],[0.25,0.06],[0,0],[0,0],[0.05,-0.25],[0,0]],"v":[[14.6,0.42],[14.26,0.47],[14.05,0.76],[13.43,3.38],[13.77,3.93],[14.32,3.59],[14.94,0.97],[14.94,0.97],[14.6,0.42]],"c":true}}},{"ty":"fl","o":{"k":100},"c":{"k":[0,0,0,1]}},{"ty":"tr","o":{"k":100},"r":{"k":0},"p":{"k":[0,0]},"a":{"k":[0,0]},"s":{"k":[100,100]},"sk":{"k":0},"sa":{"k":0},"hd":false}]},{"ty":"gr","hd":false,"it":[{"ty":"sh","ks":{"k":{"i":[[0,0],[0,-0.25],[0,0],[-0.25,0],[0,0.25],[0,0],[0.09,0.09],[0.12,0]],"o":[[-0.25,0],[0,0],[0,0.25],[0.25,0],[0,0],[0,-0.12],[-0.09,-0.09],[0,0]],"v":[[10.5,0],[10.04,0.46],[10.04,3.46],[10.5,3.91],[10.96,3.46],[10.96,0.46],[10.82,0.13],[10.5,0]],"c":true}}},{"ty":"fl","o":{"k":100},"c":{"k":[0,0,0,1]}},{"ty":"tr","o":{"k":100},"r":{"k":0},"p":{"k":[0,0]},"a":{"k":[0,0]},"s":{"k":[100,100]},"sk":{"k":0},"sa":{"k":0},"hd":false}]},{"ty":"gr","hd":false,"it":[{"ty":"sh","ks":{"k":{"i":[[0,0],[0.01,0.06],[0,0],[0.08,0.09],[0.12,0],[0,0],[0.01,-0.25],[0,0],[-0.06,-0.08],[0,0],[0,0],[-0.86,0],[0,0],[-0.01,0.86],[0,0],[0,0],[-0.08,0.09],[0,0.12],[0,0],[0.24,0.01],[0,0],[0,0]],"o":[[0.01,-0.06],[0,0],[0.01,-0.12],[-0.08,-0.09],[0,0],[-0.25,0],[0,0],[0,0.11],[0,0],[0,0],[0.01,0.86],[0,0],[0.86,0],[0,0],[0,0],[0.12,0],[0.08,-0.09],[0,0],[0.01,-0.24],[0,0],[0,0],[0,0]],"v":[[14.8,8.4],[14.8,8.21],[14.8,5.73],[14.69,5.4],[14.37,5.25],[6.61,5.25],[6.14,5.71],[6.14,8.25],[6.24,8.54],[7.79,11.86],[7.79,19.45],[9.37,21],[11.62,21],[13.19,19.45],[13.19,16.09],[13.76,16.09],[14.08,15.95],[14.2,15.63],[14.2,13.88],[13.79,13.43],[13.19,13.43],[13.19,11.82]],"c":true}}},{"ty":"sh","ks":{"k":{"i":[[0,0],[0,0],[0,0],[0,0]],"o":[[0,0],[0,0],[0,0],[0,0]],"v":[[7.07,6.19],[13.89,6.19],[13.89,7.75],[7.07,7.75]],"c":true}}},{"ty":"sh","ks":{"k":{"i":[[0,0],[0.35,0],[0,0],[0.01,0.35],[0,0],[0,0]],"o":[[-0.01,0.35],[0,0],[-0.36,0],[0,0],[0,0],[0,0]],"v":[[12.32,19.45],[11.66,20.09],[9.41,20.09],[8.76,19.45],[8.76,18.8],[12.33,18.8]],"c":true}}},{"ty":"sh","ks":{"k":{"i":[[0,0],[0,0],[0,0],[0,0]],"o":[[0,0],[0,0],[0,0],[0,0]],"v":[[13.33,14.36],[13.33,15.18],[13.24,15.18],[13.24,14.36]],"c":true}}},{"ty":"sh","ks":{"k":{"i":[[0,0],[0,-0.07],[0,0],[0,0],[0,0],[0.02,0.07],[0,0],[0,0]],"o":[[-0.03,0.07],[0,0],[0,0],[0,0],[0.02,-0.07],[0,0],[0,0],[0,0]],"v":[[12.35,11.52],[12.32,11.72],[12.32,17.88],[8.71,17.88],[8.71,11.72],[8.71,11.52],[7.38,8.67],[13.7,8.67]],"c":true}}},{"ty":"fl","o":{"k":100},"c":{"k":[0,0,0,1]}},{"ty":"tr","o":{"k":100},"r":{"k":0},"p":{"k":[0,0]},"a":{"k":[0,0]},"s":{"k":[100,100]},"sk":{"k":0},"sa":{"k":0},"hd":false}]},{"ty":"tr","o":{"k":100},"r":{"k":0},"p":{"k":[0,0]},"a":{"k":[0,0]},"s":{"k":[100,100]},"sk":{"k":0},"sa":{"k":0},"hd":false}]},{"ty":"tm","s":{"a":0,"k":0,"ix":1},"e":{"a":1,"k":[{"i":{"x":[0.35],"y":[1]},"o":{"x":[0.17],"y":[0.17]},"t":0,"s":[25]},{"t":55,"s":[100]}],"ix":2},"o":{"a":0,"k":0,"ix":3},"m":1,"ix":2,"nm":"Trim Paths 1","mn":"ADBE Vector Filter - Trim","hd":false}]}],"meta":{"g":"LF SVG to Lottie"}}
5 changes: 3 additions & 2 deletions projects/ev_stations/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'package:ev_stations/screens/users/dashboard.dart';
import 'package:ev_stations/screens/users/ev_charging_stations.dart';
import 'package:flutter/material.dart';

void main() {
Expand All @@ -12,11 +12,12 @@ class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'EV Stations',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const MyHomePage(title: 'EV Stations'),
home: const Scanner(),
);
}
}
131 changes: 131 additions & 0 deletions projects/ev_stations/lib/screens/users/ev_charging_stations.dart
Original file line number Diff line number Diff line change
@@ -1 +1,132 @@
// ev_charging_stations
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:qr_code_scanner/qr_code_scanner.dart';
import 'package:url_launcher/url_launcher.dart';
import 'package:lottie/lottie.dart';
import 'package:torch_light/torch_light.dart';

class Scanner extends StatefulWidget {
const Scanner({Key? key}) : super(key: key);

@override
_ScannerState createState() => _ScannerState();
}

class _ScannerState extends State<Scanner> {
final GlobalKey qrKey = GlobalKey(debugLabel: 'QR');
late QRViewController controller;

@override
void dispose() {
controller.dispose();
super.dispose();
}

@override
Widget build(BuildContext context) {
return Stack(
children: [
QRView(
key: qrKey,
onQRViewCreated: _onQRViewCreated,
),
Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Center(
child: Container(
width: 300,
height: 300,
decoration: BoxDecoration(
border: Border.all(
color: Colors.red,
width: 4,
),
borderRadius: BorderRadius.circular(12),
),
),
),
const SizedBox(
height: 100,
),
ElevatedButton(
child: CircleAvatar(
backgroundColor: Colors.transparent,
child: LottieBuilder.asset('assets/lottie/torch.json'),
),
onPressed: () {
_turnOnFlash(context);
})
],
),
],
);
}

void _onQRViewCreated(QRViewController controller) {
this.controller = controller;
controller.scannedDataStream.listen((scanData) async {
controller.pauseCamera();
if (await canLaunchUrl(Uri.parse((scanData.code)!))) {
await launchUrl(Uri.parse((scanData.code)!));
controller.resumeCamera();
} else {
showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: const Text('Url'),
content: SingleChildScrollView(
child: ListBody(
children: <Widget>[
Text('Barcode Type: ${describeEnum(scanData.format)}'),
Text('Data: ${scanData.code}'),
],
),
),
actions: <Widget>[
TextButton(
child: const Text('Ok'),
onPressed: () {
Navigator.of(context).pop();
_launchInBrowser(Uri.parse((scanData.code)!));
},
),
],
);
},
).then((value) => controller.resumeCamera());
}
});
}
}

Future<void> _launchInBrowser(Uri url) async {
if (!await launchUrl(
url,
mode: LaunchMode.externalApplication,
)) {
throw 'Could not launch $url';
}
}

Future<void> _turnOnFlash(BuildContext context) async {
try {
await TorchLight.enableTorch();
} on Exception catch (_) {
_showErrorMes('Could not enable Flashlight', context);
}
}

Future<void> _turnOffFlash(BuildContext context) async {
try {
await TorchLight.disableTorch();
} on Exception catch (_) {
_showErrorMes('Could not enable Flashlight', context);
}
}

void _showErrorMes(String mes, BuildContext context) {
ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text(mes)));
}
129 changes: 120 additions & 9 deletions projects/ev_stations/pubspec.lock
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
# Generated by pub
# See https://dart.dev/tools/pub/glossary#lockfile
packages:
archive:
dependency: transitive
description:
name: archive
url: "https://pub.dartlang.org"
source: hosted
version: "3.3.1"
async:
dependency: transitive
description:
Expand Down Expand Up @@ -42,7 +49,14 @@ packages:
name: collection
url: "https://pub.dartlang.org"
source: hosted
version: "1.15.0"
version: "1.16.0"
crypto:
dependency: transitive
description:
name: crypto
url: "https://pub.dartlang.org"
source: hosted
version: "3.0.2"
cupertino_icons:
dependency: "direct main"
description:
Expand All @@ -56,7 +70,7 @@ packages:
name: fake_async
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.0"
version: "1.3.0"
flutter:
dependency: "direct main"
description: flutter
Expand All @@ -74,13 +88,32 @@ packages:
description: flutter
source: sdk
version: "0.0.0"
flutter_web_plugins:
dependency: transitive
description: flutter
source: sdk
version: "0.0.0"
js:
dependency: transitive
description:
name: js
url: "https://pub.dartlang.org"
source: hosted
version: "0.6.4"
lints:
dependency: transitive
description:
name: lints
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.1"
lottie:
dependency: "direct main"
description:
name: lottie
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.0"
matcher:
dependency: transitive
description:
Expand All @@ -94,7 +127,7 @@ packages:
name: material_color_utilities
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.3"
version: "0.1.4"
meta:
dependency: transitive
description:
Expand All @@ -108,7 +141,21 @@ packages:
name: path
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.0"
version: "1.8.1"
plugin_platform_interface:
dependency: transitive
description:
name: plugin_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.2"
qr_code_scanner:
dependency: "direct main"
description:
name: qr_code_scanner
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.0"
sky_engine:
dependency: transitive
description: flutter
Expand All @@ -120,7 +167,7 @@ packages:
name: source_span
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.1"
version: "1.8.2"
stack_trace:
dependency: transitive
description:
Expand Down Expand Up @@ -155,20 +202,84 @@ packages:
name: test_api
url: "https://pub.dartlang.org"
source: hosted
version: "0.4.8"
version: "0.4.9"
torch_light:
dependency: "direct main"
description:
name: torch_light
url: "https://pub.dartlang.org"
source: hosted
version: "0.4.0"
typed_data:
dependency: transitive
description:
name: typed_data
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.0"
version: "1.3.1"
url_launcher:
dependency: "direct main"
description:
name: url_launcher
url: "https://pub.dartlang.org"
source: hosted
version: "6.1.5"
url_launcher_android:
dependency: transitive
description:
name: url_launcher_android
url: "https://pub.dartlang.org"
source: hosted
version: "6.0.17"
url_launcher_ios:
dependency: transitive
description:
name: url_launcher_ios
url: "https://pub.dartlang.org"
source: hosted
version: "6.0.17"
url_launcher_linux:
dependency: transitive
description:
name: url_launcher_linux
url: "https://pub.dartlang.org"
source: hosted
version: "3.0.1"
url_launcher_macos:
dependency: transitive
description:
name: url_launcher_macos
url: "https://pub.dartlang.org"
source: hosted
version: "3.0.1"
url_launcher_platform_interface:
dependency: transitive
description:
name: url_launcher_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.0"
url_launcher_web:
dependency: transitive
description:
name: url_launcher_web
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.12"
url_launcher_windows:
dependency: transitive
description:
name: url_launcher_windows
url: "https://pub.dartlang.org"
source: hosted
version: "3.0.1"
vector_math:
dependency: transitive
description:
name: vector_math
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.1"
version: "2.1.2"
sdks:
dart: ">=2.16.2 <3.0.0"
dart: ">=2.17.0 <3.0.0"
flutter: ">=2.10.0"
10 changes: 7 additions & 3 deletions projects/ev_stations/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ dependencies:
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^1.0.2
qr_code_scanner: ^1.0.0
url_launcher: ^6.1.5
lottie: ^1.3.0
torch_light: ^0.4.0

dev_dependencies:
flutter_test:
Expand All @@ -58,9 +62,9 @@ flutter:
uses-material-design: true

# To add assets to your application, add an assets section, like this:
# assets:
# - images/a_dot_burr.jpeg
# - images/a_dot_ham.jpeg
assets:
- assets/
- assets/lottie/

# An image asset can refer to one or more resolution-specific "variants", see
# https://flutter.dev/assets-and-images/#resolution-aware.
Expand Down
Loading

0 comments on commit d6fe3fd

Please sign in to comment.