Coder Social home page Coder Social logo

theankurpanchani / card_swiper Goto Github PK

View Code? Open in Web Editor NEW

This project forked from best-flutter/flutter_swiper

146.0 2.0 98.0 6.34 MB

Swiper/Carousel for flutter, with multiple layouts, infinite loop. Compatible with Android & iOS.

License: MIT License

Objective-C 0.03% Dart 98.14% Shell 0.42% Kotlin 0.09% Swift 0.28% HTML 1.05%
flutter swiper carousel

card_swiper's Introduction

Logo

PRs Welcome pub package

card_swiper

Swiper/Carousel for flutter, with multiple layouts, infinite loop. Compatible with Android & iOS.

✨✨ New Features:Layout for pagination.

We are using this project flutter_page_indicator now .

✨✨ New Features:PageTransformer

Finally, we have PageTransformer like android, just set a transformer to Swiper, it returns a widget that has been transformed. For now, only support for layout DEFAULT. Thanks to @FlutterRocks ,you've done great job 👏.

We are using this project transformer_page_view now .

✨✨ New Features:Layout

See More

Showcases

Horizontal

Vertical

Custom Pagination

Custom Pagination

Phone

Example

See More

Changelogs

see:CHANGELOG.md

Getting Started

Installation

Add

card_swiper : ^3.0.0

to your pubspec.yaml, and run

flutter packages get

in your project's root directory.

OR

run

flutter pub add card_swiper

in your project's root directory.

Basic Usage

Create a new project with command

flutter create myapp

Edit lib/main.dart like this:

import 'package:flutter/material.dart';

import 'package:card_swiper/card_swiper.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);

  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
    body: Swiper(
        itemBuilder: (BuildContext context,int index){
          return Image.network("https://via.placeholder.com/350x150",fit: BoxFit.fill,);
        },
        itemCount: 3,
        pagination: SwiperPagination(),
        control: SwiperControl(),
      ),
    );
  }
}

Constructor

Basic

Parameter Default Description
scrollDirection Axis.horizontal If Axis.horizontal, the scroll view's children are arranged horizontally in a row instead of vertically in a column.
axisDirection AxisDirection.left If AxisDirection.right, the scroll view's children are arranged right side in a row instead of left.
Note: Currently supported for horizontal stack layout only
loop true Set to false to disable continuous loop mode.
index 0 Index number of initial slide.
autoplay false Set to true enable auto play mode.
onIndexChanged void onIndexChanged(int index) Called with the new index when the user swiped or autoplay
onTap void onTap(int index) Called when user tap ui.
duration 300.0 The milliscends of every transaction animation costs
pagination null set SwiperPagination() to show default pagination
control null set SwiperControl() to show default control buttons

Pagination

The pagination extends from SwiperPlugin,the SwiperPlugin provides extra ui for Swiper.Set SwiperPagination() to show default pagination.

Parameter Default Description
alignment Alignment.bottomCenter Change this value if you what to put pagination in other place
margin const EdgeInsets.all(10.0) The distance between inner side of the parent container.
builder SwiperPagination.dots There are three default styles SwiperPagination.dots, SwiperPagination.fraction and SwiperPagination.rect, these can be customized.

If you'd like to customize your own pagination, you can do like this:

Swiper(
    ...,
    pagination: SwiperCustomPagination(
        builder:(BuildContext context, SwiperPluginConfig config){
            return YourOwnPagination();
        }
    )
);
Implemented pagination
DotSwiperPaginationBuilder
Parameter Default Description Required
activeColor Theme.of(context).primaryColor Active bullet color false
color Theme.of(context).scaffoldBackgroundColor Bullet color false
activeSize 10.0 Active bullet size false
size 10.0 Bullet size false
space 3.0 Distance between bullets false
key - key false
FractionPaginationBuilder
Parameter Default Description Required
activeColor Theme.of(context).primaryColor Active font color false
color Theme.of(context).scaffoldBackgroundColor font color false
activeFontSize 35.0 Active font size false
fontSize 20.0 Font size false
key - key false
RectSwiperPaginationBuilder
Parameter Default Description Required
activeColor Theme.of(context).primaryColor Active bullet color false
color Theme.of(context).scaffoldBackgroundColor Bullet color false
activeSize 10.0 Active bullet size false
size 10.0 Bullet size false
space 3.0 Distance between bullets false
key - key false

Control buttons

The control also extends from SwiperPlugin,set SwiperControl() to show default control buttons.

