photo_view_page.dart 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. import 'dart:io';
  2. import 'package:auto_route/auto_route.dart';
  3. import 'package:eitc_erm_dental_flutter/entity/history_item_info.dart';
  4. import 'package:eitc_erm_dental_flutter/funcs.dart';
  5. import 'package:eitc_erm_dental_flutter/pages/history/vm/history_view_model.dart';
  6. import 'package:flutter/material.dart';
  7. import 'package:flutter_riverpod/flutter_riverpod.dart';
  8. import 'package:photo_view/photo_view.dart';
  9. import '../../app_router.gr.dart';
  10. import 'widget/history_view_operation_view.dart';
  11. import 'widget/history_view_title.dart';
  12. ///照片查看页面
  13. @RoutePage(name: "photoViewRoute")
  14. class PhotoViewPage extends ConsumerStatefulWidget {
  15. final HistoryItemInfo? info;
  16. const PhotoViewPage({super.key, required this.info});
  17. @override
  18. ConsumerState createState() => _PhotoViewPageState();
  19. }
  20. class _PhotoViewPageState extends ConsumerState<PhotoViewPage> {
  21. @override
  22. void initState() {
  23. super.initState();
  24. //开启屏幕旋转
  25. screenEnableRotate();
  26. }
  27. @override
  28. void dispose() {
  29. super.dispose();
  30. //关闭屏幕旋转
  31. screenDisableRotate();
  32. }
  33. @override
  34. Widget build(BuildContext context) {
  35. Widget photoView = widget.info == null
  36. ? const SizedBox()
  37. : PhotoView(imageProvider: FileImage(File(widget.info!.path)));
  38. return Scaffold(
  39. body: SafeArea(
  40. child: Container(
  41. color: Colors.black,
  42. child: Stack(
  43. children: [
  44. photoView,
  45. Align(
  46. alignment: Alignment.topLeft,
  47. child: HistoryViewTitle(
  48. name: widget.info?.name,
  49. ),
  50. ),
  51. HistoryViewOperationView(
  52. onUpload: () => _onUpload(context),
  53. onDelete: () => _onDelete(context),
  54. ),
  55. ],
  56. ),
  57. ),
  58. ),
  59. );
  60. }
  61. void _onUpload(BuildContext context) async {
  62. if (!await checkInternetWifi()) {
  63. return;
  64. }
  65. if (context.mounted) {
  66. context.pushRoute(UploadSelectClinicRoute(
  67. uploadList: [widget.info!], isFromView: true));
  68. }
  69. }
  70. void _onDelete(BuildContext context) async {
  71. bool? bo = await showDeleteAlertDialog(context, getS().deletePhotoHint);
  72. if (bo == null || !bo) {
  73. return;
  74. }
  75. bool result =
  76. await ref.read(historyListProvider.notifier).delete([widget.info!]);
  77. if (result) {
  78. showToast(text: getS().deleteSuccess);
  79. if (context.mounted) {
  80. Navigator.pop(context, widget.info);
  81. }
  82. } else {
  83. showToast(text: getS().deleteFailed);
  84. }
  85. }
  86. }