패키지, 저장소 및 앱 카테고리 검색

card_slider 표지
패키지 상세v1.0.6

card_slider

드래그 가능한 플러터 이미지 캐러셀 슬라이더, 스와이프 또는 드래그하여 슬라이드를 변경하세요!

AndroidiOSWebmacOSWindowsLinux
30일 다운로드
243
좋아요
37
Pub 점수
140

패키지 설치

flutter pub add card_slider

패키지 개요

공개 정보를 바탕으로 생성한 선택 가이드입니다.

Card Slider는 사용자가 카드를 스와이프하거나 드래그하여 넘길 수 있는 드래그 가능한 이미지 캐러셀을 제공하는 Flutter 패키지입니다. 시각적으로 매력적인 방식으로 이미지, 제품 또는 콘텐츠를 전시하는 데 이상적입니다. 부드러운 전환과 여러 플랫폼에서 직관적인 제스처를 지원합니다. 성능과 사용 편의성을 고려해 설계되었으며, 인터랙티브한 카드 기반 탐색이 필요한 앱에 원활하게 통합됩니다. 갤러리, 제품 전시, 온보딩 화면에 적합합니다.

사용 사례

  • 이미지 갤러리
  • 제품 쇼케이스
  • 온보딩 화면
  • 인터랙티브 슬라이더
  • 콘텐츠 캐러셀

주요 기능

  • 드래그 가능한 제스처 지원
  • 부드러운 슬라이드 전환
  • 크로스 플랫폼 호환성
  • 사용자 지정 가능한 카드 외관
  • 내장 스와이프 애니메이션

적합한 대상

  • 모바일 앱 개발자
  • UI/UX 디자이너
  • 전자상거래 애플리케이션
  • 포트폴리오 웹사이트
  • 인터랙티브 프로토타입

고려 사항

  • 제스처 처리 설정이 필요합니다
  • 대규모 데이터 세트에 대한 최적화가 필요할 수 있습니다
  • 제한된 내장 스타일링 옵션
  • 이미지가 아닌 콘텐츠에는 적합하지 않습니다
  • 성능은 카드 수에 따라 달라집니다

원본 README

연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.

card_slider

A draggable Flutter image carousel slider on swipe or drag! Card slider for carousel images and widgets. This widget works on both Android & iOS.

Example Example App Closed Example App Open Example App Open


Installing

Add the following to your pubspec.yaml file:

dependencies:
  card_slider: ^1.0.5

Maintaining card_slider

Thank you everyone for the support surrounding this project! card_slider has grown far larger than I could have ever imagined, so parsing through all the feature requests and new issues has taken me more time than I'd like. If you're interested in helping maintain this project, please send me an email at asylzatwww@gmail.com. As a sidenote, I'll always try to make sure that this project is compatible with the latest version of Flutter.


Simple Usage

There are two ways which the CardSlider can easily be added to your project.

  1. Using the CardSlider slides as widgets.
  2. Using the CardSlider slides as images
  3. Using the CardSlider slides as widgets inside scrollable Column.

CardSlider slides as widgets

This method uses widgets as a slide cards. For example:

@override
Widget build(BuildContext context) {
  List<Color> valuesDataColors = [
    Colors.purple,
    Colors.yellow,
    Colors.green,
    Colors.red,
    Colors.grey,
    Colors.blue,
  ];

  List<Widget> valuesWidget = [];
  for (int i = 0; i < valuesDataColors.length; i++) {
    valuesWidget.add(Container(
        decoration: BoxDecoration(
          borderRadius: BorderRadius.circular(12.0),
          color: valuesDataColors[i],
        ),
        child: Align(
          alignment: Alignment.center,
          child: Text(
            i.toString(),
            style: const TextStyle(
              fontSize: 28,
            ),
          ),
        )));
  }

  return Scaffold(
      backgroundColor: const Color(0xFF1560BD),
      appBar: AppBar(
        backgroundColor: Colors.transparent,
        elevation: 0,
        title: const Text(
          "Cards",
          style: TextStyle(
              fontSize: 14, fontWeight: FontWeight.w600, color: Colors.white),
        ),
        centerTitle: true,
        leading: IconButton(
          icon: const Icon(
            Icons.arrow_back,
            color: Colors.white,
          ),
          tooltip: 'Back',
          onPressed: () => Navigator.of(context).pop(),
        ),
      ),
      body: CardSlider(
        cards: valuesWidget,
        bottomOffset: .0005,
        cardHeight: 0.75,
        itemDotOffset: 0.25,
      ));
}

CardSlider slides as images

This method uses images as a slide cards. For example:

  @override
Widget build(BuildContext context) {
  List<Widget> valuesWidget = [];

  List<String> valuesUrl = [
    'https://upload.wikimedia.org/wikipedia/commons/thumb/4/42/Shaqi_jrvej.jpg/1200px-Shaqi_jrvej.jpg',
    'https://img.freepik.com/free-photo/wide-angle-shot-single-tree-growing-clouded-sky-during-sunset-surrounded-by-grass_181624-22807.jpg',
    'https://www.eea.europa.eu/themes/biodiversity/state-of-nature-in-the-eu/state-of-nature-2020-subtopic/image_print'
  ];

  for (int i = 0; i < valuesUrl.length; i++) {
    valuesWidget.add(
      Image.network(valuesUrl[i]),
    );
  }

  return Scaffold(
    backgroundColor: Colors.white,
    appBar: AppBar(
      backgroundColor: Colors.transparent,
      elevation: 0,
      title: const Text(
        "Gallery",
        style: TextStyle(
            fontSize: 14,
            fontWeight: FontWeight.w600,
            color: Color(0xFF33a000)),
      ),
      centerTitle: true,
      leading: IconButton(
        icon: const Icon(
          Icons.arrow_back,
          color: Color(0xFF33a000),
        ),
        tooltip: 'Back',
        onPressed: () => Navigator.of(context).pop(),
      ),
    ),
    body: CardSlider(
      cards: valuesWidget,
      bottomOffset: .0008,
      itemDotWidth: 14,
      itemDotOffset: 0.15,
      itemDot: (itemDotWidth) {
        return Container(
            margin: const EdgeInsets.all(5),
            width: 8 + itemDotWidth,
            height: 8,
            decoration: BoxDecoration(
              borderRadius: BorderRadius.circular(10),
              color: const Color(0xFF33a000),
            ));
      },
    ),
  );
}

CardSlider slides as widgets inside scrollable Column widget

This method uses widget as a slide cards inside scrollable column, instead of using SingleChildScrollView use the code below which uses ListView, otherwise GestureDetector won't work. For example:

  bool _dragOverMap = false;
final GlobalKey _pointerKey = GlobalKey();

_checkDrag(Offset position, bool up) {
  if (!up) {
    // find your widget
    RenderBox box = _pointerKey.currentContext!.findRenderObject() as RenderBox;

    //get offset
    Offset boxOffset = box.localToGlobal(Offset.zero);

    // check if your pointerdown event is inside the widget (you could do the same for the width, in this case I just used the height)
    if (position.dy > boxOffset.dy &&
        position.dy < boxOffset.dy + box.size.height) {
      setState(() {
        _dragOverMap = true;
      });
    }
  } else {
    setState(() {
      _dragOverMap = false;
    });
  }
}

@override
Widget build(BuildContext context) {

  List<Color> valuesDataColors = [
    Colors.purple,
    Colors.yellow,
    Colors.green,
    Colors.red,
    Colors.grey,
    Colors.blue,
  ];

  List<Widget> valuesWidget = [];
  for (int i = 0; i < valuesDataColors.length; i++) {
    valuesWidget.add(Container(
        decoration: BoxDecoration(
          borderRadius: BorderRadius.circular(12.0),
          color: valuesDataColors[i],
        ),
        child: Align(
          alignment: Alignment.center,
          child: Text(
            i.toString(),
            style: const TextStyle(
              fontSize: 28,
            ),
          ),
        )));
  }

  return Scaffold(
    appBar: AppBar(
      title: const Text("Slide inside column widget"),
    ),
    body: Listener(
      onPointerUp: (ev) {
        _checkDrag(ev.position, true);
      },
      onPointerDown: (ev) {
        _checkDrag(ev.position, false);
      },
      child: ListView(
        // if dragging over your widget, disable scroll, otherwise allow scrolling
        physics:
        _dragOverMap ? const NeverScrollableScrollPhysics() : const ScrollPhysics(),
        children: [
          Column(
            children: [
              for (int i = 0; i < 3; i++)
                const ListTile(title: Text("Tile to scroll")),
              const Divider(),
            ],
          ),
          // Your widget that you want to prevent to scroll the Listview
          Container(
            color: Colors.amberAccent,
            key: _pointerKey, // key for finding the widget
            height: 350,
            width: double.infinity,
            child:
            CardSlider(
              cards: valuesWidget,
              bottomOffset: .0008,
              cardHeight: 0.75,
              containerHeight: MediaQuery.of(context).size.height - 100,
              itemDotOffset: 0.55,
            )
            ,
          ),
          Column(
            children: [
              for (int i = 0; i < 3; i++)
                const ListTile(title: Text("Tile to scroll")),
              const Divider(),
            ],
          ),
        ],
      ),
    ),
  );
}

Screenshots

On the image below is shown how to use parameters cardWidthOffset, cardHeightOffset, bottomOffset :

Panel Closed




Custom Usage

There are several options that allow for more control:

Properties Description
cards The List of Widgets for slider
slideChanged Optional Event fired when ever slide is changed, (sliderIndex){ } sliderIndex has a value of a current slide.
blurValue Optional blurValue used for blurring the slider
blurOnClick Optional blurOnClick is method which listens if users clicks over blurred slider to be able to remove blurry
sliderBackGroundWidget Optional widget which placed on the background of slider, can be placed logo or any other image or widget .
itemDotWidth Optional is a width of dots under slider showing current location.
bottomOffset Optional is a double value, the height of a bottom of previous slide
cardWidth Optional is a width of a slides
cardHeight Optional is a height of a slides
cardWidthOffset Optional is a width which is used for how far slide must go on in horizontal distance when swiping or dragging
cardHeightOffset Optional is a height which is used for how far slide must go on in vertical distance when swiping or dragging
itemDot Optional is a widget by which can be changed the dots of th slider position
containerWidth Optional is a width of main Container
containerHeight Optional is a height of main Container
containerColor Optional is a color of main Container
itemDotOffset Optional is a distance to position itemDot under slides


🔢 Get Current Slide Index

You can listen to slide changes and get the current slide index using the slideChanged callback.

This is useful when you need to:

Track user interactions

Sync the slider with external state

Show slide numbers (e.g. 2 / 5)

Trigger analytics or business logic

Example: Listening to Slide Changes
CardSlider(
  cards: valuesWidget,
  slideChanged: (index) {
    print("Current index of slide is");
    print(index.toString());
  },
  bottomOffset: .0003,
  cardHeight: 0.75,
  containerHeight: MediaQuery.of(context).size.height - 100,
  itemDotOffset: -0.05,
),
Callback Details

Parameter Type Description index int Zero-based index of the currently visible slide

ℹ️ The callback fires every time the active slide changes, whether by swipe or drag.

카테고리

소스 저장소

이 패키지를 사용하는 프로젝트

아직 데이터가 없습니다.