Parameter Default Description
iconPrevious Icons.arrow_back_ios The icon data to display previous control button
iconNext Icons.arrow_forward_ios The icon data to display next.
color Theme.of(context).primaryColor Control button color
disableColor Theme.of(context).disabledColor Disabled control button color
size 30.0 Control button size
padding const EdgeInsets.all(5.0) Control button padding

Controller

The Controller is used to control the index of the Swiper, start or stop autoplay.You can create a controller by SwiperController() and save the instance by futher usage.

Method Description
void move(int index, {bool animation: true}) Move to the spicified index,with animation or not
void next({bool animation: true}) Move to next
void previous({bool animation: true}) Move to previous
void startAutoplay() Start autoplay
void stopAutoplay() Stop autoplay

Autoplay

Parameter Default Description
autoplayDelay 3000 Autoplay delay milliseconds.
autoplayDisableOnInteraction true If set true, autoplay is disabled when use swipes.

Build in layouts

Swiper(
  itemBuilder: (BuildContext context, int index) {
    return Image.network(
      "https://via.placeholder.com/288x188",
      fit: BoxFit.fill,
    );
  },
  itemCount: 10,
  viewportFraction: 0.8,
  scale: 0.9,
)

Swiper(
  itemBuilder: (BuildContext context, int index) {
    return Image.network(
      "https://via.placeholder.com/288x188",
      fit: BoxFit.fill,
    );
  },
  itemCount: 10,
  itemWidth: 300.0,
  layout: SwiperLayout.STACK,
)

Swiper(
    itemBuilder: (BuildContext context, int index) {
      return Image.network(
        "https://via.placeholder.com/288x188",
        fit: BoxFit.fill,
      );
    },
    itemCount: 10,
    itemWidth: 300.0,
    itemHeight: 400.0,
    layout: SwiperLayout.TINDER,
 )

Very easy to create you own custom animation:

Swiper(
  layout: SwiperLayout.CUSTOM,
  customLayoutOption: CustomLayoutOption(
    startIndex: -1,
    stateCount: 3
  )..addRotate([
    -45.0/180,
    0.0,
    45.0/180
  ])..addTranslate([
    Offset(-370.0, -40.0),
    Offset(0.0, 0.0),
    Offset(370.0, -40.0)
  ]),
  itemWidth: 300.0,
  itemHeight: 200.0,
  itemBuilder: (context, index) {
    return Container(
      color: Colors.grey,
      child: Center(
        child: Text("$index"),
      ),
    );
  },
  itemCount: 10,
)

The CustomLayoutOption is designed to describe animations. It is very easy to specify every state of items in Swiper.

CustomLayoutOption(
  // Which index is the first item of array below
  startIndex: -1,
  // array length
  stateCount: 3
)..addRotate([
  // rotation of every item
  -45.0/180,
  0.0,
  45.0/180
])..addTranslate([
  // offset of every item
  Offset(-370.0, -40.0),
  Offset(0.0, 0.0),
  Offset(370.0, -40.0)
]);

Codes

Example

ConstrainedBox(
  child: Swiper(
    outer:false,
    itemBuilder: (c, i) {
      return Wrap(
        runSpacing: 6.0,
        children: [0,1,2,3,4,5,6,7,8,9].map((i){
          return SizedBox(
            width: MediaQuery.of(context).size.width/5,
            child: Column(
              mainAxisSize: MainAxisSize.min,
              children: <Widget>[
                SizedBox(
                  child: Container(
                    child: Image.network("https://fuss10.elemecdn.com/c/db/d20d49e5029281b9b73db1c5ec6f9jpeg.jpeg%3FimageMogr/format/webp/thumbnail/!90x90r/gravity/Center/crop/90x90"),
                  ),
                  height: MediaQuery.of(context).size.width * 0.12,
                  width: MediaQuery.of(context).size.width * 0.12,
                ),
                Padding(padding: EdgeInsets.only(top:6.0),child: Text("$i"),)
              ],
            ),
          );
        }).toList(),
      );
    },
    pagination: SwiperPagination(
      margin: EdgeInsets.all(5.0)
    ),
    itemCount: 10,
  ),
    constraints:BoxConstraints.loose(Size(screenWidth, 170.0))
),

FAQs

How to remove default controlls?

  • Do not pass any value in control parameter of constructor

How to remove default pagination?

  • Do not pass any value in pagination parameter of constructor

You can find all custom options here:

https://github.com/TheAnkurPanchani/flutter_swiper/blob/master/example/lib/src/ExampleCustom.dart

card_swiper's People

Contributors

ahmednfwela avatar arkangel12 avatar danreynolds avatar dependabot[bot] avatar eternity1984 avatar gopalvirat avatar ichenlei avatar jja08111 avatar jogboms avatar jzoom avatar lazyfatcat avatar ldd-information avatar msidolphin avatar omd avatar pepsighan avatar samadipour avatar theankurpanchani avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

card_swiper's Issues

Cannot drag with mouse in flutter web

I develop flutter web app with using card_swiper package, but I cannot drag/swipe with mouse gesture. It works fine on mobile with tap gesture.

My swiper full code:

Swiper(
  itemBuilder: (context, index) {
    final banner = listCarousel[index];
    final isActive = _activeIndex == index;
    return Padding(
      padding: const EdgeInsets.symmetric(vertical: 20),
      child: AnimatedOpacity(
        opacity: isActive ? 1.0 : .8,
        duration: const Duration(milliseconds: 1000),
        child: Container(
          width: double.infinity,
          height: double.infinity,
          decoration: BoxDecoration(
            borderRadius: BorderRadius.circular(APP_UI_CARD_RADIUS),
            color: APP_UI_COLOR[400],
            boxShadow: [
              BoxShadow(
                color: Colors.grey[800]!.withOpacity(.7),
                blurRadius: 15.0,
                spreadRadius: -2.0,
                offset: const Offset(2.0, 2.0),
              ),
            ]
          ),
          clipBehavior: Clip.antiAlias,
          child: InkWell(
            onTap: () => h.viewMenu(product: banner),
            child: Stack(
              alignment: Alignment.bottomCenter,
              children: [
                SizedBox(width: double.infinity, height: double.infinity, child: MyCachedImage(banner.photo)),
                AnimatedOpacity(
                  opacity: isActive ? 1.0 : 0.0,
                  duration: const Duration(milliseconds: 1000),
                  curve: Curves.ease,
                  child: Container(
                    width: double.infinity,
                    decoration: BoxDecoration(
                      gradient: LinearGradient(
                        begin: Alignment.topCenter,
                        end: Alignment.bottomCenter,
                        colors: [
                          Colors.white.withOpacity(0),
                          Colors.white54,
                        ],
                      ),
                    ),
                    padding: const EdgeInsets.all(APP_UI_CARD_PADDING).copyWith(top: 50),
                    child: Column(
                      mainAxisSize: MainAxisSize.min,
                      children: [
                        Text(banner.name, textAlign: TextAlign.center, style: const TextStyle(
                          fontSize: 20,
                          fontWeight: FontWeight.w800,
                          color: Colors.black,
                          shadows: [
                            Shadow(blurRadius: 10.0, color: Colors.white),
                          ],
                        ),),
                        if (banner.bestComment != null) Padding(
                          padding: const EdgeInsets.only(top: 12.0),
                          child: Text.rich(TextSpan(
                            style: const TextStyle(
                              fontSize: 15,
                              fontWeight: FontWeight.w500,
                              color: APP_UI_TEXT_DEFAULT,
                              shadows: [
                                Shadow(blurRadius: 10.0, color: Colors.white),
                              ],
                            ),
                            children: [
                              TextSpan(text: '"${banner.bestComment}"', style: const TextStyle(fontWeight: FontWeight.w600),),
                              TextSpan(text: ' — ${banner.bestCommentAuthor}',),
                            ],
                          ), textAlign: TextAlign.center,),
                        ),
                      ],
                    ),
                  ),
                ),
              ],
            ),
          ),
        ).pulseIt(scaleEnd: 1.025, duration: 3000),
      ),
    );
  },
  onIndexChanged: (index) async {
    await Future.delayed(const Duration(milliseconds: 500));
    if (mounted) setState(() { _activeIndex = index; });
  },
  viewportFraction: .7,
  scale: .8,
  itemCount: listCarousel.length,
  autoplay: true,
  autoplayDelay: 10000,
  duration: 1000,
);

The app crashes sometimes after returning from disabled state on android

D/CompatibilityChangeReporter( 9639): Compat change id reported: 160794467; UID 10594; state: DISABLED

======== Exception caught by widgets library =======================================================
The following assertion was thrown building Swiper(dependencies: [_InheritedTheme, _LocalizationsScope-[GlobalKey#ccfa3]], state: _SwiperState#98d23):
ScrollController not attached to any scroll views.
'package:flutter/src/widgets/scroll_controller.dart':
Failed assertion: line 107 pos 12: '_positions.isNotEmpty'

The relevant error-causing widget was:
Swiper Swiper

I can't reproduce the exact problem, it mostly happens after receiving a notification and then opening the app

RenderBox was not laid out: RenderLimitedBox#3e2ab NEEDS-LAYOUT NEEDS-PAINT

Hi, I'm having a problem with render layout that I have been trying to understand and fix in any ways possible but it just dont work.

Swiper works correctly and widget in screen is shown correctly, but, I always get this error on terminal:
image

This is my code:

Container(
        width: MediaQuery.of(context).size.width * 0.85,
        height: MediaQuery.of(context).size.height,
        padding: const EdgeInsets.only(top: 25, left: 150, right: 150, bottom: 35),
        child: Column(
          mainAxisAlignment: MainAxisAlignment.start,
          crossAxisAlignment: CrossAxisAlignment.start,
          mainAxisSize: MainAxisSize.max,
          children: [
            _title(),
            const SizedBox(height: 16,),
            Container(
              decoration: BoxDecoration(
                border: Border.all(
                  color: Colors.red,
                  width: 1
                )
              ),
              height: MediaQuery.of(context).size.height * 0.05,
              width: double.infinity,
              margin: const EdgeInsets.only(bottom: 16),
              child: Center(child: Text("Search", style: Theme.of(context).textTheme.headline3)),
            ),
            Expanded(
              child: Swiper(
                controller: _controller,
                indicatorLayout: PageIndicatorLayout.SCALE,
                layout: SwiperLayout.STACK,
                itemWidth: MediaQuery.of(context).size.width  * 0.4,
                itemHeight: MediaQuery.of(context).size.height * 0.7,
                pagination: const SwiperPagination(),
                control: const SwiperControl(),
                viewportFraction: 0.8,
                fade: 0.01,
                scale: 0.6,
                itemCount: 3,
                itemBuilder: (ctx, i) {
                  return Container(
                  padding: const EdgeInsets.all(48),
                  decoration: BoxDecoration(
                    color: Theme.of(context).backgroundColor,
                    borderRadius: BorderRadius.circular(12),
                    boxShadow: const [
                      BoxShadow(
                        spreadRadius: 4,
                        blurRadius: 4,
                        color: Colors.black12
                      )
                    ]
                  ),
                );
                },
              )
            ),
          ],
        ),
      ),

I dont know if I'm missing something to try. But I hope you could help me.

Thanks!

Autoplay doesn't stop on user interaction in stacked swiper

Really love the package. Sadly, the autoplay feature seems to be buggy. Autoplay doesn't stop in Stacked Swiper or SwiperLayout.STACK even if autoplayDisableOnInteraction is set to true.
If a user touches, drags and holds the card, autoplay still takes over and animates to next page in Stacked Swiper or SwiperLayout.STACK.
How can this be fixed?

Execute the direction in which the controller.next() method moves

image

I'm using card_swiper like this. I manually scroll to the next slide and swipe left to right. I call controller.next() and the animation direction is right to left. I haven't found a way to set the animation direction yet. I look forward to your help. Thank you.

The SwiperController sending notification was: Instance of 'SwiperController'`

Am I missing any steps? Please help me

The following _CastError was thrown while dispatching notifications for SwiperController:
Null check operator used on a null value

When the exception was thrown, this was the stack: 
#0      ScrollPosition.viewportDimension (package:flutter/src/widgets/scroll_position.dart:175:53)
#1      _PagePosition.getPixelsFromPage (package:flutter/src/widgets/page_view.dart:396:19)
#2      PageController.animateToPage (package:flutter/src/widgets/page_view.dart:202:16)
#3      _TransformerPageViewState.onChangeNotifier (package:card_swiper/src/transformer_page_view/transformer_page_view.dart:580:14)
#4      ChangeNotifier.notifyListeners (package:flutter/src/foundation/change_notifier.dart:308:24)
#5      IndexController.next (package:card_swiper/src/transformer_page_view/index_controller.dart:110:5)
#6      _SwiperTimerMixin._onTimer (package:card_swiper/src/swiper.dart:391:17)
(elided 3 frames from class _RawReceivePortImpl and class _Timer)
The SwiperController sending notification was: Instance of 'SwiperController'

STACK Layout - list order inverted

Good morning,

I am having a problem using STACK Layout with a list: it seems that the order of the elemets is inverted during elements swiping.
Example (gif attached):

  1. The first element on the stack is the 2
  2. The user makes the swipe in order to get the element 1 (during the movement it is possible to see that under the element 2 there is the element 1)
  3. During the swipe animation, item 1 is actually displayed
  4. As soon as the animation is completed the element 1 is changed with the element 3

It seems that the animation swiping is the opposite of the list shifting order.

wrong swiping

Here's the code:

import 'package:card_swiper/card_swiper.dart';
import 'package:flutter/material.dart';


List prova = ["1", "2", "3", "4", "5", "6", "7", "8"];

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(title: 'Flutter Demo Home Page', key: ValueKey(1),),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({required Key key, required this.title}) : super(key: key);

  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: SizedBox(
          width: 200,
          height: 200,
          child: Swiper(
            itemBuilder: (BuildContext context, int index){
              final item = prova[index];
              return SizedBox(
                width: 150,
                height: 150,
                child: Container(
                  decoration: BoxDecoration(border: Border.all(color: Colors.black)),
                  child: Text(index.toString())));
            },
            index: 0,
            axisDirection: AxisDirection.right,
            scrollDirection: Axis.horizontal,
            loop: true,
            itemCount: prova.length,
            layout: SwiperLayout.STACK,
            itemHeight: 150,
            itemWidth: 150,
            pagination: SwiperPagination(),
            // control: SwiperControl(),
          ),
        ),
      ),
    );
  }
}

widget unmounted error with multiple swipers in listView

observed with card_swiper v1.0.4

running into an issue where I have a listView of swipers, they are appropriately unmounted as they go out of scrollview, however if I reverse scroll back (with a previous swiper coming back into view), I occasionally get the following error:

"This widget has been unmounted, so the State no longer has a context (and should be considered defunct)."

it looks like it is triggered when the TransformerPageView tries to get the renderObject from the context (below), but not sure why it's being called after it's unmounted? possibly a timing issue? open to any suggestions. -- thanks!

void _onGetSize(_) {
    Size? size;

    // if (context == null) {
    //   onGetSize(size);
    //   return;
    // }
    final renderObject = context.findRenderObject();
    if (renderObject != null) {
      final bounds = renderObject.paintBounds;
      size = bounds.size;
    }
    _calcCurrentPixels();
    onGetSize(size);
 }

update: I notice that there is no "if (mounted)" check before the context.findRenderObject() is called, and also am curious why the context == null check has been commented out?

SwiperPagination.rect Invalid, no UI to show

SwiperPagination.rect Invalid, no UI to show,Customization doesn't work either
Swiper( itemCount: 5, controller: model.swiperController, loop: false, itemBuilder: (context,index){ return OtherUtil.cacheImage( 'https://c-ssl.duitang.com/uploads/item/201808/30/20180830190828_hiios.thumb.1000_0.jpg', height: double.infinity, width: Get.width,); }, pagination: const SwiperPagination( alignment: Alignment.topCenter, builder: SwiperPagination.rect ) ),

123

dots
Screenshot_20220415-174050
rect
Screenshot_20220415-174100

no touchable when using CustomLayoutOption

hello itry to make my CustomLayoutOption on top of wiper but swiping the slide with touch fingers not working

my code is

` Swiper(itemCount: _sliddata.length,

     itemBuilder:  (context, index) {
       return imgbuildr(index);
     },

     scrollDirection: Axis.horizontal,

     loop: true,

     control: new SwiperControl(
         color: Colors.red
     ),


     pagination: new SwiperPagination(
         margin: new EdgeInsets.all(5.0),
         builder: new DotSwiperPaginationBuilder(
             color: Colors.grey, activeColor: Colors.red)

     ),


     viewportFraction: 0.1,

     scale: 2,
     itemHeight: MediaQuery.of(context).size.height * 0.3,
     itemWidth: MediaQuery.of(context).size.width * 0.85 ,
     autoplayDelay: 9250,
     duration: 622,

     layout:
     SwiperLayout.CUSTOM,
     customLayoutOption: new CustomLayoutOption(
       startIndex: -1,
       stateCount: 3,

     ).addOpacity([
       0.6,
       0.6,
       1.0


     ])


         .addRotate([

       0.03,
       0.03,
       0.0

     ])



         .addScale([
       0.8,
       0.8,
       0.96

     ],Alignment.center )

         .addTranslate([
       //offset(left,upp)
       new Offset(-100.0, 5.0),
       new Offset(100 , 5.0 ),
       new Offset(0.0, 0.0)
     ]),
   ) ,`

Crashes when window resized on web

════════ Exception caught by widgets library ═══════════════════════════════════
The following assertion was thrown building Expanded(flex: 1):
Assertion failed:
../…/widgets/scroll_controller.dart:107
_positions.isNotEmpty
"ScrollController not attached to any scroll views."

The relevant error-causing widget was
Swiper

SwiperLayout.CUSTOM layout is not working as expected

There are two problems while using SwiperLayout.CUSTOM (I am using card_swiper: ^2.0.1)

  1. While using Next and Previous buttons the indexes are correctly moving but the swipe animation is going in reverse way
  2. While using the swipe, the index is changing in reverse which is wrong too
04-20-31.mov

当自动轮播时,swiperController.index并不会随着改变

 onIndexChanged: (index) async {
            print('$index & ${_swiperController.index}');
          },

输出为:

I/flutter ( 8370): 1 & 0
I/flutter ( 8370): 2 & 0
I/flutter ( 8370): 0 & 0
I/flutter ( 8370): 1 & 0
I/flutter ( 8370): 2 & 0
I/flutter ( 8370): 0 & 0

这样导致我在监听轮播变化时,无法得知当前正在轮播哪张图
例如:

_swiperController.addListener(() {
      print(_swiperController.index);
//other code
    });

输出:

I/flutter ( 8370): 0
I/flutter ( 8370): 0
I/flutter ( 8370): 0
I/flutter ( 8370): 0
I/flutter ( 8370): 0

请问是否可以在自动轮播时使swiperController.index一起改变

Bug: The following IntegerDivisionByZeroException was thrown building AnimatedBuilder: IntegerDivisionByZeroException

Hello there this error happens when try to load network resources

More details here:

When the exception was thrown, this was the stack: 
#0      int.% (dart:core-patch/integers.dart:45:7)
#1      _CustomLayoutStateBase._buildAnimation (package:card_swiper/src/custom_layout.dart:98:29)
#2      AnimatedBuilder.build (package:flutter/src/widgets/transitions.dart:1519:19)
#3      _AnimatedState.build (package:flutter/src/widgets/transitions.dart:174:48)
#4      StatefulElement.build (package:flutter/src/widgets/framework.dart:4782:27)
#5      ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4665:15)
#6      StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:4840:11)
#7      Element.rebuild (package:flutter/src/widgets/framework.dart:4355:5)
#8      ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4643:5)
#9      StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4831:11)
#10     ComponentElement.mount (package:flutter/src/widgets/framework.dart:4638:5)
#11     Element.inflateWidget (package:flutter/src/widgets/framework.dart:3673:14)
#12     Element.updateChild (package:flutter/src/widgets/framework.dart:3422:20)
#13     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4690:16)
#14     StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:4840:11)
#15     Element.rebuild (package:flutter/src/widgets/framework.dart:4355:5)
#16     BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2620:33)
#17     WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:882:21)
#18     RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:319:5)
#19     SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1143:15)
#20     SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1080:9)
#21     SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:996:5)
#25     _invoke (dart:ui/hooks.dart:166:10)
#26     PlatformDispatcher._drawFrame (dart:ui/platform_dispatcher.dart:270:5)
#27     _drawFrame (dart:ui/hooks.dart:129:31)
(elided 3 frames from dart:async)

Custom Layout Options don't accept add rotate, add translate

Hello! Im facing the following problem.

This expression has a type of 'void' so its value can't be used.
Try checking to see if you're using the correct API; there might be a function or call that returns void you didn't expect. Also check type parameters and variables which might also be void.

Im using the latest version of flutter/Dart and Card_Swiper.
I just tried the example code:

  SizedBox(
              height: 500,
              width: double.infinity,
              child: Swiper(
                  layout: SwiperLayout.CUSTOM,
                  customLayoutOption: CustomLayoutOption(
                          startIndex: -1, stateCount: 3)
                      .addRotate([-45.0 / 180, 0.0, 45.0 / 180]).addTranslate([
                    Offset(-370.0, -40.0),
                    Offset(0.0, 0.0),
                    Offset(370.0, -40.0)
                  ]),
                  itemWidth: 300.0,
                  itemHeight: 200.0,
                  itemBuilder: (context, index) {
                    return Container(
                      color: Colors.grey,
                      child: Center(
                        child: Text("$index"),
                      ),
                    );
                  },
                  itemCount: 10)),

Houpelly someone can help me :)
Greetings

Duplicated element when swiper has just one element

This fork is a very good improvement over the initial package and we are so thankful about it.

We found a very problematic thing here:
We the swiper have just one element, it duplicates it to have the carousel effect. For animation purposes is good, but when it is media sources, it break exo_player a lot, at least that's our problem now.

You can see it in the photo:
Screen Shot 2021-12-18 at 17 52 41

This just only happen when loop is true.

It should not duplicate its child if this is just one.

Thank you.

Nested Swipers

I am trying to embed a Swiper inside another Swiper in a way that when the child Swiper reaches the last element I can carry on swiping in the parent Swiper. However once I get into the child swiper's end I can't go back to the parent.

The Issue could be represented in a pattern as follows

==---==-----=====

where = is an element of the parent swiper and - is an element of the child swiper.

loop is not working

loop paramter just ignored when autoPlay is true.
with loop false swiper should just play once.

PageIndicator

@TheAnkurPanchani Can I manage dots count and show fewer dots if I have more cards than dots?
For instance: cards 20, but show only 10 dots
If it's possible, could you please share example or implement it to this plugin to control dots count?

Unexpected null value

I'm using the card_swiper for the web. When I change the scrollbar to alwaysShow to true. I get the following error (but the page loads and the card_swiper is shown):

Unexpected null value.

When the exception was thrown, this was the stack:
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 251:49      throw_
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/operations.dart 528:63  nullCheck
packages/flutter/src/widgets/scroll_metrics.dart 150:49                                                                        get maxScrollExtent
packages/flutter/src/widgets/scrollbar.dart 1553:16                                                                            [_handleScrollNotification]
packages/flutter/src/widgets/notification_listener.dart 206:27                                                                 [_dispatch]
packages/flutter/src/widgets/notification_listener.dart 122:19                                                                 visitAncestor
packages/flutter/src/widgets/scroll_notification.dart 31:18                                                                    visitAncestor
packages/flutter/src/widgets/framework.dart 4133:39                                                                            visitAncestorElements
packages/flutter/src/widgets/notification_listener.dart 138:13                                                                 dispatch
packages/flutter/src/widgets/scroll_activity.dart 94:90                                                                        dispatchScrollUpdateNotification
packages/flutter/src/widgets/scroll_position.dart 899:5                                                                        didUpdateScrollPositionBy
packages/flutter/src/widgets/scrollbar.dart 1243:25                                                                            <fn>
packages/flutter/src/scheduler/binding.dart 1143:15                                                                            [_invokeFrameCallback]
packages/flutter/src/scheduler/binding.dart 1088:9                                                                             handleDrawFrame
packages/flutter/src/scheduler/binding.dart 863:7                                                                              <fn>
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/_internal/js_dev_runtime/private/isolate_helper.dart 48:19           internalCallback

I initialized the SwiperController (for card_swiper), and ScrollController (for ListView). And I made the following changes:

@override
  void initState() {
    super.initState();
    _scrollController = ScrollController(initialScrollOffset: 0.0);
    _swiperController = SwiperController();
    _swiperController.event = SwiperController.SWIPE;

    WidgetsBinding.instance!.addPostFrameCallback((_){
      if (_swiperController.hasListeners) {
        _swiperController.pos = _swiperController.event!.toDouble();
        // _swiperController.event = 0;
        _swiperController.index = 0;
        _swiperController.animation = false;
      }
    });
  }

The devtools didn't help to identify the null value in question.

How can I solve this?

Thanks in advance

Indicator do not change

PageIndicatorLayout is not changing from dot to warm or others

  child: Swiper(
        itemBuilder: (BuildContext context, int index) {
          return Container(
            height: 100,
            child: Material(
              elevation: 10,
              shadowColor: Colors.grey.shade600,
              color: bck_color_light,
              borderRadius: BorderRadius.circular(20.r),
              child: Container(),
            ),
          );
        },
        itemCount: 10,
        itemWidth: 300.0,
        itemHeight: 200,
        fade: 10,
        outer: true,
        onIndexChanged: (val) {

        },
        indicatorLayout: PageIndicatorLayout.WARM,
        physics: const BouncingScrollPhysics(),
        pagination: SwiperPagination(alignment: Alignment.bottomCenter,
          builder: DotSwiperPaginationBuilder(space: 8,
              size: 8,
              activeSize: 12,
              color: Colors.grey.shade600,
            activeColor: Colors.white,),),
      layout: SwiperLayout.STACK,
)

card_swiper EXCEPTION: _CastError was thrown while dispatching notifications for SwiperController

Case:

I am getting this error when my swiper scaffold is in app background.

[*] I am using smooth_page_indicator for showing custom dots pagination

Initially i load the main page (which has the swiper) based on conditions i move to some other page, in the background i am getting these errors/exceptions. Only when swiper is in background of flutter app i get this kind of exception.

Any idea to solve !!!

Error: Null check operator used on a null value

Exception Caught:

======== Exception caught by foundation library ====================================================
The following _CastError was thrown while dispatching notifications for SwiperController:
Null check operator used on a null value

When the exception was thrown, this was the stack: 
#0      ScrollPosition.viewportDimension (package:flutter/src/widgets/scroll_position.dart:175:53)
#1      _PagePosition.getPixelsFromPage (package:flutter/src/widgets/page_view.dart:396:19)
#2      PageController.animateToPage (package:flutter/src/widgets/page_view.dart:202:16)
#3      _TransformerPageViewState.onChangeNotifier (package:card_swiper/src/transformer_page_view/transformer_page_view.dart:576:14)
#4      ChangeNotifier.notifyListeners (package:flutter/src/foundation/change_notifier.dart:308:24)
#5      IndexController.next (package:card_swiper/src/transformer_page_view/index_controller.dart:110:5)
#6      _SwiperTimerMixin._onTimer (package:card_swiper/src/swiper.dart:388:17)
(elided 10 frames from class _RawReceivePortImpl, class _Timer, and dart:async)
The SwiperController sending notification was: Instance of 'SwiperController'
====================================================================================================

Change the focused item position

Is it possible to align the focused item to the left of the screen somehow? It is showed in the middle and when the item width is less than screen width a lot of space on the left appears.

Can I deactivate manual Swipe?

Hi, I would like to control the swipe only by functions. So the user should not be able to swipe manually. Is this possible?
Thanks!

How can I move to real index

when use controller.move(index),index is not real index,so card move just between 0~list.count.I want get card real index.

Card in SingleChildScrollView

I have a SingleChildScrollView widget. I'd like to use card_swiper in it, but i don't know height of my future widget, because it'll be a list from some site.
Scaffold --> SingleChildScrollView --> Column
then if i use any Swiper (from examples) without SizedBox and ConstrainedBox, it returns "Horizontal viewport was given unbounded height.".
If i add SizedBox or ConstrainedBox from examples - works!
itemBuilder from Swiper looks like ListView.builder, which has shrinkWrap parametr. With this parametr (set to "true") everything works.
is there a similar setting in Swiper? Or a way to fix it

`

            return SingleChildScrollView(
                          physics: ScrollPhysics(),

          child: Column(
            children: <Widget>[
             
             // this works!
              ListView.builder(
                shrinkWrap: true,
                itemCount: 1000,
                itemBuilder: (context, index) {
                  return ListTile(
                    title: Row(
                      children: [
                        Text(index.toString()),
                      ],
                    ),
                  );
                },
              ),
			  
			  
			  // this works too
              ConstrainedBox(
				constraints:BoxConstraints.loose(Size(screenWidth, 170.0))
                child:  Swiper(
                  itemBuilder: (context, index) {
                    return    Container(width: 1000, height: 1000, color:Colors.red,child: Text(index.toString()),);
                  },
                  autoplay: true,
                  itemCount: 4,
                  pagination:
                  const SwiperPagination(),
                  control: const SwiperControl(),
                ),
              ),
			  
			// doesn't works((((  
			Swiper(
                  itemBuilder: (context, index) {
                    return    Container(width: 1000, height: 1000, color:Colors.red,child: Text(index.toString()),);
                  },
                  autoplay: true,
                  itemCount: 4,
                  pagination:
                  const SwiperPagination(),
                  control: const SwiperControl(),
                ),

            ],
          ),
        );`

Listen for swap

How can I know if the user swap to the right or to the left?
There is something like, onRightSwap callback?

Creating Custom Transformer

I would like to be able to create custom transformations like adding a parallax effect. Currently, it is not possible because the class "PageTransformer" is not exposed therefore one cannot extend nor implement the said class. It would be nice to have the option to create your custom transformations like the "ScaleAndFadeTransformer" class or via a builder i.e. PageTransformerBuilder(builder: (Widget child, TransformInfo info) { return ParrallaxContainer(...)

SwiperController.next() only works once when called manually

Hi there @TheAnkurPanchani ,

The SwiperController.next() only work once when it called from my custom button. I did try use the default SwiperControl() for the pagination, it seems the config.next() is working fine. I can't make my own custom SwiperControl() builder because the ui need to be separated from the carousel.

Any chance you know why this behaviour acting this way?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.