Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
392 views
in Technique[技术] by (71.8m points)

dart - How to add a package from GitHub in Flutter?

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
question from:https://stackoverflow.com/questions/54022704/how-to-add-a-package-from-github-in-flutter

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...