Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
AppDeggendorf_Flutter
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Chaitanya Mangra
AppDeggendorf_Flutter
Commits
7e93b7fc
Commit
7e93b7fc
authored
2 years ago
by
benedikts
Browse files
Options
Downloads
Patches
Plain Diff
added functionality to scan qr- and barcodes
parent
360fd62d
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!3
Qr scanner
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
lib/bottom_navigation_bar_buttons/event/barwidget.dart
+5
-2
5 additions, 2 deletions
lib/bottom_navigation_bar_buttons/event/barwidget.dart
lib/bottom_navigation_bar_buttons/event/qr_scanner.dart
+172
-1
172 additions, 1 deletion
lib/bottom_navigation_bar_buttons/event/qr_scanner.dart
with
177 additions
and
3 deletions
lib/bottom_navigation_bar_buttons/event/barwidget.dart
+
5
−
2
View file @
7e93b7fc
import
'package:deggendorf_app/bottom_navigation_bar_buttons/event/qr_scanner.dart'
;
import
'package:flutter/material.dart'
;
import
'package:flutter/material.dart'
;
import
'package:deggendorf_app/bottom_navigation_bar_buttons/event/imageslides.dart'
;
import
'package:deggendorf_app/bottom_navigation_bar_buttons/event/imageslides.dart'
;
import
'package:deggendorf_app/bottom_navigation_bar_buttons/event/infobox_text.dart'
;
import
'package:deggendorf_app/bottom_navigation_bar_buttons/event/infobox_text.dart'
;
import
'package:deggendorf_app/bottom_navigation_bar_buttons/event/qr_scanner.dart'
;
class
BarWidget
extends
StatefulWidget
{
class
BarWidget
extends
StatefulWidget
{
const
BarWidget
({
Key
?
key
,
required
this
.
barName
})
:
super
(
key:
key
);
const
BarWidget
({
Key
?
key
,
required
this
.
barName
})
:
super
(
key:
key
);
...
@@ -33,7 +33,10 @@ class _BarWidgetState extends State<BarWidget> {
...
@@ -33,7 +33,10 @@ class _BarWidgetState extends State<BarWidget> {
)),
)),
floatingActionButton:
FloatingActionButton
(
floatingActionButton:
FloatingActionButton
(
onPressed:
()
{
onPressed:
()
{
QrScanner
();
Navigator
.
push
(
context
,
MaterialPageRoute
(
builder:
(
context
)
=
>
QRViewExample
()),
);
},
},
backgroundColor:
Colors
.
green
,
backgroundColor:
Colors
.
green
,
child:
Icon
(
Icons
.
qr_code_scanner
),
child:
Icon
(
Icons
.
qr_code_scanner
),
...
...
This diff is collapsed.
Click to expand it.
lib/bottom_navigation_bar_buttons/event/qr_scanner.dart
+
172
−
1
View file @
7e93b7fc
import
'package:flutter/cupertino.dart'
;
import
'dart:developer'
;
import
'package:flutter/foundation.dart'
;
import
'package:flutter/material.dart'
;
import
'package:flutter/material.dart'
;
import
'package:qr_code_scanner/qr_code_scanner.dart'
;
/*
class QrScanner extends StatefulWidget {
class QrScanner extends StatefulWidget {
const QrScanner({Key? key}) : super(key: key);
const QrScanner({Key? key}) : super(key: key);
...
@@ -14,3 +19,169 @@ class _QrScannerState extends State {
...
@@ -14,3 +19,169 @@ class _QrScannerState extends State {
return Scaffold(body: Container(color: Colors.greenAccent));
return Scaffold(body: Container(color: Colors.greenAccent));
}
}
}
}
*/
class
QRViewExample
extends
StatefulWidget
{
const
QRViewExample
({
Key
?
key
})
:
super
(
key:
key
);
@override
State
<
StatefulWidget
>
createState
()
=
>
_QRViewExampleState
();
}
class
_QRViewExampleState
extends
State
<
QRViewExample
>
{
Barcode
?
result
;
QRViewController
?
controller
;
final
GlobalKey
qrKey
=
GlobalKey
(
debugLabel:
'QR'
);
// In order to get hot reload to work we need to pause the camera if the platform
// is android, or resume the camera if the platform is iOS.
@override
void
reassemble
()
{
super
.
reassemble
();
controller
!.
pauseCamera
();
}
@override
Widget
build
(
BuildContext
context
)
{
return
Scaffold
(
body:
Column
(
children:
<
Widget
>[
Expanded
(
flex:
4
,
child:
_buildQrView
(
context
)),
Expanded
(
flex:
1
,
child:
FittedBox
(
fit:
BoxFit
.
contain
,
child:
Column
(
mainAxisAlignment:
MainAxisAlignment
.
spaceEvenly
,
children:
<
Widget
>[
if
(
result
!=
null
)
Text
(
'Barcode Type:
${describeEnum(result!.format)}
Data:
${result!.code}
'
)
else
const
Text
(
'Scan a code'
),
Row
(
mainAxisAlignment:
MainAxisAlignment
.
center
,
crossAxisAlignment:
CrossAxisAlignment
.
center
,
children:
<
Widget
>[
Container
(
margin:
const
EdgeInsets
.
all
(
8
),
child:
ElevatedButton
(
onPressed:
()
async
{
await
controller
?.
toggleFlash
();
setState
(()
{});
},
child:
FutureBuilder
(
future:
controller
?.
getFlashStatus
(),
builder:
(
context
,
snapshot
)
{
return
Text
(
'Flash:
${snapshot.data}
'
);
},
)),
),
Container
(
margin:
const
EdgeInsets
.
all
(
8
),
child:
ElevatedButton
(
onPressed:
()
async
{
await
controller
?.
flipCamera
();
setState
(()
{});
},
child:
FutureBuilder
(
future:
controller
?.
getCameraInfo
(),
builder:
(
context
,
snapshot
)
{
if
(
snapshot
.
data
!=
null
)
{
return
Text
(
'Camera facing
${describeEnum(snapshot.data!)}
'
);
}
else
{
return
const
Text
(
'loading'
);
}
},
)),
)
],
),
Row
(
mainAxisAlignment:
MainAxisAlignment
.
center
,
crossAxisAlignment:
CrossAxisAlignment
.
center
,
children:
<
Widget
>[
Container
(
margin:
const
EdgeInsets
.
all
(
8
),
child:
ElevatedButton
(
onPressed:
()
async
{
await
controller
?.
pauseCamera
();
},
child:
const
Text
(
'pause'
,
style:
TextStyle
(
fontSize:
20
)),
),
),
Container
(
margin:
const
EdgeInsets
.
all
(
8
),
child:
ElevatedButton
(
onPressed:
()
async
{
await
controller
?.
resumeCamera
();
},
child:
const
Text
(
'resume'
,
style:
TextStyle
(
fontSize:
20
)),
),
)
],
),
],
),
),
)
],
),
);
}
Widget
_buildQrView
(
BuildContext
context
)
{
// For this example we check how width or tall the device is and change the scanArea and overlay accordingly.
var
scanArea
=
(
MediaQuery
.
of
(
context
)
.
size
.
width
<
400
||
MediaQuery
.
of
(
context
)
.
size
.
height
<
400
)
?
150.0
:
300.0
;
// To ensure the Scanner view is properly sizes after rotation
// we need to listen for Flutter SizeChanged notification and update controller
return
QRView
(
key:
qrKey
,
onQRViewCreated:
_onQRViewCreated
,
overlay:
QrScannerOverlayShape
(
borderColor:
Colors
.
red
,
borderRadius:
10
,
borderLength:
30
,
borderWidth:
10
,
cutOutSize:
scanArea
),
onPermissionSet:
(
ctrl
,
p
)
=
>
_onPermissionSet
(
context
,
ctrl
,
p
),
);
}
void
_onQRViewCreated
(
QRViewController
controller
)
{
setState
(()
{
this
.
controller
=
controller
;
});
controller
.
scannedDataStream
.
listen
((
scanData
)
{
setState
(()
{
result
=
scanData
;
});
});
}
void
_onPermissionSet
(
BuildContext
context
,
QRViewController
ctrl
,
bool
p
)
{
log
(
'
${DateTime.now().toIso8601String()}
_onPermissionSet
$p
'
);
if
(
!
p
)
{
ScaffoldMessenger
.
of
(
context
)
.
showSnackBar
(
const
SnackBar
(
content:
Text
(
'no Permission'
)),
);
}
}
@override
void
dispose
()
{
controller
?.
dispose
();
super
.
dispose
();
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment