Skip to content

Commit

Permalink
- Corrigindo bug de não trocar de camera em aparelhos com mais de uma…
Browse files Browse the repository at this point in the history
… camera
  • Loading branch information
matheusperez committed Jun 8, 2020
1 parent aeb3ac8 commit 7b08d85
Show file tree
Hide file tree
Showing 8 changed files with 101 additions and 44 deletions.
1 change: 1 addition & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
{
"name": "Flutter",
"request": "launch",
"program": "example/lib/main_dev.dart",
"type": "dart"
}
]
Expand Down
2 changes: 1 addition & 1 deletion example/.flutter-plugins-dependencies
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"camera","path":"/Users/gabrielsavio/Developer/Mobile/Setup/flutter/.pub-cache/hosted/pub.dartlang.org/camera-0.5.7+4/","dependencies":[]},{"name":"native_device_orientation","path":"/Users/gabrielsavio/Developer/Mobile/Setup/flutter/.pub-cache/hosted/pub.dartlang.org/native_device_orientation-0.3.0/","dependencies":[]},{"name":"path_provider","path":"/Users/gabrielsavio/Developer/Mobile/Setup/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider-1.6.7/","dependencies":[]},{"name":"video_player","path":"/Users/gabrielsavio/Developer/Mobile/Setup/flutter/.pub-cache/hosted/pub.dartlang.org/video_player-0.10.9+2/","dependencies":[]},{"name":"wakelock","path":"/Users/gabrielsavio/Developer/Mobile/Setup/flutter/.pub-cache/hosted/pub.dartlang.org/wakelock-0.1.4+1/","dependencies":[]}],"android":[{"name":"camera","path":"/Users/gabrielsavio/Developer/Mobile/Setup/flutter/.pub-cache/hosted/pub.dartlang.org/camera-0.5.7+4/","dependencies":[]},{"name":"native_device_orientation","path":"/Users/gabrielsavio/Developer/Mobile/Setup/flutter/.pub-cache/hosted/pub.dartlang.org/native_device_orientation-0.3.0/","dependencies":[]},{"name":"path_provider","path":"/Users/gabrielsavio/Developer/Mobile/Setup/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider-1.6.7/","dependencies":[]},{"name":"video_player","path":"/Users/gabrielsavio/Developer/Mobile/Setup/flutter/.pub-cache/hosted/pub.dartlang.org/video_player-0.10.9+2/","dependencies":[]},{"name":"wakelock","path":"/Users/gabrielsavio/Developer/Mobile/Setup/flutter/.pub-cache/hosted/pub.dartlang.org/wakelock-0.1.4+1/","dependencies":[]}],"macos":[{"name":"path_provider_macos","path":"/Users/gabrielsavio/Developer/Mobile/Setup/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider_macos-0.0.4+2/","dependencies":[]}],"linux":[],"windows":[],"web":[{"name":"video_player_web","path":"/Users/gabrielsavio/Developer/Mobile/Setup/flutter/.pub-cache/hosted/pub.dartlang.org/video_player_web-0.1.1+1/","dependencies":[]}]},"dependencyGraph":[{"name":"camera","dependencies":[]},{"name":"native_device_orientation","dependencies":[]},{"name":"path_provider","dependencies":["path_provider_macos"]},{"name":"path_provider_macos","dependencies":[]},{"name":"video_player","dependencies":["video_player_web"]},{"name":"video_player_web","dependencies":[]},{"name":"wakelock","dependencies":[]}],"date_created":"2020-05-14 07:05:28.979122","version":"1.17.0"}
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"camera","path":"C:\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\camera-0.5.8+2\\\\","dependencies":[]},{"name":"native_device_orientation","path":"C:\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\native_device_orientation-0.3.0\\\\","dependencies":[]},{"name":"path_provider","path":"C:\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\path_provider-1.6.10\\\\","dependencies":[]},{"name":"video_player","path":"C:\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\video_player-0.10.11+1\\\\","dependencies":[]},{"name":"wakelock","path":"C:\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\wakelock-0.1.4+1\\\\","dependencies":[]}],"android":[{"name":"camera","path":"C:\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\camera-0.5.8+2\\\\","dependencies":[]},{"name":"native_device_orientation","path":"C:\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\native_device_orientation-0.3.0\\\\","dependencies":[]},{"name":"path_provider","path":"C:\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\path_provider-1.6.10\\\\","dependencies":[]},{"name":"video_player","path":"C:\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\video_player-0.10.11+1\\\\","dependencies":[]},{"name":"wakelock","path":"C:\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\wakelock-0.1.4+1\\\\","dependencies":[]}],"macos":[{"name":"path_provider_macos","path":"C:\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\path_provider_macos-0.0.4+3\\\\","dependencies":[]}],"linux":[{"name":"path_provider_linux","path":"C:\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\path_provider_linux-0.0.1+1\\\\","dependencies":[]}],"windows":[],"web":[{"name":"video_player_web","path":"C:\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\video_player_web-0.1.3+1\\\\","dependencies":[]}]},"dependencyGraph":[{"name":"camera","dependencies":[]},{"name":"native_device_orientation","dependencies":[]},{"name":"path_provider","dependencies":["path_provider_macos","path_provider_linux"]},{"name":"path_provider_linux","dependencies":[]},{"name":"path_provider_macos","dependencies":[]},{"name":"video_player","dependencies":["video_player_web"]},{"name":"video_player_web","dependencies":[]},{"name":"wakelock","dependencies":[]}],"date_created":"2020-06-08 15:56:22.563026","version":"1.17.3"}
10 changes: 5 additions & 5 deletions example/ios/Flutter/flutter_export_environment.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#!/bin/sh
# This is a generated file; do not edit or check into version control.
export "FLUTTER_ROOT=/Users/gabrielsavio/Developer/Mobile/Setup/flutter"
export "FLUTTER_APPLICATION_PATH=/Users/gabrielsavio/Developer/Mobile/Packages/camera_camera/example"
export "FLUTTER_TARGET=lib/main.dart"
export "FLUTTER_ROOT=C:\flutter"
export "FLUTTER_APPLICATION_PATH=D:\APPS\PACKAGES\camera_camera\example"
export "FLUTTER_TARGET=lib\main.dart"
export "FLUTTER_BUILD_DIR=build"
export "SYMROOT=${SOURCE_ROOT}/../build/ios"
export "SYMROOT=${SOURCE_ROOT}/../build\ios"
export "OTHER_LDFLAGS=$(inherited) -framework Flutter"
export "FLUTTER_FRAMEWORK_DIR=/Users/gabrielsavio/Developer/Mobile/Setup/flutter/bin/cache/artifacts/engine/ios"
export "FLUTTER_FRAMEWORK_DIR=C:\flutter\bin\cache\artifacts\engine\ios"
export "FLUTTER_BUILD_NAME=1.0.0"
export "FLUTTER_BUILD_NUMBER=1"
11 changes: 8 additions & 3 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'dart:developer';
import 'dart:io';

