image_pagination.dart 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. import 'package:fis_measure/view/mobile_view/widgets/debounce.dart' as utils;
  2. import 'package:fis_measure/process/workspace/measure_controller.dart';
  3. import 'package:fis_measure/process/workspace/measure_handler.dart';
  4. import 'package:fis_ui/index.dart';
  5. import 'package:flutter/material.dart';
  6. import 'package:flutter/services.dart';
  7. import 'package:get/get.dart';
  8. class ImagePagination extends StatefulWidget {
  9. const ImagePagination({super.key, required this.measureController});
  10. final MeasureController measureController;
  11. @override
  12. State<StatefulWidget> createState() {
  13. return ImagePaginationState();
  14. }
  15. }
  16. class ImagePaginationState extends State<ImagePagination> {
  17. late final IMeasureHandler measureHandler = Get.find<IMeasureHandler>();
  18. int totelCount = 0;
  19. int currentIndex = 0;
  20. void preImage() {
  21. utils.debounce(() {
  22. if (currentIndex > 0) {
  23. currentIndex--;
  24. changeImageByIndex(currentIndex);
  25. HapticFeedback.mediumImpact();
  26. }
  27. setState(() {
  28. currentIndex = currentIndex;
  29. });
  30. }, 'onChangeImage', 600);
  31. }
  32. void nextImage() {
  33. utils.debounce(() {
  34. if (currentIndex < totelCount - 1) {
  35. currentIndex++;
  36. changeImageByIndex(currentIndex);
  37. HapticFeedback.mediumImpact();
  38. }
  39. setState(() {
  40. currentIndex = currentIndex;
  41. });
  42. }, 'onChangeImage', 600);
  43. }
  44. void changeImageByIndex(int index) {
  45. measureHandler.newImageLoading = true;
  46. widget.measureController.examInfo.selectedImageIndex = index;
  47. }
  48. get noNext => currentIndex >= totelCount - 1;
  49. get noPre => currentIndex <= 0;
  50. @override
  51. void initState() {
  52. super.initState();
  53. currentIndex = widget.measureController.examInfo.selectedImageIndex;
  54. totelCount = widget.measureController.examInfo.images.length;
  55. }
  56. @override
  57. Widget build(BuildContext context) {
  58. return SizedBox(
  59. width: 50,
  60. child: Column(
  61. mainAxisAlignment: MainAxisAlignment.center,
  62. children: [
  63. Opacity(
  64. opacity: noPre ? 0.2 : 1,
  65. child: Container(
  66. margin: const EdgeInsets.symmetric(horizontal: 5),
  67. child: ElevatedButton(
  68. onPressed: noPre ? null : preImage,
  69. style: ElevatedButton.styleFrom(
  70. padding:
  71. const EdgeInsets.symmetric(horizontal: 0, vertical: 16),
  72. elevation: 0,
  73. backgroundColor: Colors.white.withOpacity(0.2),
  74. ),
  75. child: const Icon(
  76. Icons.keyboard_arrow_up,
  77. size: 30,
  78. color: Colors.white,
  79. ),
  80. ),
  81. ),
  82. ),
  83. const FSizedBox(
  84. height: 10,
  85. ),
  86. Text(
  87. "${currentIndex + 1}/$totelCount",
  88. style: const TextStyle(color: Colors.white70, fontSize: 14),
  89. ),
  90. const FSizedBox(
  91. height: 10,
  92. ),
  93. Opacity(
  94. opacity: noNext ? 0.2 : 1,
  95. child: Container(
  96. margin: const EdgeInsets.symmetric(horizontal: 5),
  97. child: ElevatedButton(
  98. style: ElevatedButton.styleFrom(
  99. // shape: const CircleBorder(),
  100. padding:
  101. const EdgeInsets.symmetric(horizontal: 0, vertical: 16),
  102. elevation: 0,
  103. backgroundColor: Colors.white.withOpacity(0.2),
  104. ),
  105. onPressed: noNext ? null : nextImage,
  106. child: const Icon(
  107. Icons.keyboard_arrow_down,
  108. size: 30,
  109. color: Colors.white,
  110. ),
  111. ),
  112. ),
  113. ),
  114. ],
  115. ),
  116. );
  117. }
  118. }