daohoangson / flutter_widget_from_html

Flutter package to render html as widgets that supports hyperlink, image, audio, video, iframe and many other tags.
https://pub.dev/packages/flutter_widget_from_html
MIT License
640 stars 239 forks source link

Version solving failed with local flutter_widget_from_html_core #474

Closed sorrychan closed 3 years ago

sorrychan commented 3 years ago

Hi, I previously used 0.5.2+1 and customize buildImage widget in widget_factory.dart for implementing image zoom and save in device function.

When upgrading to version 0.6.0, I found that the part was moved to flutter_widget_html_core and tried to modify the package by moving it to the build folder.

However, adding it in pubspec.yaml told me the version solving failed with fwfh_url_launcher.

The core package is in 'flutter_widget_from_html' folder and it also located in app folder. Did I miss something?

image

error message : [flutter_widget_from_html-0.6.0-rc.2021031201] flutter pub get Running "flutter pub get" in flutter_widget_from_html-0.6.0-rc.2021031201...
Because fwfh_url_launcher 0.6.0-rc.2021022601 depends on flutter_widget_from_html_core ^0.6.0 and no versions of fwfh_url_launcher match >=0.6.0-0 <0.6.0-rc.2021022601 or >0.6.0-rc.2021022601 <0.7.0, fwfh_url_launcher ^0.6.0-rc.2021022601 requires flutter_widget_from_html_core from hosted.

So, because flutter_widget_from_html depends on both flutter_widget_from_html_core from path and fwfh_url_launcher ^0.6.0-rc.2021022601, version solving failed. pub get failed (1; So, because flutter_widget_from_html depends on both flutter_widget_from_html_core from path and fwfh_url_launcher ^0.6.0-rc.2021022601, version solving failed.) exit code 1

flutter doctor -v : [√] Flutter (Channel stable, 2.0.3, on Microsoft Windows [Version 10.0.19042.867], locale ko-KR) • Flutter version 2.0.3 at C:\src\flutter • Framework revision 4d7946a68d (10 days ago), 2021-03-18 17:24:33 -0700 • Engine revision 3459eb2436 • Dart version 2.12.2

[√] Android toolchain - develop for Android devices (Android SDK version 30.0.2) • Android SDK at C:\Users\csk\AppData\Local\Android\sdk • Platform android-30, build-tools 30.0.2 • Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
• Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01) • All Android licenses accepted.

[√] Chrome - develop for the web • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe

[√] Android Studio (version 4.0) • Android Studio at C:\Program Files\Android\Android Studio • Flutter plugin version 49.0.2 • Dart plugin version 193.7547 • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)

[√] VS Code (version 1.54.3) • VS Code at C:\Users\csk\AppData\Local\Programs\Microsoft VS Code • Flutter extension version 3.20.0

[√] Connected device (3 available) • LM G710N (mobile) • LMG710N4fcfcdd2 • android-arm64 • Android 10 (API 29) • Chrome (web) • chrome • web-javascript • Google Chrome 89.0.4389.90 • Edge (web) • edge • web-javascript • Microsoft Edge 89.0.774.63

• No issues found!

daohoangson commented 3 years ago

You probably need to use normal version constraints in dependencies and move the path constraint into dependency_overrides to avoid this kind of pub get error.

By the way, what are you trying to do that need to fork the package this way? It is fine by all mean but I have designed quite a few integration points so app developer should be able to change thing easily. Without this sort of complexity.

sorrychan commented 3 years ago

Thank you for fast response :)

What I trying to do is make image save and zoom function inside of html content with using photo_view and dio. I previously implemented it with wrapping image builder by gesture detector and create new page with image save function when tapping image in html content.

Is there any other easier way to implement that?

This is the way I used in 0.5.2+1 version.

 @override
  Widget buildImage(BuildMetadata meta, Object provider, ImageMetadata image) {
    var built = super.buildImage(meta, provider, image);

    if (provider is ImageProvider) {
      final heroTag = image.sources.first.url;

      return Builder(
        builder: (context) => GestureDetector(
          child: Container(
            padding: EdgeInsets.only(right: 32),
            child: built,
          ),
          onTap: () => Navigator.of(context).push(MaterialPageRoute(
              builder: (_) => Scaffold(
                    appBar: AppBar(
                      backgroundColor: Colors.black,
                      leading: Builder(
                        builder: (context) => IconButton(
                          icon: ImageIcon(
                            AssetImage('assets/images/icon_arrowLeft.png'),
                            color: Colors.white,
                            size: 16,
                          ),
                          color: Colors.white,
                          onPressed: () => Navigator.pop(context),
                        ),
                      ),
                      actions: <Widget>[
                        TextButton(
                          onPressed: () async {
                            await _requestPermission();
                            try {
                              var img = image.sources.last.url;
                              var appDocDir =
                                  await getExternalStorageDirectory();
                              var savePath = appDocDir.path + img;
                              var fileUrl = img;
                              await Dio().download(fileUrl, savePath);
                              final result =
                                  await ImageGallerySaver.saveFile(savePath);
                              if (result == null) {
                                return;
                              } else {
                                await Fluttertoast.showToast(
                                    msg: 'save complete',
                                    toastLength: Toast.LENGTH_SHORT,
                                    gravity: ToastGravity.CENTER,
                              }
                            } on PlatformException catch (error) {
                              print(error);
                            }
                          },
                          child: Text(
                            'Save',
                            style: TextStyle(
                                color: Colors.white),
                          ),
                        ),
                      ],
                    ),
                    body: Container(
                      child: PhotoView(
                        heroAttributes: PhotoViewHeroAttributes(tag: heroTag),
                        imageProvider: provider,
                      ),
                    ),
                  ))),
        ),
      );
    }
sorrychan commented 3 years ago

Oh, I can make it inside of onTapImage in HtmlWidget. I was making it difficult and complicated, leaving an easy way to do it. I'm sorry I asked you something weird.

Anyway, the problem is solved, and thank you for making a good package.

daohoangson commented 3 years ago

Yes, onTapImage is a rather new addition which should work for your use case 👍 Glad to be of help.