Closed ken-ty closed 7 months ago
I opened an issue related to Flutter/Flutter for the first time. Is this reproducible? I'd like to write a PR if you need a fix. 👍
After doing some research, I found the cause. The original condition calls Navigator.pop() multiple times each time the controller changes. You can avoid this problem by modifying the conditions appropriately as shown below.
...
@override
void initState() {
super.initState();
_videoPlayerController =
VideoPlayerController.asset('assets/Butterfly-209.mp4');
_videoPlayerController.addListener(() {
// # before
// if (startedPlaying && !_videoPlayerController.value.isPlaying) {
// Navigator.pop(context);
// }
// # after
if (startedPlaying && _videoPlayerController.value.isCompleted) {
Navigator.pop(context);
startedPlaying = false;
}
});
}
...
Thanks for filing the issue and proposing a solution for this. But I see there is a known issue at https://github.com/flutter/flutter/issues/122690. We welcome everyone to contribute a PR so please take it if you are interested :)
Closing this as a duplicate of https://github.com/flutter/flutter/issues/122690.
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v
and a minimal reproduction of the issue.
Steps to reproduce
Expected results
The screen pops and transitions to the original tab screen.
Actual results
The context cannot be obtained, and if you are using Android, the screen will freeze, or if you are using iPhone, the screen will be black.
Code sample
This code has not been edited.
Code sample
```dart // Copyright 2013 The Flutter Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // ignore_for_file: public_member_api_docs /// An example of using the plugin, controlling lifecycle and playback of the /// video. library; import 'package:flutter/material.dart'; import 'package:video_player/video_player.dart'; void main() { runApp( MaterialApp( home: _App(), ), ); } class _App extends StatelessWidget { @override Widget build(BuildContext context) { return DefaultTabController( length: 3, child: Scaffold( key: const ValueKeyScreenshots or Video
Screenshots / Video demonstration
https://github.com/flutter/flutter/assets/38717219/c6eca1e5-5400-413c-989d-af484a8b1960Logs
Logs
```console ════════ Exception caught by foundation library ════════════════════════════════ The following StateError was thrown while dispatching notifications for VideoPlayerController: Bad state: No element When the exception was thrown, this was the stack: #0 Iterable.lastWhere (dart:core/iterable.dart:733:9) iterable.dart:733 #1 NavigatorState.pop (package:flutter/src/widgets/navigator.dart:5243:40) navigator.dart:5243 #2 Navigator.pop (package:flutter/src/widgets/navigator.dart:2569:27) navigator.dart:2569 #3 _PlayerVideoAndPopPageState.initState.Flutter Doctor output
Doctor output
```console xxx@yyy packages % flutter doctor Doctor summary (to see all details, run flutter doctor -v): [✓] Flutter (Channel stable, 3.16.7, on macOS 14.0 23A344 darwin-x64, locale ja-JP) [✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0) [✓] Xcode - develop for iOS and macOS (Xcode 15.0) [✓] Chrome - develop for the web [✓] Android Studio (version 2021.3) [✓] VS Code (version 1.85.2) [✓] Connected device (5 available) [✓] Network resources • No issues found! ```