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
2023-11-09 10:13:43 +0100
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
c941a4cb2739307d207e91dcdfa49723b9788853
c941a4cb
1 parent
1c8776b2
add helper widgets for the example
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
164 additions
and
0 deletions
example/lib/scanner_button_widgets.dart
example/lib/scanner_button_widgets.dart
0 → 100644
View file @
c941a4c
import
'package:flutter/material.dart'
;
import
'package:image_picker/image_picker.dart'
;
import
'package:mobile_scanner/mobile_scanner.dart'
;
class
AnalyzeImageFromGalleryButton
extends
StatelessWidget
{
const
AnalyzeImageFromGalleryButton
({
required
this
.
controller
,
super
.
key
});
final
MobileScannerController
controller
;
@override
Widget
build
(
BuildContext
context
)
{
return
IconButton
(
color:
Colors
.
white
,
icon:
const
Icon
(
Icons
.
image
),
iconSize:
32.0
,
onPressed:
()
async
{
final
ImagePicker
picker
=
ImagePicker
();
final
XFile
?
image
=
await
picker
.
pickImage
(
source
:
ImageSource
.
gallery
,
);
if
(
image
==
null
)
{
return
;
}
final
BarcodeCapture
?
barcodes
=
await
controller
.
analyzeImage
(
image
.
path
,
);
if
(!
context
.
mounted
)
{
return
;
}
final
SnackBar
snackbar
=
barcodes
!=
null
?
const
SnackBar
(
content:
Text
(
'Barcode found!'
),
backgroundColor:
Colors
.
green
,
)
:
const
SnackBar
(
content:
Text
(
'No barcode found!'
),
backgroundColor:
Colors
.
red
,
);
ScaffoldMessenger
.
of
(
context
).
showSnackBar
(
snackbar
);
},
);
}
}
class
StartStopMobileScannerButton
extends
StatelessWidget
{
const
StartStopMobileScannerButton
({
required
this
.
controller
,
super
.
key
});
final
MobileScannerController
controller
;
@override
Widget
build
(
BuildContext
context
)
{
return
ValueListenableBuilder
(
valueListenable:
controller
,
builder:
(
context
,
state
,
child
)
{
if
(!
state
.
isInitialized
||
!
state
.
isRunning
)
{
return
IconButton
(
color:
Colors
.
white
,
icon:
const
Icon
(
Icons
.
play_arrow
),
iconSize:
32.0
,
onPressed:
()
async
{
await
controller
.
start
();
},
);
}
return
IconButton
(
color:
Colors
.
white
,
icon:
const
Icon
(
Icons
.
stop
),
iconSize:
32.0
,
onPressed:
()
async
{
await
controller
.
stop
();
},
);
},
);
}
}
class
SwitchCameraButton
extends
StatelessWidget
{
const
SwitchCameraButton
({
required
this
.
controller
,
super
.
key
});
final
MobileScannerController
controller
;
@override
Widget
build
(
BuildContext
context
)
{
return
ValueListenableBuilder
(
valueListenable:
controller
,
builder:
(
context
,
state
,
child
)
{
if
(!
state
.
isInitialized
||
!
state
.
isRunning
)
{
return
const
SizedBox
.
shrink
();
}
final
Widget
icon
;
switch
(
state
.
cameraDirection
)
{
case
CameraFacing
.
front
:
icon
=
const
Icon
(
Icons
.
camera_front
);
break
;
case
CameraFacing
.
back
:
icon
=
const
Icon
(
Icons
.
camera_rear
);
break
;
}
return
IconButton
(
iconSize:
32.0
,
icon:
icon
,
onPressed:
()
async
{
await
controller
.
switchCamera
();
},
);
},
);
}
}
class
ToggleFlashlightButton
extends
StatelessWidget
{
const
ToggleFlashlightButton
({
required
this
.
controller
,
super
.
key
});
final
MobileScannerController
controller
;
@override
Widget
build
(
BuildContext
context
)
{
return
ValueListenableBuilder
(
valueListenable:
controller
,
builder:
(
context
,
state
,
child
)
{
if
(!
state
.
isInitialized
||
!
state
.
isRunning
)
{
return
const
SizedBox
.
shrink
();
}
switch
(
state
.
torchState
)
{
case
TorchState
.
off
:
return
IconButton
(
color:
Colors
.
white
,
iconSize:
32.0
,
icon:
const
Icon
(
Icons
.
flash_off
),
onPressed:
()
async
{
await
controller
.
toggleTorch
();
},
);
case
TorchState
.
on
:
return
IconButton
(
color:
Colors
.
white
,
iconSize:
32.0
,
icon:
const
Icon
(
Icons
.
flash_on
),
onPressed:
()
async
{
await
controller
.
toggleTorch
();
},
);
case
TorchState
.
unavailable
:
return
const
Icon
(
Icons
.
no_flash
,
color:
Colors
.
grey
,
);
}
},
);
}
}
...
...
Please
register
or
login
to post a comment