【问题标题】:Custom package library needs a dependency from project where is imported on自定义包库需要依赖于导入的项目
【发布时间】:2020-05-15 23:24:48
【问题描述】:

我创建了一个自定义包库。该库在 pubspec.yaml 中定义了 http 包依赖项。

version: 0.0.1
author:
homepage:

environment:
  sdk: ">=2.1.0 <3.0.0"

dependencies:
  flutter:
    sdk: flutter

dev_dependencies:
  flutter_test:
    sdk: flutter

  http: ^0.12.0+4

我在另一个项目中导入了这个自定义库。当我运行这个项目时,显示这个与 http 包相关的错误:

Compiler message:
Error: Could not resolve the package 'http' in 'package:http/http.dart'.
Error: Could not resolve the package 'http_parser' in 'package:http_parser/http_parser.dart'.
../xxxxx/lib/src/network/base/http_request.dart:4:8: Error: Not found: 'package:http/http.dart'
import 'package:http/http.dart';

如果这个http包只在自定义库中使用,我不明白为什么需要在项目中导入这个包依赖。

在自定义库结构和主 dart 文件下方找到。

提前谢谢你。

【问题讨论】:

  • 将http依赖添加到dependencies:而不是dev_dependencies:
  • 是的!这就是解决方案。谢谢老哥!!!

标签: flutter flutter-dependencies


【解决方案1】:

正如@Eugene 所说,解决方案是将http 依赖项移至dependencies: 部分而不是dev_dependencies: 部分

非常感谢@尤金

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-04-05
    • 2020-03-15
    • 1970-01-01
    • 2013-08-17
    • 1970-01-01
    • 2020-03-09
    • 1970-01-01
    • 2011-10-12
    相关资源
    最近更新 更多