Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/flashlight player ticket #8

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 37 additions & 6 deletions lib/screens/ticket_player.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:camera/camera.dart';
import 'package:ua_app_secu/controllers/entrance.dart';
import 'package:ua_app_secu/models/entrance_player.dart';

Expand All @@ -14,6 +15,25 @@ class PlayerTicket extends StatefulWidget {

class _PlayerTicketState extends State<PlayerTicket> {
EntranceController controller = Get.find();
late CameraController _camController;
bool _isFlashlightOn = false;

@override
void initState() {
super.initState();
availableCameras().then((value) async {
_camController = CameraController(value[0], ResolutionPreset.low, enableAudio: false);
await _camController.initialize();
await _camController.setFlashMode(FlashMode.off);
_isFlashlightOn = false;
});
}

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

@override
Widget build(BuildContext context) {
Expand All @@ -24,13 +44,30 @@ class _PlayerTicketState extends State<PlayerTicket> {
children: [
// Back icon
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
IconButton(
icon: const Icon(Icons.arrow_back_rounded),
onPressed: () {
controller.changePage(0);
},
),
IconButton(
icon: Icon(_isFlashlightOn ? Icons.flashlight_off_rounded : Icons.flashlight_on_rounded),
onPressed: () {
setState(() {
if(_camController.value.isInitialized) {
if(_camController.value.flashMode != FlashMode.torch) {
_camController.setFlashMode(FlashMode.torch);
_isFlashlightOn = true;
} else{
_camController.setFlashMode(FlashMode.off);
_isFlashlightOn = false;
}
}
});
},
),
],
),
Column(
Expand Down Expand Up @@ -113,12 +150,6 @@ class _PlayerTicketState extends State<PlayerTicket> {
},
child: const Text('SCANNER UN AUTRE BILLET'),
),
// ElevatedButton(
// onPressed: () {
// controller.changePage(0);
// },
// child: const Text('VALIDER'),
// ),
],
),
],
Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ dependencies:
flutter_dotenv: ^5.0.2
get_storage: ^2.0.3
flutter_native_splash: ^2.2.15
camera: ^0.10.5+5

dev_dependencies:
flutter_test:
Expand Down