build method

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

Implementation

@override
Widget build(BuildContext context, SwiperPluginConfig config) {
  final themeData = Theme.of(context);
  final activeColor = this.activeColor ?? themeData.primaryColor;
  final color = this.color ?? themeData.scaffoldBackgroundColor;

  final list = <Widget>[];

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

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

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