facility_location_page.dart 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. import 'package:cs_resources/theme/app_colors_theme.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:auto_route/auto_route.dart';
  4. import 'package:flutter_hooks/flutter_hooks.dart';
  5. import 'package:hooks_riverpod/hooks_riverpod.dart';
  6. import 'package:router/ext/auto_router_extensions.dart';
  7. import 'package:widgets/my_appbar.dart';
  8. import 'package:widgets/my_load_image.dart';
  9. import '../../router/page/facility_page_router.dart';
  10. @RoutePage()
  11. class FacilityLocationPage extends HookConsumerWidget {
  12. final List<String> imageUrls;
  13. const FacilityLocationPage({Key? key, required this.imageUrls}) : super(key: key);
  14. //启动当前页面
  15. static void startInstance({BuildContext? context, required List<String> imageUrls}) {
  16. if (context != null) {
  17. context.router.push(FacilityLocationPageRoute(imageUrls: imageUrls));
  18. } else {
  19. appRouter.push(FacilityLocationPageRoute(imageUrls: imageUrls));
  20. }
  21. }
  22. @override
  23. Widget build(BuildContext context, WidgetRef ref) {
  24. final currentPage = useState(0); // 记录当前页索引
  25. final pageController = usePageController(); // 创建 PageController
  26. // 监听页面变化
  27. useEffect(() {
  28. pageController.addListener(() {
  29. currentPage.value = pageController.page!.round();
  30. });
  31. return () => pageController.dispose();
  32. }, [pageController]);
  33. return Scaffold(
  34. appBar: MyAppBar.appBar(
  35. context,
  36. "Kids party room",
  37. ),
  38. backgroundColor: context.appColors.backgroundWhite,
  39. body: Container(
  40. width: double.infinity,
  41. height: double.infinity,
  42. child: Stack(
  43. children: [
  44. PageView.builder(
  45. controller: pageController,
  46. itemCount: imageUrls.length,
  47. itemBuilder: (context, index) {
  48. return MyLoadImage(
  49. imageUrls[index],
  50. fit: BoxFit.fitWidth,
  51. );
  52. },
  53. ),
  54. // 底部指示器
  55. Positioned(
  56. bottom: 36,
  57. left: 0,
  58. right: 0,
  59. child: Row(
  60. mainAxisAlignment: MainAxisAlignment.center,
  61. children: List.generate(imageUrls.length, (index) {
  62. return Container(
  63. margin: const EdgeInsets.symmetric(horizontal: 4),
  64. height: 8,
  65. width: 8,
  66. decoration: BoxDecoration(
  67. shape: BoxShape.circle,
  68. color: currentPage.value == index ? Colors.blue : Colors.grey,
  69. ),
  70. );
  71. }),
  72. ),
  73. ),
  74. ],
  75. ),
  76. ),
  77. );
  78. }
  79. }