How to add a package from github? (Flutter)

僤鯓⒐⒋嵵緔 提交于 2020-12-29 05:00:32

问题


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 bellow 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

回答1:


Example of pubsec.yaml

dependencies:
  flutter:
    sdk: flutter

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

Example of a file, importing the package

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: [],
      ),
    );
  }
}

Note: If your IDE doesn't see the package, try to restart it.



来源:https://stackoverflow.com/questions/54022704/how-to-add-a-package-from-github-flutter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!