Closed dy0gu closed 9 months ago
I also run into this issue. As far as I can see, the files 'bar_chart_data.dart' and 'line_chart_data.dart' contain an import of dart.io.
They contain the following line:
final _isTest = Platform.environment.containsKey('FLUTTER_TEST');
This might be the reason why Web is not detected automatically as target platform.
There are two solutions:
1) Restructuring the code by moving
final _axisValues = LineChartHelper().calculateMaxAxisValues;
into the test classes.
However, the tests 'should paint horizontal lines' and 'bar chart should not paint vertical lines' call
barChartPainter.paint(mockBuildContext, mockCanvasWrapper, holder);
which prevents the manual initialization of the axisValues.
2) Recognize the test mode in a different way
Yes, seems like importing dart.io
will immediately block the Web from being detected as a supported platform.
This has already been noted and mentioned on #1565, as I suspected.
Either way, the purpose of this issue (and respective pull request) was more to discuss the choice of having manually defined supported platforms.
Take my case for example, I started working with fl_chart 0.66.0
.
Since that version already had the dart.io
import pub.dev is not showing Web as supported.
And when I tried using it on the web it did in fact throw an exception, like discussed on #1565.
The problem is, I thought this was intended behavior, having never used a version of it that worked on the web. Only after going on this repository and reading the issues did I learn it was in fact a "bug" introduced in the latest version, and that Web was supposed to work.
Setting the supported platforms manually would help let people know that not running on one of them is an issue to be investigated. This may not seem like a big deal because the platform that stopped working with the dart.io
change was the Web, which is relatively mainstream in flutter development, but if it happened on a platform like Linux it would take quite longer for an issue to possibly be opened until anyone noticed.
Thanks for your detailed explanation. I will merge the PR asap to fix this issue.
Fixed in 0.66.2
You guys discussed, found the solution, and created PR. I just merged and bumped the version up (almost nothing) This is the power of open-source. Thanks a lot!
Since fl_chart is fully functional on the web it should be shown as a supported platform. The Dart docs explain that the supported list is auto-detected and should be manually set in the
pubspec.yaml
if it is incorrect.It seems this was already previously discussed and fixed, in #780, but the issue has returned. Setting it manually would prevent the same from ever happening again.
The missing Web support label could turn away newcomers since there is not a lot of mention in any of the package pages about the platforms it works on.
It also made me personally have to double check if the package was actually supported on the Web, since I experienced the issue mentioned on #1565 and didn't know if it was intended behavior.
This would make it clear that all current platforms are supported and that failure to work in any of them is indeed a bug and not intended.