fluffychat/lib/pangea/common/widgets/url_image_widget.dart
ggurdin 677e9ce594
3822 begin activity design implementation (#3827)
* file reorganization

* added activity summary widget to show in chat view and activity launch view

* more updates to activity sessions start page

* function to ping course

* remove duplicate loading of participants

* nav bar visibility changes

* add generalized image from url widget

* update bottom of screen activity status message and add summaries to chat event list

* scroll to summary on click

* show invited activity sessions in course chats view
2025-09-02 12:37:16 -04:00

71 lines
2 KiB
Dart

// ignore_for_file: depend_on_referenced_packages
import 'package:flutter/material.dart';
import 'package:cached_network_image/cached_network_image.dart';
import 'package:cached_network_image_platform_interface/cached_network_image_platform_interface.dart';
import 'package:fluffychat/widgets/matrix.dart';
import 'package:fluffychat/widgets/mxc_image.dart';
class ImageByUrl extends StatelessWidget {
final String? imageUrl;
final double width;
final BorderRadius borderRadius;
final Widget? replacement;
const ImageByUrl({
super.key,
required this.imageUrl,
required this.width,
this.replacement,
this.borderRadius = const BorderRadius.all(Radius.circular(20.0)),
});
@override
Widget build(BuildContext context) {
if (imageUrl == null) {
return replacement ?? const SizedBox();
}
return SizedBox(
width: width,
height: width,
child: ClipRRect(
borderRadius: borderRadius,
child: imageUrl!.startsWith("mxc")
? MxcImage(
uri: Uri.parse(imageUrl!),
width: width,
height: width,
cacheKey: imageUrl,
fit: BoxFit.cover,
)
: CachedNetworkImage(
width: width,
height: width,
fit: BoxFit.cover,
imageUrl: imageUrl!,
placeholder: (
context,
url,
) =>
const Center(
child: CircularProgressIndicator(),
),
errorWidget: (
context,
url,
error,
) =>
replacement ?? const SizedBox(),
httpHeaders: {
'Authorization':
'Bearer ${MatrixState.pangeaController.userController.accessToken}',
},
imageRenderMethodForWeb: ImageRenderMethodForWeb.HttpGet,
),
),
);
}
}