build method

  1. @override
Widget build(
  1. BuildContext context,
  2. SwiperPluginConfig config
)
override

Implementation

@override
Widget build(BuildContext context, SwiperPluginConfig config) {
  int itemCount = config.itemCount;
  if (itemCount <= 1) {
    return Container();
  }

  ThemeData themeData = Theme.of(context);
  Color activeColor = this.activeColor ?? themeData.primaryColor;
  Color color = this.color ?? themeData.scaffoldBackgroundColor;

  List<Widget> list = [];

  int activeIndex = config.activeIndex;
  if (itemCount > 20) {
    debugPrint(
        "The itemCount is too big, we suggest use FractionPaginationBuilder instead of DotSwiperPaginationBuilder in this situation");
  }

  for (int i = 0; i < itemCount; ++i) {
    bool active = i == activeIndex;
    Size size = active ? activeSize : this.size;
    list.add(Container(
      width: size.width,
      height: size.height,
      key: Key("pagination_$i"),
      margin: EdgeInsets.all(space),
      decoration: BoxDecoration(
        borderRadius: BorderRadius.circular(1.5),
        color: active ? activeColor : color,
      ),
    ));
  }

  if (config.scrollDirection == Axis.vertical) {
    return Column(
      key: key,
      mainAxisSize: MainAxisSize.min,
      children: list,
    );
  } else {
    return Row(
      key: key,
      mainAxisSize: MainAxisSize.min,
      children: list,
    );
  }
}