import 'package:flutter/material.dart';

class PageViewIndicator extends StatelessWidget {
  final bool isActive;
  final int length;
  final double currentPage;
  PageViewIndicator({
    @required this.isActive,
    @required this.length,
    @required this.currentPage,
  });

  @override
  Widget build(BuildContext context) {
    return _indicator(this.isActive);
  }

  Widget _indicator(bool isActive) {
    return Positioned(
      top: 20,
      left: 0,
      right: 0,
      child: Container(
        margin: EdgeInsets.only(top: 0),
        child: Row(
          mainAxisSize: MainAxisSize.min,
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            for (int i = 0; i < length; i++)
              if (i == currentPage) ...[circleBar(true)] else circleBar(false),
          ],
        ),
      ),
    );
  }

  Widget circleBar(bool isActive) {
    return AnimatedContainer(
      duration: Duration(milliseconds: 150),
      margin: EdgeInsets.symmetric(horizontal: 3),
      height: isActive ? 12 : 8,
      width: isActive ? 12 : 8,
      decoration: BoxDecoration(
          color: isActive ? Colors.red : Colors.grey,
          borderRadius: BorderRadius.all(Radius.circular(12))),
    );
  }
}
