Flutter:填坑常见错误 package:http/http.dart

import 'package:http/http.dart' as http;

 void main() {
  var url = 'http://httpbin.org/';
  http.get(url).then((response) {
    print("Response status: ${response.statusCode}");
    print("Response body: ${response.body}");
  });
}

错误提示:

Your application could not be compiled, because its dependencies could not be established.

The following Dart file:

/Users/mac/APP/http_test/lib/main.dart

...refers, in an import, to the following library:

package:http/http.dart

That library is in a package that is not known. Maybe you forgot to mention it in your pubspec.yaml file?

原因:

需要在项目根目录下的文件pubspec.yaml中注册依赖:

dependencies:
  http: ^0.11.0      // --加入这行 
  flutter:
    sdk: flutter

 

Test failed. See exception logs above. The test description was: Counter increments smoke test ══╡ EXCEPTION CAUGHT BY FLUTTER TEST FRAMEWORK ╞════════════════════════════════════════════════════ The following TestFailure was thrown running a test (but after the test had completed): Expected: exactly one matching candidate Actual: _TextWidgetFinder:<Found 0 widgets with text "0": []> Which: means none were found but one was expected When the exception was thrown, this was the stack: #0 fail (package:matcher/src/expect/expect.dart:149:31) #1 _expect (package:matcher/src/expect/expect.dart:144:3) #2 expect (package:matcher/src/expect/expect.dart:56:3) #3 expect (package:flutter_test/src/widget_tester.dart:474:18) #4 main.<anonymous closure> (file:///Users/eirikr/Documents/CODE/StoryBox/MeowShortIAA/Flutter%20App/MeowShort/test/widget_test.dart:19:5) <asynchronous suspension> #5 testWidgets.<anonymous closure>.<anonymous closure> (package:flutter_test/src/widget_tester.dart:193:15) <asynchronous suspension> #6 TestWidgetsFlutterBinding._runTestBody (package:flutter_test/src/binding.dart:1064:5) <asynchronous suspension> <asynchronous suspension> (elided one frame from package:stack_trace) ════════════════════════════════════════════════════════════════════════════════════════════════════ Test failed. See exception logs above. The test description was: Counter increments smoke test Test failed. See exception logs above. The test description was: Counter increments smoke test
04-01
分析一下yaml文件格式问题:name: tpub_web description: tpub web # 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 is used as CFBundleVersion. # Read more about iOS versioning at # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html # In Windows, build-name is used as the major, minor, and patch parts # of the product and file versions while build-number is used as the build suffix. version: 1.0.0+1 environment: sdk: '>=2.19.6 <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: flutter: sdk: flutter flutter_svg: 1.1.6 trouter: git: url: https://git.woa.com/flutter_components/TRouterGroup/TRouter.git path: trouter ref: master3+ dependency_overrides: trouter_platform_interface: git: url: https://git.woa.com/flutter_components/TRouterGroup/TRouter.git path: trouter_platform_interface ref: master3+ trouter_web: git: url: https://git.woa.com/flutter_components/TRouterGroup/TRouter.git path: trouter_web ref: master3+ # The following adds the Cupertino Icons font to your application. # Use with the CupertinoIcons class for iOS style icons. cupertino_icons: ^1.0.2 dev_dependencies: flutter_test: sdk: flutter # 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: ^2.0.0 # 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 packages. 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 assets: - images/ # To add assets to your application, add an assets section, like this: # assets: # - 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: Schyler # fonts: # - asset: fonts/Schyler-Regular.ttf # - asset: fonts/Schyler-Italic.ttf # style: italic # - family: Trajan Pro # fonts: # - asset: fonts/TrajanPro.ttf # - asset: fonts/TrajanPro_Bold.ttf # weight: 700 # # For details regarding fonts from package dependencies, # see https://flutter.dev/custom-fonts/#from-packages
最新发布
06-27
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值