-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Description
Steps to Reproduce
- Create a new Flutter App
- Install camera package
camera: 0.10.0+1 - Add the following in your Info.plist
<key>NSCameraUsageDescription</key>
<string>your usage description here</string>
<key>NSMicrophoneUsageDescription</key>
<string>your usage description here</string>
- Use the code below as your
main.dart - Run on an iOS device
Expected results:
The code renders a CameraPreview. It should call the callback of the startImageStream function and thus print "STREAM" in the console on every frame.
I have tested this on an iOS device (not simulator)
Actual results:
I receive a MissingPluginException, the callback of the startImageStream is not called and nothing is printed to the console.
What is particularly odd is, sometimes (not always!) after I run flutter clean it resolves the issue on the first run however when refreshing the app, this issue occurs again.
════════ Exception caught by services library ══════════════════════════════════
The following MissingPluginException was thrown while activating platform stream on channel plugins.flutter.io/camera_avfoundation/imageStream:
MissingPluginException(No implementation found for method listen on channel plugins.flutter.io/camera_avfoundation/imageStream)When the exception was thrown, this was the stack
#0 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:165:7)
#1 EventChannel.receiveBroadcastStream. (package:flutter/src/services/platform_channel.dart:506:9)
════════════════════════════════════════════════════════════════════════════════
Code sample
import 'package:camera/camera.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({Key? key}) : super(key: key);
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Digital Coach',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const HomePage(),
);
}
}
class HomePage extends StatefulWidget {
const HomePage({Key? key}) : super(key: key);
@override
State<HomePage> createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
late CameraController controller;
List<CameraDescription>? cameras;
@override
void initState() {
loadCameras();
super.initState();
}
loadCameras() async {
try {
cameras = await availableCameras();
setState(() {});
} on CameraException catch (e) {
print('Error: ${e.code}\nError Message: ${e.description}');
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text("Digital Coach"),
),
body: body(),
);
}
body() {
if (cameras?.isNotEmpty ?? false) {
return Center(
child: MyCameraPreview(cameras: cameras!),
);
}
return const Center(
child: Text("Loading Model"),
);
}
}
class MyCameraPreview extends StatefulWidget {
final List<CameraDescription> cameras;
const MyCameraPreview({
Key? key,
required this.cameras,
}) : super(key: key);
@override
State<MyCameraPreview> createState() => _MyCameraPreviewState();
}
class _MyCameraPreviewState extends State<MyCameraPreview> {
late CameraController controller;
bool isDetecting = false;
@override
void initState() {
initController();
super.initState();
}
initController() async {
controller = CameraController(
widget.cameras[1],
ResolutionPreset.low,
enableAudio: false,
imageFormatGroup: ImageFormatGroup.bgra8888,
);
await controller.initialize();
if (!mounted) {
return;
}
controller.startImageStream((CameraImage img) async {
print("STREAM");
});
setState(() {});
}
@override
Widget build(BuildContext context) {
return CameraPreview(controller);
}
}
Logs
Analyzing digital_coach...
info • Avoid `print` calls in production code • lib/main.dart:50:7 • avoid_print
info • Avoid `print` calls in production code • lib/main.dart:111:7 • avoid_print
[✓] Flutter (Channel stable, 3.0.0, on macOS 12.4 21F79 darwin-arm, locale en-DE)
• Flutter version 3.0.0 at /Users/jonas/Documents/flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision ee4e09cce0 (3 months ago), 2022-05-09 16:45:18 -0700
• Engine revision d1b9a6938a
• Dart version 2.17.0
• DevTools version 2.12.2
[✓] Android toolchain - develop for Android devices (Android SDK version 32.1.0-rc1)
• Android SDK at /Users/jonas/Library/Android/sdk
• Platform android-32, build-tools 32.1.0-rc1
• Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 13.4.1)
• Xcode at /Applications/Xcode.app/Contents/Developer
• CocoaPods version 1.11.3
[✓] Chrome - develop for the web
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[✓] Android Studio (version 2021.2)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840)
[✓] VS Code (version 1.69.0)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.46.0
[✓] Connected device (3 available)
• iPhone 13 Pro Max (mobile) • B4B1B502-82B3-410C-BF1E-4FFC61A12433 • ios • com.apple.CoreSimulator.SimRuntime.iOS-15-5 (simulator)
• macOS (desktop) • macos • darwin-arm64 • macOS 12.4 21F79 darwin-arm
• Chrome (web) • chrome • web-javascript • Google Chrome 104.0.5112.101
[✓] HTTP Host Availability
• All required HTTP hosts are available
• No issues found!