Skip to content

Commit

Permalink
⚡️ Improved grid performance
Browse files Browse the repository at this point in the history
  • Loading branch information
LNA-DEV committed Nov 1, 2024
1 parent e5a63d7 commit f33ab54
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
9 changes: 5 additions & 4 deletions lib/views/gallery.dart
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import 'package:flutter/material.dart';
import 'package:open_media_server_app/apis/inventory_api.dart';
import 'package:open_media_server_app/apis/metadata_api.dart';
import 'package:open_media_server_app/globals/globals.dart';
import 'package:open_media_server_app/models/internal/grid_item_model.dart';
import 'package:open_media_server_app/models/metadata/metadata_model.dart';
import 'package:open_media_server_app/widgets/gallery_item.dart';
import 'package:open_media_server_app/widgets/grid_item.dart';
import 'package:open_media_server_app/views/detail_views/movie_detail.dart';
import 'package:open_media_server_app/views/player.dart';
import 'package:open_media_server_app/views/detail_views/show_detail.dart';

class Gallery extends StatelessWidget {
Expand Down Expand Up @@ -48,7 +46,10 @@ class Gallery extends StatelessWidget {
),
itemBuilder: (context, index) {
return InkWell(
child: GridItem(item: items[index]),
child: GridItem(
item: items[index],
desiredItemWidth: desiredItemWidth,
),
onTap: () {
Navigator.push(
context,
Expand Down
8 changes: 7 additions & 1 deletion lib/widgets/custom_image.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,14 @@ class CustomImage extends StatelessWidget {

@override
Widget build(BuildContext context) {
String addon = "";

if (width?.isFinite ?? false) {
addon = "?width=${width?.floor()}";
}

return CachedNetworkImage(
imageUrl: imageUrl,
imageUrl: "$imageUrl$addon",
fit: fit,
width: width,
height: height,
Expand Down
6 changes: 4 additions & 2 deletions lib/widgets/gallery_item.dart → lib/widgets/grid_item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import 'package:open_media_server_app/widgets/custom_image.dart';
class GridItem extends StatelessWidget {
final GridItemModel item;

const GridItem({Key? key, required this.item}) : super(key: key);
const GridItem({Key? key, required this.item, required this.desiredItemWidth}) : super(key: key);

final double desiredItemWidth;

@override
Widget build(BuildContext context) {
Expand All @@ -19,7 +21,7 @@ class GridItem extends StatelessWidget {
child: CustomImage(
imageUrl: item.posterUrl ?? Globals.PictureNotFoundUrl,
fit: BoxFit.cover,
width: double.infinity,
width: desiredItemWidth + 150,
),
),
),
Expand Down

0 comments on commit f33ab54

Please sign in to comment.