Skip to content
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

Incorrect dart:io documentation statement #6103

Open
1 task
alestiago opened this issue Sep 23, 2024 · 0 comments
Open
1 task

Incorrect dart:io documentation statement #6103

alestiago opened this issue Sep 23, 2024 · 0 comments
Labels
from.page-issue Reported in a reader-filed concern

Comments

@alestiago
Copy link

alestiago commented Sep 23, 2024

Page URL

https://dart.dev/libraries/dart-io

Page source

https://github.com/dart-lang/site-www/blob/main/src/content/libraries/dart-io.md

Describe the problem

Currently the dart:io documentation states:

"Only non-web Flutter apps, command-line scripts, and servers can import and use dart:io, not web apps"

However, I believe this is not entirely true, consider the following reproductive steps:

Importing and using dart:io in a Flutter web applcation

  1. Create a Flutter web application:
flutter create web_app --platforms web
  1. Add an import to dart:io at the start of the main.dart file at the start of the file:
import 'dart:io';
  1. Replace the title the "MyHomePage" in the `main.dart file:
home: MyHomePage(title: HttpDate.format(DateTime.now())),

Note that HttpDate is coming from dart:io and helps convert a DateTime string according to RFC 1123.

  1. Run the flutter application (from web_app):
flutter run -d chrome

It succeeds, proving the documentation statement to be incorrect.

  1. Build the flutter application (from web_app):
flutter build web

It succeeds, proving the documentation statement to be incorrect.

Expected fix

The notice is updated to be more accurate and outlines what specific parts of dart:io are not Web compatible.

Additional context

  • I'm personally not able to enumerate all the parts of dart:io that are not Web compatible. If those are provided I wouldn't mind updating the documentation.

  • At least, the documentation does end with a recommendation to use package:http that will cater for some cases, but that's not a justification to provide incorrect statements highlighted as important.

You should avoid directly using dart:io to make HTTP requests. The HttpClient class in dart:io is platform-dependent and tied to a single implementation. Instead, use a higher-level library like package:http.

I would like to fix this problem.

  • I will try and fix this problem on dart.dev.
@alestiago alestiago added the from.page-issue Reported in a reader-filed concern label Sep 23, 2024
@alestiago alestiago changed the title Invalid dart:io statement Incorrect dart:io documentation statement Sep 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
from.page-issue Reported in a reader-filed concern
Projects
None yet
Development

No branches or pull requests

1 participant