0

I'm creating a full-text page using the API. That API body contains some data. I want to display that data without html tags.

For this, I'm trying to use import'package:flutter_html/flutter_html.dart';. Added the dependency but when I run the pub get I get the below error.

Error:

flutter pub get Running "flutter pub get" in toyzania_app...
Because flutter_html >=2.0.0-nullsafety.1 <3.0.0-alpha.1 depends on flutter_svg >=0.22.0 <1.0.0 and countries_flag >=1.0.0 depends on flutter_svg ^2.0.4, flutter_html >=2.0.0-nullsafety.1 <3.0.0-alpha.1 is incompatible with countries_flag >=1.0.0. So, because toyzania_app depends on both countries_flag ^1.0.0 and flutter_html ^2.2.1, version solving failed. pub get failed (1; So, because toyzania_app depends on both countries_flag ^1.0.0 and flutter_html ^2.2.1, version solving failed.) exit code 1

Pubspec file:

  cached_network_image: ^3.2.3
  carousel_slider: ^4.2.1
  country_flags: ^1.0.0
  cupertino_icons: ^1.0.2
  video_player: ^2.5.1
  flutter_html: ^2.2.1

How to solve this?

1
  • Change flutter_html: ^2.2.1 to flutter_html: . This way flutter will automatically pick the correct and compatible version of library for you. You can also update the other libraries to the latest version and see if that fixes your issue. Commented May 11, 2023 at 14:46

1 Answer 1

0

Use html: ^0.15.0 and try like this

                       Html(
                              data: model.items?.text, // your html content
                              onLinkTap: (url, _, __, ___) {
                                if (url!.contains('https')) {
                                  launchUrl(Uri.parse(url));
                                } else {
                                  launchUrl(Uri.parse(
                                      staticPagesImageUrlGenerator(url)));
                                }
                              }),

onLinkTap is optional

Sign up to request clarification or add additional context in comments.

5 Comments

Thanks for your reply! I want to display the data of below API productController.privacypolicy.value.data!.shop!.privacyPolicy!.body.toString(), How to show this?
add this in data field
If I use ''Html(data: productController.privacypolicy.value.data!.shop!.privacyPolicy!.body.toString()), I'm gettting below error. The method 'HTML' isn't defined for the type '_PrivacypolicyState'. Try correcting the name to the name of an existing method, or defining a method named 'HTML'. I use it like this - Paddind(child: HTML()),
did you import the library properly? If error is saying "HTML" isn't defined means that either your pub get didn't work properly or you didn;t import the correct file for library.
html: ^0.15.0 add in pubspec.yaml and import import 'package:flutter_html/flutter_html.dart';

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.