lint changes media
This commit is contained in:
@@ -8,24 +8,24 @@ import 'package:jiffy/jiffy.dart';
|
|||||||
import 'package:photo_view/photo_view.dart';
|
import 'package:photo_view/photo_view.dart';
|
||||||
import 'package:stream_chat_flutter/src/image_footer.dart';
|
import 'package:stream_chat_flutter/src/image_footer.dart';
|
||||||
import 'package:stream_chat_flutter/src/image_header.dart';
|
import 'package:stream_chat_flutter/src/image_header.dart';
|
||||||
|
import 'package:stream_chat_flutter/stream_chat_flutter.dart';
|
||||||
import 'package:video_player/video_player.dart';
|
import 'package:video_player/video_player.dart';
|
||||||
|
|
||||||
import '../stream_chat_flutter.dart';
|
/// Return action for coming back from pages
|
||||||
|
enum ReturnActionType {
|
||||||
|
|
||||||
enum ReturnActionType { none, reply }
|
/// No return action
|
||||||
|
none,
|
||||||
|
|
||||||
|
/// Go to reply message action
|
||||||
|
reply,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Callback when show message is tapped
|
||||||
typedef ShowMessageCallback = void Function(Message message, Channel channel);
|
typedef ShowMessageCallback = void Function(Message message, Channel channel);
|
||||||
|
|
||||||
/// A full screen image widget
|
/// A full screen image widget
|
||||||
class FullScreenMedia extends StatefulWidget {
|
class FullScreenMedia extends StatefulWidget {
|
||||||
/// The url of the image
|
|
||||||
final List<Attachment> mediaAttachments;
|
|
||||||
final Message message;
|
|
||||||
|
|
||||||
final int startIndex;
|
|
||||||
final String userName;
|
|
||||||
final ShowMessageCallback? onShowMessage;
|
|
||||||
|
|
||||||
/// Instantiate a new FullScreenImage
|
/// Instantiate a new FullScreenImage
|
||||||
const FullScreenMedia({
|
const FullScreenMedia({
|
||||||
Key? key,
|
Key? key,
|
||||||
@@ -37,6 +37,21 @@ class FullScreenMedia extends StatefulWidget {
|
|||||||
}) : userName = userName ?? '',
|
}) : userName = userName ?? '',
|
||||||
super(key: key);
|
super(key: key);
|
||||||
|
|
||||||
|
/// The url of the image
|
||||||
|
final List<Attachment> mediaAttachments;
|
||||||
|
|
||||||
|
/// Message where attachments are attached
|
||||||
|
final Message message;
|
||||||
|
|
||||||
|
/// First index of media shown
|
||||||
|
final int startIndex;
|
||||||
|
|
||||||
|
/// Username of sender
|
||||||
|
final String userName;
|
||||||
|
|
||||||
|
/// Callback for when show message is tapped
|
||||||
|
final ShowMessageCallback? onShowMessage;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
_FullScreenMediaState createState() => _FullScreenMediaState();
|
_FullScreenMediaState createState() => _FullScreenMediaState();
|
||||||
}
|
}
|
||||||
@@ -57,7 +72,7 @@ class _FullScreenMediaState extends State<FullScreenMedia>
|
|||||||
super.initState();
|
super.initState();
|
||||||
_controller = AnimationController(
|
_controller = AnimationController(
|
||||||
vsync: this,
|
vsync: this,
|
||||||
duration: Duration(milliseconds: 300),
|
duration: const Duration(milliseconds: 300),
|
||||||
);
|
);
|
||||||
_pageController = PageController(initialPage: widget.startIndex);
|
_pageController = PageController(initialPage: widget.startIndex);
|
||||||
_currentPage = widget.startIndex;
|
_currentPage = widget.startIndex;
|
||||||
@@ -77,15 +92,13 @@ class _FullScreenMediaState extends State<FullScreenMedia>
|
|||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) => Scaffold(
|
||||||
return Scaffold(
|
|
||||||
resizeToAvoidBottomInset: false,
|
resizeToAvoidBottomInset: false,
|
||||||
body: Stack(
|
body: Stack(
|
||||||
children: [
|
children: [
|
||||||
AnimatedBuilder(
|
AnimatedBuilder(
|
||||||
animation: _controller,
|
animation: _controller,
|
||||||
builder: (context, snapshot) {
|
builder: (context, snapshot) => PageView.builder(
|
||||||
return PageView.builder(
|
|
||||||
controller: _pageController,
|
controller: _pageController,
|
||||||
onPageChanged: (val) {
|
onPageChanged: (val) {
|
||||||
setState(() {
|
setState(() {
|
||||||
@@ -133,7 +146,7 @@ class _FullScreenMediaState extends State<FullScreenMedia>
|
|||||||
} else if (attachment.type == 'video') {
|
} else if (attachment.type == 'video') {
|
||||||
final controller = videoPackages[attachment.id]!;
|
final controller = videoPackages[attachment.id]!;
|
||||||
if (!controller.initialized) {
|
if (!controller.initialized) {
|
||||||
return Center(
|
return const Center(
|
||||||
child: CircularProgressIndicator(),
|
child: CircularProgressIndicator(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -161,17 +174,17 @@ class _FullScreenMediaState extends State<FullScreenMedia>
|
|||||||
return Container();
|
return Container();
|
||||||
},
|
},
|
||||||
itemCount: widget.mediaAttachments.length,
|
itemCount: widget.mediaAttachments.length,
|
||||||
);
|
)),
|
||||||
}),
|
|
||||||
AnimatedOpacity(
|
AnimatedOpacity(
|
||||||
opacity: _optionsShown ? 1.0 : 0.0,
|
opacity: _optionsShown ? 1.0 : 0.0,
|
||||||
duration: Duration(milliseconds: 300),
|
duration: const Duration(milliseconds: 300),
|
||||||
child: Column(
|
child: Column(
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
children: [
|
children: [
|
||||||
ImageHeader(
|
ImageHeader(
|
||||||
userName: widget.userName,
|
userName: widget.userName,
|
||||||
sentAt:
|
sentAt:
|
||||||
|
// ignore: lines_longer_than_80_chars
|
||||||
'Sent ${getDay(widget.message.createdAt.toLocal())} at ${Jiffy(widget.message.createdAt.toLocal()).format('HH:mm')}',
|
'Sent ${getDay(widget.message.createdAt.toLocal())} at ${Jiffy(widget.message.createdAt.toLocal()).format('HH:mm')}',
|
||||||
onBackPressed: () {
|
onBackPressed: () {
|
||||||
Navigator.of(context).pop();
|
Navigator.of(context).pop();
|
||||||
@@ -196,7 +209,7 @@ class _FullScreenMediaState extends State<FullScreenMedia>
|
|||||||
_currentPage = val;
|
_currentPage = val;
|
||||||
_pageController.animateToPage(
|
_pageController.animateToPage(
|
||||||
val,
|
val,
|
||||||
duration: Duration(milliseconds: 300),
|
duration: const Duration(milliseconds: 300),
|
||||||
curve: Curves.easeInOut,
|
curve: Curves.easeInOut,
|
||||||
);
|
);
|
||||||
Navigator.pop(context);
|
Navigator.pop(context);
|
||||||
@@ -209,7 +222,6 @@ class _FullScreenMediaState extends State<FullScreenMedia>
|
|||||||
],
|
],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
|
||||||
|
|
||||||
String getDay(DateTime dateTime) {
|
String getDay(DateTime dateTime) {
|
||||||
final now = DateTime.now();
|
final now = DateTime.now();
|
||||||
@@ -236,18 +248,9 @@ class _FullScreenMediaState extends State<FullScreenMedia>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Class for packaging up things required for videos
|
||||||
class VideoPackage {
|
class VideoPackage {
|
||||||
final bool _showControls;
|
/// Constructor for creating [VideoPackage]
|
||||||
final bool _autoInitialize;
|
|
||||||
final VideoPlayerController _videoPlayerController;
|
|
||||||
ChewieController? _chewieController;
|
|
||||||
|
|
||||||
VideoPlayerController get videoPlayer => _videoPlayerController;
|
|
||||||
|
|
||||||
ChewieController? get chewieController => _chewieController;
|
|
||||||
|
|
||||||
bool get initialized => _videoPlayerController.value.isInitialized;
|
|
||||||
|
|
||||||
VideoPackage(
|
VideoPackage(
|
||||||
Attachment attachment, {
|
Attachment attachment, {
|
||||||
bool showControls = false,
|
bool showControls = false,
|
||||||
@@ -258,8 +261,22 @@ class VideoPackage {
|
|||||||
? VideoPlayerController.file(File.fromUri(attachment.localUri!))
|
? VideoPlayerController.file(File.fromUri(attachment.localUri!))
|
||||||
: VideoPlayerController.network(attachment.assetUrl!);
|
: VideoPlayerController.network(attachment.assetUrl!);
|
||||||
|
|
||||||
Future<void> initialize() {
|
final bool _showControls;
|
||||||
return _videoPlayerController.initialize().then((_) {
|
final bool _autoInitialize;
|
||||||
|
final VideoPlayerController _videoPlayerController;
|
||||||
|
ChewieController? _chewieController;
|
||||||
|
|
||||||
|
/// Get video player for video
|
||||||
|
VideoPlayerController get videoPlayer => _videoPlayerController;
|
||||||
|
|
||||||
|
/// Get [ChewieController] for video
|
||||||
|
ChewieController? get chewieController => _chewieController;
|
||||||
|
|
||||||
|
/// Check if controller is initialised
|
||||||
|
bool get initialized => _videoPlayerController.value.isInitialized;
|
||||||
|
|
||||||
|
/// Initialize all things required for [VideoPackage]
|
||||||
|
Future<void> initialize() => _videoPlayerController.initialize().then((_) {
|
||||||
_chewieController = ChewieController(
|
_chewieController = ChewieController(
|
||||||
videoPlayerController: _videoPlayerController,
|
videoPlayerController: _videoPlayerController,
|
||||||
autoInitialize: _autoInitialize,
|
autoInitialize: _autoInitialize,
|
||||||
@@ -267,16 +284,16 @@ class VideoPackage {
|
|||||||
aspectRatio: _videoPlayerController.value.aspectRatio,
|
aspectRatio: _videoPlayerController.value.aspectRatio,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
|
||||||
void addListener(VoidCallback listener) {
|
/// Add a listener to video player controller
|
||||||
return _videoPlayerController.addListener(listener);
|
void addListener(VoidCallback listener) =>
|
||||||
}
|
_videoPlayerController.addListener(listener);
|
||||||
|
|
||||||
void removeListener(VoidCallback listener) {
|
/// Remove a listener to video player controller
|
||||||
return _videoPlayerController.removeListener(listener);
|
void removeListener(VoidCallback listener) =>
|
||||||
}
|
_videoPlayerController.removeListener(listener);
|
||||||
|
|
||||||
|
/// Dispose controllers
|
||||||
Future<void> dispose() {
|
Future<void> dispose() {
|
||||||
_chewieController?.dispose();
|
_chewieController?.dispose();
|
||||||
return _videoPlayerController.dispose();
|
return _videoPlayerController.dispose();
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
import 'package:cached_network_image/cached_network_image.dart';
|
import 'package:cached_network_image/cached_network_image.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:stream_chat_flutter/stream_chat_flutter.dart';
|
||||||
|
|
||||||
import '../stream_chat_flutter.dart';
|
/// Widget for constructing a group of images
|
||||||
|
|
||||||
class GroupImage extends StatelessWidget {
|
class GroupImage extends StatelessWidget {
|
||||||
|
/// Constructor for creating a [GroupImage]
|
||||||
const GroupImage({
|
const GroupImage({
|
||||||
Key? key,
|
Key? key,
|
||||||
required this.images,
|
required this.images,
|
||||||
@@ -15,17 +16,30 @@ class GroupImage extends StatelessWidget {
|
|||||||
this.selectionThickness = 4,
|
this.selectionThickness = 4,
|
||||||
}) : super(key: key);
|
}) : super(key: key);
|
||||||
|
|
||||||
|
/// List of images to display
|
||||||
final List<String> images;
|
final List<String> images;
|
||||||
|
|
||||||
|
/// Constraints on the widget
|
||||||
final BoxConstraints? constraints;
|
final BoxConstraints? constraints;
|
||||||
|
|
||||||
|
/// Callback when widget is tapped
|
||||||
final VoidCallback? onTap;
|
final VoidCallback? onTap;
|
||||||
|
|
||||||
|
/// Highlights if selected
|
||||||
final bool selected;
|
final bool selected;
|
||||||
|
|
||||||
|
/// [BorderRadius] to pass to the widget
|
||||||
final BorderRadius? borderRadius;
|
final BorderRadius? borderRadius;
|
||||||
|
|
||||||
|
/// Color of selection if selected
|
||||||
final Color? selectionColor;
|
final Color? selectionColor;
|
||||||
|
|
||||||
|
/// Thickness with which color of selection is shown
|
||||||
final double selectionThickness;
|
final double selectionThickness;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
var avatar;
|
Widget? avatar;
|
||||||
final streamChatTheme = StreamChatTheme.of(context);
|
final streamChatTheme = StreamChatTheme.of(context);
|
||||||
|
|
||||||
avatar = GestureDetector(
|
avatar = GestureDetector(
|
||||||
|
|||||||
Reference in New Issue
Block a user