How to add a package from GitHub in Flutter?

 Dependency with the specific branch:

dependencies:
  flutter:
    sdk: flutter

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

Dependency with the specific commit:

dependencies:
  flutter:
    sdk: flutter

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

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.

Post a Comment

Previous Post Next Post

Subscribe Us


Get tutorials, Flutter news and other exclusive content delivered to your inbox. Join 1000+ growth-oriented Flutter developers subscribed to the newsletter

100% value, 0% spam. Unsubscribe anytime