会话页面
This commit is contained in:
78
lib/views/conversation/preview/image_widget.dart
Normal file
78
lib/views/conversation/preview/image_widget.dart
Normal file
@@ -0,0 +1,78 @@
|
||||
import 'dart:io';
|
||||
import 'package:cached_network_image/cached_network_image.dart';
|
||||
import 'package:chat/configs/app_colors.dart';
|
||||
import 'package:chat/constants/message_constant.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:photo_view/photo_view.dart';
|
||||
import 'package:photo_view/photo_view_gallery.dart';
|
||||
|
||||
class PreviewImageWidget extends StatelessWidget {
|
||||
final IMG_PREVIEW_TYPE type;
|
||||
|
||||
final String path;
|
||||
|
||||
final String original;
|
||||
|
||||
const PreviewImageWidget({
|
||||
Key? key,
|
||||
required this.type,
|
||||
required this.path,
|
||||
required this.original,
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Material(
|
||||
color: AppColors.black,
|
||||
child: SafeArea(
|
||||
child: Stack(
|
||||
children: [
|
||||
Positioned.fill(
|
||||
child: PhotoViewGallery.builder(
|
||||
pageController: PageController(initialPage: 0),
|
||||
itemCount: 1,
|
||||
builder: (context, index) {
|
||||
if (type == IMG_PREVIEW_TYPE.local) {
|
||||
return PhotoViewGalleryPageOptions(
|
||||
imageProvider: FileImage(File(path)),
|
||||
minScale: PhotoViewComputedScale.contained,
|
||||
maxScale: PhotoViewComputedScale.covered * 2,
|
||||
);
|
||||
} else {
|
||||
if (path.split('?').first.isImageFileName) {
|
||||
return PhotoViewGalleryPageOptions(
|
||||
imageProvider: CachedNetworkImageProvider(path),
|
||||
minScale: PhotoViewComputedScale.contained,
|
||||
maxScale: PhotoViewComputedScale.covered * 2,
|
||||
);
|
||||
} else {
|
||||
return PhotoViewGalleryPageOptions.customChild(
|
||||
child: const Center(
|
||||
child: Text(
|
||||
'格式不支持',
|
||||
style: TextStyle(
|
||||
color: AppColors.white,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
},
|
||||
),
|
||||
),
|
||||
const SafeArea(
|
||||
child: Padding(
|
||||
padding: EdgeInsets.all(4.0),
|
||||
child: BackButton(
|
||||
color: AppColors.white,
|
||||
),
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
119
lib/views/conversation/preview/video_widget.dart
Normal file
119
lib/views/conversation/preview/video_widget.dart
Normal file
@@ -0,0 +1,119 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:chat/configs/app_colors.dart';
|
||||
import 'package:chat/utils/ui_tools.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:tencent_im_sdk_plugin/models/v2_tim_video_elem.dart';
|
||||
import 'package:video_player/video_player.dart';
|
||||
|
||||
class PreviewVideoWidget extends StatefulWidget {
|
||||
final V2TimVideoElem video;
|
||||
const PreviewVideoWidget(this.video, {Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<PreviewVideoWidget> createState() => _PreviewVideoWidgetState();
|
||||
}
|
||||
|
||||
class _PreviewVideoWidgetState extends State<PreviewVideoWidget> {
|
||||
late VideoPlayerController _controller;
|
||||
bool isPause = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
||||
var lv = widget.video.localVideoUrl;
|
||||
|
||||
if (lv != null && lv.isNotEmpty && File(lv).existsSync()) {
|
||||
_controller =
|
||||
VideoPlayerController.file(File(widget.video.localVideoUrl!))
|
||||
..initialize().then((value) {
|
||||
setState(() {
|
||||
_controller.play();
|
||||
});
|
||||
}).catchError((e) {
|
||||
UiTools.toast(e.toString());
|
||||
});
|
||||
} else {
|
||||
_controller = VideoPlayerController.network(widget.video.videoUrl!)
|
||||
..initialize().then((value) {
|
||||
setState(() {
|
||||
_controller.play();
|
||||
});
|
||||
}).catchError((e) {
|
||||
UiTools.toast(e.toString());
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_controller.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
backgroundColor: AppColors.mainBlack,
|
||||
appBar: AppBar(
|
||||
backgroundColor: AppColors.transparent,
|
||||
foregroundColor: AppColors.white,
|
||||
),
|
||||
body: GestureDetector(
|
||||
onTap: () {
|
||||
setState(() {
|
||||
if (_controller.value.isInitialized) {
|
||||
if (_controller.value.isPlaying) {
|
||||
_controller.pause();
|
||||
isPause = true;
|
||||
} else {
|
||||
_controller.play();
|
||||
isPause = false;
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
child: Stack(
|
||||
children: [
|
||||
Center(
|
||||
child: _controller.value.isInitialized
|
||||
? AspectRatio(
|
||||
aspectRatio: _controller.value.aspectRatio,
|
||||
child: VideoPlayer(_controller),
|
||||
)
|
||||
: _controller.value.hasError
|
||||
? const Text(
|
||||
'视频加载失败',
|
||||
style: TextStyle(
|
||||
color: AppColors.white,
|
||||
),
|
||||
)
|
||||
: const CircularProgressIndicator(
|
||||
color: AppColors.primary,
|
||||
),
|
||||
),
|
||||
Align(
|
||||
alignment: Alignment.bottomCenter,
|
||||
child: VideoProgressIndicator(
|
||||
_controller,
|
||||
allowScrubbing: true,
|
||||
),
|
||||
),
|
||||
Align(
|
||||
alignment: Alignment.center,
|
||||
child: Visibility(
|
||||
visible: isPause,
|
||||
child: const Icon(
|
||||
Icons.play_circle_outline,
|
||||
size: 96,
|
||||
color: AppColors.white,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user