import 'package:flutter/material.dart';
Expand Down Expand Up @@ -38,12 +39,16 @@ class _HomeScreenState extends State<HomeScreen> {
context: context,
builder: (context) => Camera(
mode: CameraMode.normal,
orientationEnablePhoto: CameraOrientation.landscape,
/*
// orientationEnablePhoto: CameraOrientation.landscape,
onChangeCamera: (direction, _) {
print('--------------');
print('$direction');
print('--------------');
},

imageMask: CameraFocus.square(
color: Colors.black.withOpacity(0.5),
),
*/
));
setState(() {});
}),
Expand Down
51 changes: 43 additions & 8 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ packages:
name: camera
url: "https://pub.dartlang.org"
source: hosted
version: "0.5.7+4"
version: "0.5.8+2"
camera_camera:
dependency: "direct main"
description:
Expand Down Expand Up @@ -78,6 +78,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.3"
file:
dependency: transitive
description:
name: file
url: "https://pub.dartlang.org"
source: hosted
version: "5.1.0"
flutter:
dependency: "direct main"
description: flutter
Expand All @@ -100,6 +107,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.12"
intl:
dependency: transitive
description:
name: intl
url: "https://pub.dartlang.org"
source: hosted
version: "0.16.1"
matcher:
dependency: transitive
description:
Expand Down Expand Up @@ -134,21 +148,28 @@ packages:
name: path_provider
url: "https://pub.dartlang.org"
source: hosted
version: "1.6.7"
version: "1.6.10"
path_provider_linux:
dependency: transitive
description:
name: path_provider_linux
url: "https://pub.dartlang.org"
source: hosted
version: "0.0.1+1"
path_provider_macos:
dependency: transitive
description:
name: path_provider_macos
url: "https://pub.dartlang.org"
source: hosted
version: "0.0.4+2"
version: "0.0.4+3"
path_provider_platform_interface:
dependency: transitive
description:
name: path_provider_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.1"
version: "1.0.2"
petitparser:
dependency: transitive
description:
Expand All @@ -170,6 +191,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.2"
process:
dependency: transitive
description:
name: process
url: "https://pub.dartlang.org"
source: hosted
version: "3.0.13"
quiver:
dependency: transitive
description:
Expand All @@ -183,7 +211,7 @@ packages:
name: rxdart
url: "https://pub.dartlang.org"
source: hosted
version: "0.24.0"
version: "0.24.1"
sky_engine:
dependency: transitive
description: flutter
Expand Down Expand Up @@ -251,28 +279,35 @@ packages:
name: video_player
url: "https://pub.dartlang.org"
source: hosted
version: "0.10.9+2"
version: "0.10.11+1"
video_player_platform_interface:
dependency: transitive
description:
name: video_player_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.4"
version: "2.0.2"
video_player_web:
dependency: transitive
description:
name: video_player_web
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.1+1"
version: "0.1.3+1"
wakelock:
dependency: transitive
description:
name: wakelock
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.4+1"
xdg_directories:
dependency: transitive
description:
name: xdg_directories
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.0"
xml:
dependency: transitive
description:
Expand Down
6 changes: 0 additions & 6 deletions example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,29 +30,23 @@ dev_dependencies:
flutter_test:
sdk: flutter


