fix: Avoid using MediaQuery.of()

This commit is contained in:
imnotlxy 2025-08-01 06:15:23 +08:00
commit d2c2fd48d4
13 changed files with 20 additions and 21 deletions

View file

@ -14,10 +14,10 @@ abstract class FluffyThemes {
width > columnWidth * 2 + navRailWidth; width > columnWidth * 2 + navRailWidth;
static bool isColumnMode(BuildContext context) => static bool isColumnMode(BuildContext context) =>
isColumnModeByWidth(MediaQuery.of(context).size.width); isColumnModeByWidth(MediaQuery.sizeOf(context).width);
static bool isThreeColumnMode(BuildContext context) => static bool isThreeColumnMode(BuildContext context) =>
MediaQuery.of(context).size.width > FluffyThemes.columnWidth * 3.5; MediaQuery.sizeOf(context).width > FluffyThemes.columnWidth * 3.5;
static LinearGradient backgroundGradient( static LinearGradient backgroundGradient(
BuildContext context, BuildContext context,

View file

@ -21,7 +21,7 @@ class ChatEmojiPicker extends StatelessWidget {
clipBehavior: Clip.hardEdge, clipBehavior: Clip.hardEdge,
decoration: const BoxDecoration(), decoration: const BoxDecoration(),
height: controller.showEmojiPicker height: controller.showEmojiPicker
? MediaQuery.of(context).size.height / 2 ? MediaQuery.sizeOf(context).height / 2
: 0, : 0,
child: controller.showEmojiPicker child: controller.showEmojiPicker
? DefaultTabController( ? DefaultTabController(

View file

@ -274,8 +274,8 @@ class ChatView extends StatelessWidget {
cacheKey: accountConfig.wallpaperUrl.toString(), cacheKey: accountConfig.wallpaperUrl.toString(),
uri: accountConfig.wallpaperUrl, uri: accountConfig.wallpaperUrl,
fit: BoxFit.cover, fit: BoxFit.cover,
height: MediaQuery.of(context).size.height, height: MediaQuery.sizeOf(context).height,
width: MediaQuery.of(context).size.width, width: MediaQuery.sizeOf(context).width,
isThumbnail: false, isThumbnail: false,
placeholder: (_) => Container(), placeholder: (_) => Container(),
), ),

View file

@ -463,8 +463,8 @@ class Message extends StatelessWidget {
colors: colors, colors: colors,
ignore: noBubble || ignore: noBubble ||
!ownMessage || !ownMessage ||
MediaQuery.of(context) MediaQuery.highContrastOf(
.highContrast, context),
scrollController: scrollController:
scrollController, scrollController,
child: Container( child: Container(

View file

@ -238,18 +238,18 @@ class MyCallingPage extends State<Calling> {
void _resizeLocalVideo(Orientation orientation) { void _resizeLocalVideo(Orientation orientation) {
final shortSide = min( final shortSide = min(
MediaQuery.of(widget.context).size.width, MediaQuery.sizeOf(widget.context).width,
MediaQuery.of(widget.context).size.height, MediaQuery.sizeOf(widget.context).height,
); );
_localVideoMargin = remoteStream != null _localVideoMargin = remoteStream != null
? const EdgeInsets.only(top: 20.0, right: 20.0) ? const EdgeInsets.only(top: 20.0, right: 20.0)
: EdgeInsets.zero; : EdgeInsets.zero;
_localVideoWidth = remoteStream != null _localVideoWidth = remoteStream != null
? shortSide / 3 ? shortSide / 3
: MediaQuery.of(widget.context).size.width; : MediaQuery.sizeOf(widget.context).width;
_localVideoHeight = remoteStream != null _localVideoHeight = remoteStream != null
? shortSide / 4 ? shortSide / 4
: MediaQuery.of(widget.context).size.height; : MediaQuery.sizeOf(widget.context).height;
} }
void _handleCallState(CallState state) { void _handleCallState(CallState state) {

View file

@ -138,10 +138,9 @@ class PIPViewState extends State<PIPView> with TickerProviderStateMixin {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final mediaQuery = MediaQuery.of(context); var windowPadding = MediaQuery.paddingOf(context);
var windowPadding = mediaQuery.padding;
if (widget.avoidKeyboard) { if (widget.avoidKeyboard) {
windowPadding += mediaQuery.viewInsets; windowPadding += MediaQuery.viewInsetsOf(context);
} }
final isFloating = _floating; final isFloating = _floating;

View file

@ -111,7 +111,7 @@ class ImageViewerController extends State<ImageViewer> {
void onInteractionEnds(ScaleEndDetails endDetails) { void onInteractionEnds(ScaleEndDetails endDetails) {
if (PlatformInfos.usesTouchscreen == false) { if (PlatformInfos.usesTouchscreen == false) {
if (endDetails.velocity.pixelsPerSecond.dy > if (endDetails.velocity.pixelsPerSecond.dy >
MediaQuery.of(context).size.height * maxScaleFactor) { MediaQuery.sizeOf(context).height * maxScaleFactor) {
Navigator.of(context, rootNavigator: false).pop(); Navigator.of(context, rootNavigator: false).pop();
} }
} }

View file

@ -127,7 +127,7 @@ class EventVideoPlayerState extends State<EventVideoPlayer> {
final infoMap = widget.event.content.tryGetMap<String, Object?>('info'); final infoMap = widget.event.content.tryGetMap<String, Object?>('info');
final videoWidth = infoMap?.tryGet<int>('w') ?? 400; final videoWidth = infoMap?.tryGet<int>('w') ?? 400;
final videoHeight = infoMap?.tryGet<int>('h') ?? 300; final videoHeight = infoMap?.tryGet<int>('h') ?? 300;
final height = MediaQuery.of(context).size.height - 52; final height = MediaQuery.sizeOf(context).height - 52;
final width = videoWidth * (height / videoHeight); final width = videoWidth * (height / videoHeight);
final chewieController = _chewieController; final chewieController = _chewieController;

View file

@ -54,7 +54,7 @@ Future<T?> showAdaptiveBottomSheet<T>({
isDismissible: isDismissible, isDismissible: isDismissible,
isScrollControlled: isScrollControlled, isScrollControlled: isScrollControlled,
constraints: BoxConstraints( constraints: BoxConstraints(
maxHeight: min(MediaQuery.of(context).size.height - 32, 600), maxHeight: min(MediaQuery.sizeOf(context).height - 32, 600),
maxWidth: FluffyThemes.columnWidth * 1.25, maxWidth: FluffyThemes.columnWidth * 1.25,
), ),
backgroundColor: Colors.transparent, backgroundColor: Colors.transparent,

View file

@ -23,7 +23,7 @@ Future<T?> showModalActionPopup<T>({
clipBehavior: Clip.hardEdge, clipBehavior: Clip.hardEdge,
constraints: BoxConstraints( constraints: BoxConstraints(
maxWidth: 512, maxWidth: 512,
maxHeight: MediaQuery.of(context).size.height - 32, maxHeight: MediaQuery.sizeOf(context).height - 32,
), ),
builder: (context) => ListView( builder: (context) => ListView(
shrinkWrap: true, shrinkWrap: true,

View file

@ -7,7 +7,7 @@ class EmptyPage extends StatelessWidget {
const EmptyPage({super.key}); const EmptyPage({super.key});
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final width = min(MediaQuery.of(context).size.width, EmptyPage._width) / 2; final width = min(MediaQuery.sizeOf(context).width, EmptyPage._width) / 2;
final theme = Theme.of(context); final theme = Theme.of(context);
return Scaffold( return Scaffold(
// Add invisible appbar to make status bar on Android tablets bright. // Add invisible appbar to make status bar on Android tablets bright.

View file

@ -73,7 +73,7 @@ class _MxcImageState extends State<MxcImage> {
final event = widget.event; final event = widget.event;
if (uri != null) { if (uri != null) {
final devicePixelRatio = MediaQuery.of(context).devicePixelRatio; final devicePixelRatio = MediaQuery.devicePixelRatioOf(context);
final width = widget.width; final width = widget.width;
final realWidth = width == null ? null : width * devicePixelRatio; final realWidth = width == null ? null : width * devicePixelRatio;
final height = widget.height; final height = widget.height;

View file

@ -35,7 +35,7 @@ class MxcImageViewer extends StatelessWidget {
maxScale: 10.0, maxScale: 10.0,
onInteractionEnd: (endDetails) { onInteractionEnd: (endDetails) {
if (endDetails.velocity.pixelsPerSecond.dy > if (endDetails.velocity.pixelsPerSecond.dy >
MediaQuery.of(context).size.height * 1.5) { MediaQuery.sizeOf(context).height * 1.5) {
Navigator.of(context, rootNavigator: false).pop(); Navigator.of(context, rootNavigator: false).pop();
} }
}, },