Hibok
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 
 
 
 

68 righe
1.7 KiB

  1. import 'dart:math';
  2. import 'package:flutter/material.dart';
  3. class DotsIndicator extends AnimatedWidget {
  4. DotsIndicator({
  5. this.controller,
  6. this.itemCount,
  7. this.onPageSelected,
  8. this.color: Colors.red,
  9. }) : super(listenable: controller);
  10. /// The PageController that this DotsIndicator is representing.
  11. final PageController controller;
  12. /// The number of items managed by the PageController
  13. final int itemCount;
  14. /// Called when a dot is tapped
  15. final ValueChanged<int> onPageSelected;
  16. /// The color of the dots.
  17. ///
  18. /// Defaults to `Colors.white`.
  19. final Color color;
  20. // The base size of the dots
  21. static const double _kDotSize = 8.0;
  22. // The increase in the size of the selected dot
  23. static const double _kMaxZoom = 2.0;
  24. // The distance between the center of each dot
  25. static const double _kDotSpacing = 25.0;
  26. Widget _buildDot(int index) {
  27. double selectedness = Curves.easeOut.transform(
  28. max(
  29. 0.0,
  30. 1.0 - ((controller.page ?? controller.initialPage) - index).abs(),
  31. ),
  32. );
  33. double zoom = 1.0 + (_kMaxZoom - 1.0) * selectedness;
  34. return new Container(
  35. width: _kDotSpacing,
  36. child: new Center(
  37. child: new Material(
  38. color: color,
  39. type: MaterialType.circle,
  40. child: new Container(
  41. width: _kDotSize * zoom,
  42. height: _kDotSize * zoom,
  43. child: new InkWell(
  44. onTap: () => onPageSelected(index),
  45. ),
  46. ),
  47. ),
  48. ),
  49. );
  50. }
  51. Widget build(BuildContext context) {
  52. return new Row(
  53. mainAxisAlignment: MainAxisAlignment.center,
  54. children: new List<Widget>.generate(itemCount, _buildDot),
  55. );
  56. }
  57. }