Toggle navigation
Toggle navigation
This project
Loading...
Sign in
flutter_package
/
mobile_scanner
Go to a project
Toggle navigation
Projects
Groups
Snippets
Help
Toggle navigation pinning
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
Navaron Bracke
2022-11-20 14:57:17 +0100
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
718ee59e1a8cc54e5b11d311e0d8b16a4e69ad1d
718ee59e
1 parent
2ddac10f
handle errors from controller.start() in example app
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
78 additions
and
14 deletions
example/lib/barcode_list_scanner_controller.dart
example/lib/barcode_scanner_controller.dart
example/lib/barcode_scanner_returning_image.dart
example/lib/barcode_list_scanner_controller.dart
View file @
718ee59
...
...
@@ -26,6 +26,31 @@ class _BarcodeListScannerWithControllerState
bool
isStarted
=
true
;
void
_startOrStop
()
{
if
(
isStarted
)
{
controller
.
stop
();
}
else
{
controller
.
start
().
catchError
((
error
)
{
final
exception
=
error
as
MobileScannerException
;
switch
(
exception
.
errorCode
)
{
case
MobileScannerErrorCode
.
controllerUninitialized
:
break
;
// This error code is not used by `start()`.
case
MobileScannerErrorCode
.
genericError
:
debugPrint
(
'Scanner failed to start'
);
break
;
case
MobileScannerErrorCode
.
permissionDenied
:
debugPrint
(
'Camera permission denied'
);
break
;
}
});
}
setState
(()
{
isStarted
=
!
isStarted
;
});
}
@override
Widget
build
(
BuildContext
context
)
{
return
Scaffold
(
...
...
@@ -93,10 +118,7 @@ class _BarcodeListScannerWithControllerState
?
const
Icon
(
Icons
.
stop
)
:
const
Icon
(
Icons
.
play_arrow
),
iconSize:
32.0
,
onPressed:
()
=>
setState
(()
{
isStarted
?
controller
.
stop
()
:
controller
.
start
();
isStarted
=
!
isStarted
;
}),
onPressed:
_startOrStop
,
),
Center
(
child:
SizedBox
(
...
...
example/lib/barcode_scanner_controller.dart
View file @
718ee59
...
...
@@ -26,6 +26,31 @@ class _BarcodeScannerWithControllerState
bool
isStarted
=
true
;
void
_startOrStop
()
{
if
(
isStarted
)
{
controller
.
stop
();
}
else
{
controller
.
start
().
catchError
((
error
)
{
final
exception
=
error
as
MobileScannerException
;
switch
(
exception
.
errorCode
)
{
case
MobileScannerErrorCode
.
controllerUninitialized
:
break
;
// This error code is not used by `start()`.
case
MobileScannerErrorCode
.
genericError
:
debugPrint
(
'Scanner failed to start'
);
break
;
case
MobileScannerErrorCode
.
permissionDenied
:
debugPrint
(
'Camera permission denied'
);
break
;
}
});
}
setState
(()
{
isStarted
=
!
isStarted
;
});
}
@override
Widget
build
(
BuildContext
context
)
{
return
Scaffold
(
...
...
@@ -90,10 +115,7 @@ class _BarcodeScannerWithControllerState
?
const
Icon
(
Icons
.
stop
)
:
const
Icon
(
Icons
.
play_arrow
),
iconSize:
32.0
,
onPressed:
()
=>
setState
(()
{
isStarted
?
controller
.
stop
()
:
controller
.
start
();
isStarted
=
!
isStarted
;
}),
onPressed:
_startOrStop
,
),
Center
(
child:
SizedBox
(
...
...
example/lib/barcode_scanner_returning_image.dart
View file @
718ee59
...
...
@@ -28,6 +28,31 @@ class _BarcodeScannerReturningImageState
bool
isStarted
=
true
;
void
_startOrStop
()
{
if
(
isStarted
)
{
controller
.
stop
();
}
else
{
controller
.
start
().
catchError
((
error
)
{
final
exception
=
error
as
MobileScannerException
;
switch
(
exception
.
errorCode
)
{
case
MobileScannerErrorCode
.
controllerUninitialized
:
break
;
// This error code is not used by `start()`.
case
MobileScannerErrorCode
.
genericError
:
debugPrint
(
'Scanner failed to start'
);
break
;
case
MobileScannerErrorCode
.
permissionDenied
:
debugPrint
(
'Camera permission denied'
);
break
;
}
});
}
setState
(()
{
isStarted
=
!
isStarted
;
});
}
@override
Widget
build
(
BuildContext
context
)
{
return
Scaffold
(
...
...
@@ -112,12 +137,7 @@ class _BarcodeScannerReturningImageState
?
const
Icon
(
Icons
.
stop
)
:
const
Icon
(
Icons
.
play_arrow
),
iconSize:
32.0
,
onPressed:
()
=>
setState
(()
{
isStarted
?
controller
.
stop
()
:
controller
.
start
();
isStarted
=
!
isStarted
;
}),
onPressed:
_startOrStop
,
),
Center
(
child:
SizedBox
(
...
...
Please
register
or
login
to post a comment