-
Notifications
You must be signed in to change notification settings - Fork 380
Bad state: Cannot add event while adding a stream #1759
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
Comments
I think that the problem is that you are not - req.sink.addStream(result.files[0].readStream!);
+ await req.sink.addStream(result.files[0].readStream!); Please reopen the issue if that doesn't solve the problem. |
Thank you for your reply, but addStream will continue to block and cannot continue running until the HTTP function is sent |
Thank you for your reply, but addStream will continue to block and cannot continue running until the HTTP function is sent |
Then maybe you want to do (untested): - req.sink.addStream(result.files[0].readStream!);
- unawaited(req.sink.close());
+ unawaited(req.sink.addStream(result.files[0].readStream!)).then((_) => req.sink.close())); |
I tried, but it's still a bad state: Cannot add event while adding a stream |
Could you post your exact code and the exact stacktrace that you get? |
import 'dart:async'; import 'package:file_picker/file_picker.dart'; void main() { class MyApp extends StatelessWidget { @OverRide Future doS() async {
} catch (e) { Launching lib\main.dart on Chrome in debug mode... PS S:\SecludedClient\frontend> flutter doctor
! Doctor found issues in 2 categories. This is my diagnosis, and I think it should be fine because other HTTP functions in this library can run normally |
versions: http: ^1.3.0 |
You didn't modify your code to match my suggestion. |
Thank you, I have resolved it and need to modify it to req.sink.addStream(file.readStream!).then((_) => req.sink.close()); |
I tried to run the code in a web project, but encountered the error 'Bad state: Cannot add event while adding a stream'
import 'dart:async';
import 'dart:convert' as convert;
import 'package:file_picker/file_picker.dart';
import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@OverRide
Widget build(BuildContext context) {
return MaterialApp(
home: TextButton(onPressed: () => doS(), child: Text('data')),
);
}
}
Future doS() async {
try {
FilePickerResult? result = await FilePicker.platform.pickFiles(
type: FileType.custom,
allowedExtensions: ["txt", "zip"],
withData: false,
withReadStream: true,
);
} catch (e) {
debugPrint(e.toString());
}
}
The text was updated successfully, but these errors were encountered: