Files
eatvio_app/lib/features/chat/presentation/pages/photo_view_screen.dart
mso7nueh df290fa89b feature(consultant): Невозможно поставить точку в адресе сайта
добавить лоти анимацию на модалку завершение
                     Убрать фокус на 4 шаге (соцсети)
                     добавить текст на первый экран
                     выход с последнего экрана
                     радиобаттон на 5 шаге в синий цвет
                     оптимизировать загрузку изображений
                     Добавить галерею
                     Лоадинг в кнопке при отправке
2024-10-14 16:23:43 +03:00

129 lines
4.3 KiB
Dart

import 'dart:io';
import 'package:cached_network_image/cached_network_image.dart';
import 'package:dismissible_page/dismissible_page.dart';
import 'package:eatvio_app/core/const.dart';
import 'package:eatvio_app/theme/app_decoration.dart';
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:photo_view/photo_view.dart';
import 'package:photo_view/photo_view_gallery.dart';
import 'package:url_launcher/url_launcher.dart';
class PhotoViewScreen extends StatefulWidget {
final List<String> imageUrls;
final int index;
final bool isLocal;
const PhotoViewScreen({
super.key,
required this.imageUrls,
required this.index,
this.isLocal = false,
});
@override
State<PhotoViewScreen> createState() => _PhotoViewScreenState();
}
class _PhotoViewScreenState extends State<PhotoViewScreen> {
late final pageController;
int imageIndex = 0;
@override
void initState() {
imageIndex = widget.index;
pageController = PageController(initialPage: imageIndex);
super.initState();
}
@override
Widget build(BuildContext context) {
return DismissiblePage(
minScale: 1,
onDismissed: () => GoRouter.of(context).pop(),
direction: DismissiblePageDismissDirection.vertical,
isFullScreen: true,
child: PhotoViewGallery.builder(
backgroundDecoration: BoxDecoration(
color: Colors.transparent,
),
scrollPhysics: const BouncingScrollPhysics(),
builder: (BuildContext context, int index) {
return PhotoViewGalleryPageOptions(
imageProvider: widget.isLocal
? FileImage(
File(widget.imageUrls[index]),
) as ImageProvider
: CachedNetworkImageProvider(
widget.imageUrls[index],
),
initialScale: PhotoViewComputedScale.contained,
minScale: PhotoViewComputedScale.contained,
heroAttributes: PhotoViewHeroAttributes(
tag: widget.imageUrls[index],
transitionOnUserGestures: true,
),
errorBuilder: (context, object, stackTrace) {
return Scaffold(
backgroundColor: Colors.black,
body: SafeArea(
child: Column(
children: [
SizedBox(height: 32),
Text('Файл'),
SizedBox(height: 8),
ListTile(
shape: RoundedRectangleBorder(
borderRadius: BorderRadiusStyle.circleBorder17,
),
contentPadding: EdgeInsets.all(16),
onTap: () async {
if (!await launchUrl(Uri.parse(widget.imageUrls[index]))) {
throw Exception('Could not launch ${widget.imageUrls[index]}');
}
},
leading: Icon(
Icons.file_copy_outlined,
color: Colors.white,
),
trailing: Icon(
Icons.download_outlined,
color: Colors.white,
),
title: Text(
widget.imageUrls[index].replaceAll(baseUrl + '/storage/' + 'chat_files/', ''),
style: TextStyle(
color: Colors.white,
fontSize: 12,
),
),
),
],
),
),
);
},
);
},
itemCount: widget.imageUrls.length,
loadingBuilder: (context, event) => Center(
child: Container(
width: 20.0,
height: 20.0,
child: CircularProgressIndicator(
value: event == null ? 0 : event.cumulativeBytesLoaded / event.expectedTotalBytes!,
),
),
),
pageController: pageController,
onPageChanged: (page) {
setState(() {
imageIndex = page;
});
},
),
);
}
}