首页 > 解决方案 > 如何在 Flutter 项目中添加自定义库?

问题描述

我想创建一个自定义库并在 Flutter 项目中使用它。

我在项目中创建了一个自定义库:

演示

但我无法发布它。(错误)

Because write_library_external depends on lib_math from path which doesn't exist (could not find package lib_math at "..\lib_math"), version solving failed. pub get failed (66; Because write_library_external depends on lib_math from path which doesn't exist (could not find package lib_math at "..\lib_math"), version solving failed.)

这是我的pubspec.yaml

version: 1.0.0+1

environment:
  sdk: ">=2.1.0 <3.0.0"

dependencies:
  flutter:
    sdk: flutter
  lib_math:
    path: /lib_math

  # The following adds the Cupertino Icons font to your application.
  # Use with the CupertinoIcons class for iOS style icons.
  cupertino_icons: ^0.1.2

dev_dependencies:
  flutter_test:
    sdk: flutter

请帮我!谢谢!

标签: flutter

解决方案


看起来您添加了错误的库path

对于您的项目,您应该尝试在以下位置更改文件pubspec.yaml

dependencies:
  lib_math:
    path: ../write_library_external/library/lib_math

推荐阅读