ui: Make [VideoChatWidget] stateless
This commit is contained in:
parent
da22d5a3d2
commit
3676973dbe
@ -1,7 +1,6 @@
|
|||||||
import "dart:typed_data";
|
import "dart:typed_data";
|
||||||
|
|
||||||
import "package:moxxyv2/shared/models/message.dart";
|
import "package:moxxyv2/shared/models/message.dart";
|
||||||
import "package:moxxyv2/ui/service/data.dart";
|
|
||||||
import "package:moxxyv2/ui/service/thumbnail.dart";
|
import "package:moxxyv2/ui/service/thumbnail.dart";
|
||||||
import "package:moxxyv2/ui/widgets/chat/gradient.dart";
|
import "package:moxxyv2/ui/widgets/chat/gradient.dart";
|
||||||
import "package:moxxyv2/ui/widgets/chat/bottom.dart";
|
import "package:moxxyv2/ui/widgets/chat/bottom.dart";
|
||||||
@ -14,9 +13,7 @@ import "package:flutter/material.dart";
|
|||||||
import "package:get_it/get_it.dart";
|
import "package:get_it/get_it.dart";
|
||||||
import "package:open_file/open_file.dart";
|
import "package:open_file/open_file.dart";
|
||||||
|
|
||||||
// TODO: This should be stateless
|
class VideoChatWidget extends StatelessWidget {
|
||||||
|
|
||||||
class VideoChatWidget extends StatefulWidget {
|
|
||||||
final Message message;
|
final Message message;
|
||||||
final double maxWidth;
|
final double maxWidth;
|
||||||
final BorderRadius radius;
|
final BorderRadius radius;
|
||||||
@ -30,19 +27,14 @@ class VideoChatWidget extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
) : super(key: key);
|
) : super(key: key);
|
||||||
|
|
||||||
@override
|
|
||||||
_VideoChatWidgetState createState() => _VideoChatWidgetState();
|
|
||||||
}
|
|
||||||
|
|
||||||
class _VideoChatWidgetState extends State<VideoChatWidget> {
|
|
||||||
Widget _buildNonDownloaded() {
|
Widget _buildNonDownloaded() {
|
||||||
// TODO
|
// TODO
|
||||||
if (widget.message.thumbnailData != null) {}
|
if (message.thumbnailData != null) {}
|
||||||
|
|
||||||
return FileChatWidget(
|
return FileChatWidget(
|
||||||
widget.message,
|
message,
|
||||||
extra: ElevatedButton(
|
extra: ElevatedButton(
|
||||||
onPressed: () => requestMediaDownload(widget.message),
|
onPressed: () => requestMediaDownload(message),
|
||||||
child: const Text("Download")
|
child: const Text("Download")
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
@ -50,22 +42,22 @@ class _VideoChatWidgetState extends State<VideoChatWidget> {
|
|||||||
|
|
||||||
Widget _buildDownloading() {
|
Widget _buildDownloading() {
|
||||||
// TODO
|
// TODO
|
||||||
if (widget.message.thumbnailData != null) {}
|
if (message.thumbnailData != null) {}
|
||||||
|
|
||||||
return FileChatWidget(widget.message);
|
return FileChatWidget(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildVideo() {
|
Widget _buildVideo() {
|
||||||
return FutureBuilder<Uint8List>(
|
return FutureBuilder<Uint8List>(
|
||||||
future: GetIt.I.get<ThumbnailCacheService>().getVideoThumbnail(widget.message.mediaUrl!),
|
future: GetIt.I.get<ThumbnailCacheService>().getVideoThumbnail(message.mediaUrl!),
|
||||||
builder: (context, snapshot) {
|
builder: (context, snapshot) {
|
||||||
if (snapshot.connectionState == ConnectionState.done) {
|
if (snapshot.connectionState == ConnectionState.done) {
|
||||||
if (snapshot.data != null) {
|
if (snapshot.data != null) {
|
||||||
return ImageBaseChatWidget(
|
return ImageBaseChatWidget(
|
||||||
widget.message.mediaUrl!,
|
message.mediaUrl!,
|
||||||
widget.radius,
|
radius,
|
||||||
Image.memory(snapshot.data!),
|
Image.memory(snapshot.data!),
|
||||||
MessageBubbleBottom(widget.message),
|
MessageBubbleBottom(message),
|
||||||
extra: const PlayButton()
|
extra: const PlayButton()
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
@ -88,7 +80,6 @@ class _VideoChatWidgetState extends State<VideoChatWidget> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Widget _innerBuild() {
|
Widget _innerBuild() {
|
||||||
final message = widget.message;
|
|
||||||
if (!message.isDownloading && message.mediaUrl != null) return _buildVideo();
|
if (!message.isDownloading && message.mediaUrl != null) return _buildVideo();
|
||||||
if (message.isDownloading) return _buildDownloading();
|
if (message.isDownloading) return _buildDownloading();
|
||||||
|
|
||||||
@ -100,22 +91,22 @@ class _VideoChatWidgetState extends State<VideoChatWidget> {
|
|||||||
return IntrinsicWidth(
|
return IntrinsicWidth(
|
||||||
child: InkWell(
|
child: InkWell(
|
||||||
onTap: () {
|
onTap: () {
|
||||||
OpenFile.open(widget.message.mediaUrl!);
|
OpenFile.open(message.mediaUrl!);
|
||||||
},
|
},
|
||||||
child: Stack(
|
child: Stack(
|
||||||
children: [
|
children: [
|
||||||
ClipRRect(
|
ClipRRect(
|
||||||
borderRadius: widget.radius,
|
borderRadius: radius,
|
||||||
child: _innerBuild()
|
child: _innerBuild()
|
||||||
),
|
),
|
||||||
BottomGradient(widget.radius),
|
BottomGradient(radius),
|
||||||
Positioned(
|
Positioned(
|
||||||
bottom: 0,
|
bottom: 0,
|
||||||
left: 0,
|
left: 0,
|
||||||
right: 0,
|
right: 0,
|
||||||
child: Padding(
|
child: Padding(
|
||||||
padding: const EdgeInsets.only(bottom: 3.0, right: 6.0),
|
padding: const EdgeInsets.only(bottom: 3.0, right: 6.0),
|
||||||
child: MessageBubbleBottom(widget.message)
|
child: MessageBubbleBottom(message)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
]
|
]
|
||||||
|
Loading…
Reference in New Issue
Block a user