photo_view.dart 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter_swiper/flutter_swiper.dart';
  3. import 'package:cached_network_image/cached_network_image.dart';
  4. import 'package:twong/utils/index.dart';
  5. class PhotoListData {
  6. final int index;
  7. final List<String> imageList;
  8. PhotoListData(this.index, this.imageList);
  9. }
  10. class PhotoViewPage extends StatefulWidget {
  11. final PhotoListData data;
  12. PhotoViewPage(this.data);
  13. @override
  14. State<StatefulWidget> createState() {
  15. return _PhotoViewPageState();
  16. }
  17. }
  18. class _PhotoViewPageState extends State<PhotoViewPage> {
  19. @override
  20. Widget build(BuildContext context) {
  21. return Scaffold(
  22. backgroundColor: Colors.black,
  23. body: SafeArea(child: Stack(
  24. children: [
  25. Swiper(
  26. loop: false,
  27. autoplay: false,
  28. index: widget.data.index,
  29. itemBuilder: _buildSlider,
  30. itemCount: widget.data.imageList.length,
  31. pagination: SwiperPagination(),
  32. autoplayDisableOnInteraction: true,
  33. ),
  34. Positioned(
  35. top: 10.px,
  36. left: 10.px,
  37. child: InkWell(
  38. highlightColor: Colors.transparent,
  39. onTap: () { Navigator.pop(context); },
  40. child: Container(
  41. width: 30.px,
  42. height: 30.px,
  43. decoration: BoxDecoration(
  44. color: Color.fromARGB(123, 0, 0, 0),
  45. borderRadius: BorderRadius.circular(20.px)
  46. ),
  47. child: Icon(
  48. Icons.chevron_left, color: Colors.white, size: 30.px),
  49. ),
  50. )
  51. ),
  52. ],
  53. )
  54. ),
  55. );
  56. }
  57. Widget _buildSlider(BuildContext context, int index) {
  58. return CachedNetworkImage(
  59. fit: BoxFit.contain,
  60. imageUrl: widget.data.imageList[index],
  61. placeholder: (BuildContext context, String str) {
  62. return Center(child: CircularProgressIndicator());
  63. },
  64. );
  65. }
  66. }