-
-
Notifications
You must be signed in to change notification settings - Fork 74
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
[Bug report] Cannot compile ExtendedImage.file
on the web
#51
Comments
In real world the network path and file path are represented as |
@zmtzawqlp this is not a question this is a bug. Keep in mind that ...
if (kIsWeb) {
Image.network(pickedFile.path);
} else {
Image.file(File(pickedFile.path));
}
... This workaround doesn't work: Current workarounds include creating a conditional export for the |
fluttercandies/extended_image#531 do not import 'dart:io' directly. |
This is called workaround rather than fix fixing the bug. If you want to maintain the mock File class for web, check out the #50 pull request's first commit. |
37bbeb1 plz check this import 'package:extended_image/extended_image.dart';
import 'package:extended_image_library/extended_image_library.dart' show File;
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
// This is the theme of your application.
//
// Try running your application with "flutter run". You'll see the
// application has a blue toolbar. Then, without quitting the app, try
// changing the primarySwatch below to Colors.green and then invoke
// "hot reload" (press "r" in the console where you ran "flutter run",
// or simply save your changes to "hot reload" in a Flutter IDE).
// Notice that the counter didn't reset back to zero; the application
// is not restarted.
primarySwatch: Colors.blue,
),
home: const MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key, required this.title});
// This widget is the home page of your application. It is stateful, meaning
// that it has a State object (defined below) that contains fields that affect
// how it looks.
// This class is the configuration for the state. It holds the values (in this
// case the title) provided by the parent (in this case the App widget) and
// used by the build method of the State. Fields in a Widget subclass are
// always marked "final".
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;
void _incrementCounter() {
setState(() {
// This call to setState tells the Flutter framework that something has
// changed in this State, which causes it to rerun the build method below
// so that the display can reflect the updated values. If we changed
// _counter without calling setState(), then the build method would not be
// called again, and so nothing would appear to happen.
_counter++;
});
}
@override
Widget build(BuildContext context) {
// This method is rerun every time setState is called, for instance as done
// by the _incrementCounter method above.
//
// The Flutter framework has been optimized to make rerunning build methods
// fast, so that you can just rebuild anything that needs updating rather
// than having to individually change instances of widgets.
return Scaffold(
appBar: AppBar(
// Here we take the value from the MyHomePage object that was created by
// the App.build method, and use it to set our appbar title.
title: Text(widget.title),
),
body: Center(
// Center is a layout widget. It takes a single child and positions it
// in the middle of the parent.
child: kIsWeb
? ExtendedImage.network(
'https://t7.baidu.com/it/u=1595072465,3644073269&fm=193&f=GIF')
: ExtendedImage.file(File('')),
),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: const Icon(Icons.add),
), // This trailing comma makes auto-formatting nicer for build methods.
);
}
} |
@zmtzawqlp thank you very much it solves the problem. (I'm on phone but that changes seems fine) One note: I still need to import import 'package:extended_image_library/extended_image_library.dart' show File; I can live with that but the perfect solution would be if |
extended_image hide them, because other packages use extended_image and they are not use |
Mock |
mock it due to Web support flag. |
You won't lose the web support flag. You can only lose the web support flag if you depend on a plugin that doesn't handle the web. In the case of plugins in flutter:
plugin:
platforms:
android:
ios:
web: In the case of a package which is pure Dart code (like For instance, you can check out https://pub.dev/packages/image_size_getter package. It imports |
if your project use dart:io before, it will failed in web. This is only latest change of pub.dev and dart. This package is stable, there are not much reasons to change. |
When I tried to import
|
Version
7.0.2
Platforms
Web
Device Model
web compiler
flutter info
How to reproduce?
Try to compile the following code:
Log
When I want to try import
File
fromextended_image_library
the program won't compile too:Log
Logs
No response
Example code (optional)
No response
Contact
No response
The text was updated successfully, but these errors were encountered: