build method

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

Implementation

@override
Widget build(BuildContext context, SwiperPluginConfig config) {
  if (config.itemCount > 20) {
    print(
        "The itemCount is too big, we suggest use FractionPaginationBuilder instead of DotSwiperPaginationBuilder in this sitituation");
  }
  Color? activeColor = this.activeColor;
  Color? color = this.color;

  if (activeColor == null || color == null) {
    ThemeData themeData = Theme.of(context);
    activeColor = this.activeColor ?? themeData.primaryColor;
    color = this.color ?? themeData.scaffoldBackgroundColor;
  }

  if (config.indicatorLayout != PageIndicatorLayout.NONE &&
      config.layout == SwiperLayout.DEFAULT) {
    return new PageIndicator(
      count: config.itemCount,
      controller: config.pageController,
      layout: config.indicatorLayout,
      size: size,
      activeColor: activeColor,
      color: color,
      space: space,
    );
  }

  List<Widget> list = [];

  int itemCount = config.itemCount;
  int activeIndex = config.activeIndex;

  for (int i = 0; i < itemCount; ++i) {
    bool active = i == activeIndex;
    list.add(Container(
      key: Key("pagination_$i"),
      margin: EdgeInsets.all(space),
      child: ClipOval(
        child: Container(
          color: active ? activeColor : color,
          width: active ? activeSize : size,
          height: active ? activeSize : size,
        ),
      ),
    ));
  }

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