请帮助我解决我在 Flutter 中"The argument type 'String' can't be assigned to the parameter type 'Uri'"的错误



我需要帮助解决这个错误。所以我在youtube上看了这个教程,时间是2:40到8:01。我得到的错误是这个

The argument type 'String' can't be assigned to the parameter type 'Uri'.dart(argument_type_not_assignable)

这是我的代码(代码与教程相同,只是链接不同(

import 'dart:convert';
import 'package:xml2json/xml2json.dart';
import 'package:http/http.dart' as http;
Future<List> rssToJson(String category,
{String baseUrl = 'https://www.cnnindonesia.com/nasional/rss'}) async {
var client = http.Client();
final myTranformer = Xml2Json();
return await client.get(baseUrl + category + '/rssfeed.xml').then((Response) {
return Response.body;
}).then((bodyString) {
myTranformer.parse(bodyString);
var json = myTranformer.toGData();
return jsonDecode(json)['rss']['channel']['item'];
});
}

代码上有一条红色下划线

return await client.get(baseUrl + category + '/rssfeed.xml').then((Response)

这是我的pubspec.yaml

name: lah
description: A new Flutter project.
# The following line prevents the package from being accidentally published to
# pub.dev using `flutter pub publish`. This is preferred for private packages.
publish_to: 'none' # Remove this line if you wish to publish to pub.dev
# The following defines the version and build number for your application.
# A version number is three numbers separated by dots, like 1.2.43
# followed by an optional build number separated by a +.
# Both the version and the builder number may be overridden in flutter
# build by specifying --build-name and --build-number, respectively.
# In Android, build-name is used as versionName while build-number used as versionCode.
# Read more about Android versioning at https://developer.android.com/studio/publish/versioning
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 1.0.0+1
environment:
sdk: ">=2.7.0 <3.0.0"
# Dependencies specify other packages that your package needs in order to work.
# To automatically upgrade your package dependencies to the latest versions
# consider running `flutter pub upgrade --major-versions`. Alternatively,
# dependencies can be manually updated by changing the version numbers below to
# the latest version available on pub.dev. To see which dependencies have newer
# versions available, run `flutter pub outdated`.
dependencies:
http: ^0.13.4
font_awesome_flutter: ^9.2.0
bubble_bottom_bar: ^2.0.0
cupertino_icons: ^1.0.2
flutter_svg: ^1.0.3
xml2json: ^5.3.2
flutter:
SDK: flutter
dev_dependencies:
# The "flutter_lints" package below contains a set of recommended lints to
# encourage good coding practices. The lint set provided by the package is
# activated in the `analysis_options.yaml` file located at the root of your
# package. See that file for information about deactivating specific lint
# rules and activating additional ones.
flutter_lints: ^1.0.0
flutter_test:
sdk: flutter
# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec
# The following section is specific to Flutter.
flutter:
# The following line ensures that the Material Icons font is
# included with your application, so that you can use the icons in
# the material Icons class.
uses-material-design: true
# To add assets to your application, add an assets section, like this:
assets:
- assets/icons/
#   - images/a_dot_burr.jpeg
#   - images/a_dot_ham.jpeg
# An image asset can refer to one or more resolution-specific "variants", see
# https://flutter.dev/assets-and-images/#resolution-aware.
# For details regarding adding assets from package dependencies, see
# https://flutter.dev/assets-and-images/#from-packages
# To add custom fonts to your application, add a fonts section here,
# in this "flutter" section. Each entry in this list should have a
# "family" key with the font family name, and a "fonts" key with a
# list giving the asset and other descriptors for the font. For
# example:
fonts:
- family: Times
fonts:
- asset: assets/fonts/times_news_roman/Times New Roman 400.ttf
weight: 400
- asset: assets/fonts/times_news_roman/Times New Roman Gras 700.ttf
weight: 700
- family: Avenir
fonts:
- asset: assets/fonts/avenir/AvenirNextLTPro-Regular.otf
weight: 400
- asset: assets/fonts/avenir/AvenirNextLTPro-Demi.otf
weight: 500
- asset: assets/fonts/avenir/AvenirNextLTPro-Demi.otf
weight: 600
- asset: assets/fonts/avenir/avenir-next-lt-pro-bold.otf
weight: 700
- family: League
fonts:
- asset: assets/fonts/league_spartan/LeagueSpartan-Bold.otf
#
# For details regarding fonts from package dependencies,
# see https://flutter.dev/custom-fonts/#from-packages

目前,我使用的是Flutter SDK的新版本,2.10.1版本。请帮帮我。我需要尽快得到解决方案。谢谢

编辑:这是我的github链接,如果你有任何解决方案,为什么新闻没有出现。请告诉我

client.get((方法需要一个Uri,而您正在其中传递字符串

client.get(Uri.parse(baseUrl + category + '/rssfeed.xml'))

相关内容

最新更新