picture_display_page.dart 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import 'package:bbyyy/my_tools/AsperctRaioImage.dart';
  2. import 'package:cached_network_image/cached_network_image.dart';
  3. import 'package:flutter/material.dart';
  4. class PictureDisplayPage extends StatefulWidget {
  5. String imagePath;
  6. PictureDisplayPage(this.imagePath);
  7. @override
  8. _PictureDisplayPageState createState() => _PictureDisplayPageState();
  9. }
  10. class _PictureDisplayPageState extends State<PictureDisplayPage> {
  11. @override
  12. Widget build(BuildContext context) {
  13. return Scaffold(
  14. backgroundColor: Colors.black,
  15. body: Column(
  16. children: <Widget>[
  17. Expanded(
  18. child: GestureDetector(
  19. child: AsperctRaioImage.network(widget.imagePath,
  20. builder: (context, snapshot, url) {
  21. double h = (snapshot.data.height.toDouble() / 5);
  22. double w = (snapshot.data.width.toDouble() / 5);
  23. bool fw = h / w >=
  24. MediaQuery.of(context).size.height /
  25. MediaQuery.of(context).size.width;
  26. print('h-------------$h\nw----------------$w');
  27. return CachedNetworkImage(
  28. imageUrl: widget.imagePath,
  29. height: fw
  30. ? h / w * MediaQuery.of(context).size.width
  31. : MediaQuery.of(context).size.height,
  32. width: fw
  33. ? MediaQuery.of(context).size.width
  34. : w / h * MediaQuery.of(context).size.height,
  35. );
  36. }),
  37. onTap: () {
  38. Navigator.pop(context);
  39. },
  40. behavior: HitTestBehavior.translucent,
  41. ),
  42. )
  43. ],
  44. ),
  45. );
  46. }
  47. }