PhotoView.dart 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import 'package:cached_network_image/cached_network_image.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:photo_view/photo_view.dart';
  4. import 'package:photo_view/photo_view_gallery.dart';
  5. class PhotoView extends StatefulWidget {
  6. final List<String> imageList;
  7. PhotoView({this.imageList = const []});
  8. @override
  9. _PhotoViewState createState() => _PhotoViewState();
  10. }
  11. class _PhotoViewState extends State<PhotoView> with WidgetsBindingObserver {
  12. int nowIndex = 1;
  13. @override
  14. Widget build(BuildContext context) {
  15. return Scaffold(
  16. appBar: AppBar(
  17. title: Text(''),
  18. ),
  19. backgroundColor: Colors.black,
  20. body: PhotoViewGallery.builder(
  21. scrollPhysics: const BouncingScrollPhysics(),
  22. builder: (BuildContext context, int index) {
  23. return PhotoViewGalleryPageOptions(
  24. imageProvider: CachedNetworkImageProvider(widget.imageList[index]),
  25. );
  26. },
  27. itemCount: widget.imageList.length,
  28. backgroundDecoration: BoxDecoration(color: Colors.black),
  29. onPageChanged: (index) {
  30. print(index);
  31. setState(() {
  32. nowIndex = index + 1;
  33. });
  34. },
  35. // loadingChild: Center(
  36. // child: Text('加载中...',),
  37. // )
  38. ),
  39. floatingActionButton: Column(
  40. mainAxisSize: MainAxisSize.min,
  41. children: <Widget>[
  42. Text('${nowIndex}/${widget.imageList.length}', style: TextStyle(color: Colors.white)),
  43. Container(
  44. width: 220,
  45. height: 36,
  46. margin: EdgeInsets.only(top: 10, bottom: 20),
  47. child: RaisedButton(
  48. color: Color(0xFFD4504B),
  49. shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(4)),
  50. child: Text(
  51. '我已设置完毕',
  52. style: TextStyle(color: Colors.white, fontSize: 14),
  53. ),
  54. onPressed: () {
  55. Navigator.of(context).pop(true);
  56. },
  57. ),
  58. )
  59. ],
  60. ),
  61. floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
  62. );
  63. }
  64. }