I think it’s rare to encounter this error because I found no one that had the same issue, so let me explain hoping I find the solution here.
I need to open a security camera stream (rtsp) in my app, and I am able to do that when running the app in debug mode (flutter run
). Although I encounter the same error, it still works. But if I run the app in release mode, it instantly crashes the app and it closes.
Here’s my code:
import 'package:flutter/material.dart';
import 'package:flutter_vlc_player/flutter_vlc_player.dart';
class StreamingScreen extends StatefulWidget {
final String streamUrl;
const StreamingScreen({Key? key, required this.streamUrl}) : super(key: key);
@override
State<StreamingScreen> createState() => _StreamingScreenState();
}
class _StreamingScreenState extends State<StreamingScreen> {
late VlcPlayerController _controller;
bool isFullScreen = false;
bool isLoading = true;
@override
void initState() {
super.initState();
_controller = VlcPlayerController.network(
widget.streamUrl,
autoPlay: true,
hwAcc: HwAcc.full,
);
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Live streaming'),
centerTitle: true,
),
body: Center(
child: Stack(
children: [
Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Expanded(
child: VlcPlayer(
controller: _controller,
aspectRatio: 16 / 9,
placeholder: const Center(
child: CircularProgressIndicator(),
),
),
),
],
),
],
),
),
);
}
@override
void dispose() {
_controller.dispose();
super.dispose();
}
}
Part of the error:
E/flutter (10296): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: LateInitializationError: Field '_viewId@1174035241' has not been initialized. E/flutter (10296): #0 VlcPlayerController._viewId (package:flutter_vlc_player/src/vlc_player_controller.dart) E/flutter (10296): #1 VlcPlayerController.initialize (package:flutter_vlc_player/src/vlc_player_controller.dart:192:15) E/flutter (10296): #2 _StreamingScreenState._initializeController (package:el_act/screens/streaming.dart:29:24) E/flutter (10296): #3 _StreamingScreenState.initState (package:el_act/screens/streaming.dart:20:5) E/flutter (10296): #4 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:5618:55) E/flutter (10296): #5 ComponentElement.mount (package:flutter/src/widgets/framework.dart:5463:5) E/flutter (10296): #6 Element.inflateWidget (package:flutter/src/widgets/framework.dart:4340:16)
I tried many solutions I found, and most of them suggested from ChatGPT, but nothing worked since this view id field is in the package code.
Firas Hkiri is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.