Skip to content

Commit

Permalink
Improved code
Browse files Browse the repository at this point in the history
Use MediaQuery.sizeOf(context) instead of MediaQuery.of(context).size to avoid unwanted rebuilding
  • Loading branch information
gokadzev committed Sep 4, 2024
1 parent e40469d commit a902844
Show file tree
Hide file tree
Showing 8 changed files with 11 additions and 11 deletions.
6 changes: 3 additions & 3 deletions lib/screens/home_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ class _HomePageState extends State<HomePage> {
}

Widget _buildPlaylistSection(BuildContext context, List<dynamic> playlists) {
final playlistHeight = MediaQuery.of(context).size.height * 0.25 / 1.1;
final playlistHeight = MediaQuery.sizeOf(context).height * 0.25 / 1.1;

return Column(
children: [
Expand Down Expand Up @@ -240,7 +240,7 @@ class _HomePageState extends State<HomePage> {
required List<dynamic> data,
bool showArtists = true,
}) {
final contentHeight = MediaQuery.of(context).size.height * 0.25;
final contentHeight = MediaQuery.sizeOf(context).height * 0.25;

return Column(
children: [
Expand Down Expand Up @@ -313,7 +313,7 @@ class _HomePageState extends State<HomePage> {
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
SizedBox(
width: MediaQuery.of(context).size.width * 0.7,
width: MediaQuery.sizeOf(context).width * 0.7,
child: MarqueeWidget(
child: Text(
title,
Expand Down
2 changes: 1 addition & 1 deletion lib/screens/now_playing_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class NowPlayingPage extends StatelessWidget {

@override
Widget build(BuildContext context) {
final size = MediaQuery.of(context).size;
final size = MediaQuery.sizeOf(context);

return Scaffold(
appBar: AppBar(backgroundColor: Colors.transparent),
Expand Down
4 changes: 2 additions & 2 deletions lib/screens/playlist_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ class _PlaylistPageState extends State<PlaylistPage> {
],
)
: SizedBox(
height: MediaQuery.of(context).size.height - 100,
height: MediaQuery.sizeOf(context).height - 100,
child: const Spinner(),
),
);
Expand All @@ -172,7 +172,7 @@ class _PlaylistPageState extends State<PlaylistPage> {
Widget _buildPlaylistImage() {
return PlaylistCube(
_playlist,
size: MediaQuery.of(context).size.width / 2.5,
size: MediaQuery.sizeOf(context).width / 2.5,
onClickOpen: false,
cubeIcon: widget.cubeIcon,
showFavoriteButton: false,
Expand Down
2 changes: 1 addition & 1 deletion lib/screens/user_songs_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ class _UserSongsPageState extends State<UserSongsPage> {
{'title': title},
onClickOpen: false,
showFavoriteButton: false,
size: MediaQuery.of(context).size.width / 2.5,
size: MediaQuery.sizeOf(context).width / 2.5,
cubeIcon: icon,
);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/services/update_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ Future<void> checkAppUpdates() async {
const SizedBox(height: 10),
ConstrainedBox(
constraints: BoxConstraints(
maxHeight: MediaQuery.of(context).size.height / 2.14,
maxHeight: MediaQuery.sizeOf(context).height / 2.14,
),
child: SingleChildScrollView(
child: AutoFormatText(text: releasesResponse['body']),
Expand Down
2 changes: 1 addition & 1 deletion lib/utilities/flutter_bottom_sheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import 'package:fluentui_system_icons/fluentui_system_icons.dart';
import 'package:flutter/material.dart';

void showCustomBottomSheet(BuildContext context, Widget content) {
final size = MediaQuery.of(context).size;
final size = MediaQuery.sizeOf(context);
showBottomSheet(
enableDrag: true,
context: context,
Expand Down
2 changes: 1 addition & 1 deletion lib/widgets/playlist_header.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class PlaylistHeader extends StatelessWidget {
image,
const SizedBox(width: 10),
SizedBox(
width: MediaQuery.of(context).size.width / 2.3,
width: MediaQuery.sizeOf(context).width / 2.3,
child: Column(
children: [
Text(
Expand Down
2 changes: 1 addition & 1 deletion lib/widgets/song_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ void showAddToPlaylistDialog(BuildContext context, dynamic song) {
content: Container(
width: double.maxFinite,
constraints: BoxConstraints(
maxHeight: MediaQuery.of(context).size.height * 0.6,
maxHeight: MediaQuery.sizeOf(context).height * 0.6,
),
child: userCustomPlaylists.isNotEmpty
? ListView.builder(
Expand Down

0 comments on commit a902844

Please sign in to comment.