# For information on the generic Dart part of this file, see the
# following page: https://www.dartlang.org/tools/pub/pubspec

# The following section is specific to Flutter.
flutter:

# The following line ensures that the Material Icons font is
# included with your application, so that you can use the icons in
# the material Icons class.
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

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

# For details regarding adding assets from package dependencies, see
# https://flutter.io/assets-and-images/#from-packages

# To add custom fonts to your application, add a fonts section here,
# in this "flutter" section. Each entry in this list should have a
# "family" key with the font family name, and a "fonts" key with a
Expand Down
25 changes: 18 additions & 7 deletions lib/page/bloc/bloc_camera.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import 'dart:developer';
import 'dart:io';
import 'package:camera/camera.dart';
import 'package:flutter/cupertino.dart';
import 'package:rxdart/rxdart.dart';
import 'dart:async';
import 'package:path_provider/path_provider.dart';
Expand Down Expand Up @@ -52,7 +54,7 @@ class BlocCamera {
});
}

void onNewCameraSelected(CameraDescription cameraDescription) async {
Future<Null> onNewCameraSelected(CameraDescription cameraDescription) async {
selectCamera.sink.add(null);
if (controllCamera != null) {
await controllCamera.dispose();
Expand All @@ -66,22 +68,31 @@ class BlocCamera {
await controllCamera.initialize().then((value) {
selectCamera.sink.add(true);
}).catchError((e) {
print(e);
debugPrint('####### ERROR ####### ');
debugPrint(e);
debugPrint('############## ');
});

return;
}

void changeCamera() {
Future<Null> changeCamera() async {
var list = cameras.value;
if (list.length == 2) {

debugPrint('LOGX: ${list.length}');
if (list.length > 1) {
if (controllCamera.description.lensDirection ==
CameraLensDirection.back) {
onNewCameraSelected(list[1]);
cameraOn.sink.add(1);
debugPrint('LOGX: Frontal selected');
await onNewCameraSelected(list.last);
cameraOn.sink.add(list.length - 1);
} else {
onNewCameraSelected(list[0]);
debugPrint('LOGX: Back selected');
await onNewCameraSelected(list[0]);
cameraOn.sink.add(0);
}
}
return;
}

void deletePhoto() {
Expand Down
39 changes: 25 additions & 14 deletions lib/page/camera.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,18 @@ class Camera extends StatefulWidget {
final Widget warning;
final CameraOrientation orientationEnablePhoto;
final Function(File image) onFile;
const Camera(
{Key key,
this.imageMask,
this.mode = CameraMode.fullscreen,
this.orientationEnablePhoto = CameraOrientation.all,
this.onFile,
this.warning})
: super(key: key);
final Function(CameraLensDirection direction, List<CameraDescription> cameras)
onChangeCamera;

const Camera({
Key key,
this.imageMask,
this.mode = CameraMode.fullscreen,
this.orientationEnablePhoto = CameraOrientation.all,
this.onFile,
this.warning,
this.onChangeCamera,
}) : super(key: key);
@override
_CameraState createState() => _CameraState();
}
Expand Down Expand Up @@ -67,6 +71,17 @@ class _CameraState extends State<Camera> {
bloc.dispose();
}

void _changeCamera() async {
await bloc.changeCamera();

if (widget.onChangeCamera != null) {
widget.onChangeCamera(
bloc.controllCamera.description.lensDirection,
bloc.cameras.value,
);
}
}

@override
Widget build(BuildContext context) {
Size size = MediaQuery.of(context).size;
Expand Down Expand Up @@ -276,9 +291,7 @@ class _CameraState extends State<Camera> {
color: Colors.white,
),
),
onTap: () {
bloc.changeCamera();
},
onTap: () => _changeCamera(),
),
backgroundColor: Colors.black38,
radius: 25.0,
Expand Down Expand Up @@ -367,9 +380,7 @@ class _CameraState extends State<Camera> {
color: Colors.white,
),
),
onTap: () {
bloc.changeCamera();
},
onTap: () => _changeCamera(),
),
backgroundColor: Colors.black38,
radius: 25.0,
Expand Down

0 comments on commit 7b08d85

Please sign in to comment.