如何在 Flutter 中添加来自 GitHub 的包? [英] How to add a package from GitHub in Flutter?

查看:17
本文介绍了如何在 Flutter 中添加来自 GitHub 的包?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用一个包的最新源代码,而最新源代码尚未发布.我应该在 pubspec.yaml 中写入什么来获取 Github 中的包?

I need to use the latest source code of a package and the latest source hasn't been published yet. What should I write into pubspec.yaml to get a package in Github?

下面的代码不起作用.它不下载包,我无法将它导入到我的源代码中

The code below doesn't work. It doesn't download the package and I can't import it into my source code

dependencies:
  flutter:
    sdk: flutter

  carousel_pro:
    git:
      url: https://github.com/jlouage/flutter-carousel-pro.git

推荐答案

pubspec.yaml 示例


与特定分支的依赖关系:

dependencies:
  flutter:
    sdk: flutter

  carousel_pro:
    git:
      url: git://github.com/jlouage/flutter-carousel-pro.git
      ref: main # branch name


与特定提交的依赖关系:

dependencies:
  flutter:
    sdk: flutter

  carousel_pro:
    git:
      url: git://github.com/jlouage/flutter-carousel-pro.git
      ref: ea12e41 # commit hash

导入包的文件示例:

import 'package:carousel_pro/src/carousel_pro_widgets.dart';
import 'package:flutter/material.dart';

class NewsCarousel extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return SizedBox(
      height: 200.0,
      child: WidgetCarousel(
        autoplay: false,
        pages: [],
      ),
    );
  }
}

注意:如果您的 IDE 没有看到该软件包,请尝试重新启动它.

这篇关于如何在 Flutter 中添加来自 GitHub 的包?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