Skip to content

Commit

Permalink
⚡️ Improved grid loading
Browse files Browse the repository at this point in the history
  • Loading branch information
LNA-DEV committed Nov 7, 2024
1 parent 9ff37cb commit a1f21ce
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 33 deletions.
1 change: 1 addition & 0 deletions lib/models/internal/grid_item_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class GridItemModel {
String? backdropUrl;
List<String>? childIds;
int? listPosition;
bool fake = false;

GridItemModel({
required this.inventoryItem,
Expand Down
79 changes: 46 additions & 33 deletions lib/views/gallery.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Gallery extends StatelessWidget {

@override
Widget build(BuildContext context) {
var futureItems = getGridItems();
var futureItems = getInventoryItems();

double screenWidth = MediaQuery.of(context).size.width;
double desiredItemWidth = 150;
Expand Down Expand Up @@ -47,44 +47,57 @@ class Gallery extends StatelessWidget {
childAspectRatio: 0.7, // Adjust for desired aspect ratio
),
itemBuilder: (context, index) {
var gridItemFake = GridItemModel(
inventoryItem: items[index],
metadataModel: null,
);

gridItemFake.posterUrl =
"${Preferences.prefs?.getString("BaseUrl")}/images/${items[index].category}/${items[index].metadataId}/poster";

return InkWell(
child: GridItem(
item: gridItemFake,
desiredItemWidth: desiredItemWidth,
),
onTap: () async {
return FutureBuilder<GridItemModel>(
future: items[index].category == "Movie"
? getMovie(items[index])
: getShow(items[index]),
builder: (context, snapshot) {
GridItemModel gridItem;

if (items[index].category == "Movie") {
gridItem = await getMovie(items[index]);
if (snapshot.connectionState == ConnectionState.waiting) {
gridItem = GridItemModel(
inventoryItem: items[index],
metadataModel: null,
);

gridItem.fake = true;
gridItem.posterUrl =
"${Preferences.prefs?.getString("BaseUrl")}/images/${items[index].category}/${items[index].metadataId}/poster";
} else if (snapshot.hasError) {
return Center(child: Text('Error: ${snapshot.error}'));
} else if (!snapshot.hasData) {
return const Center(
child: Text('Grid item could not be loaded'));
} else {
gridItem = await getShow(items[index]);
gridItem = snapshot.data!;
}

Navigator.push(
context,
MaterialPageRoute(builder: (context) {
if (items[index].category == "Movie") {
return MovieDetailView(
itemModel: gridItem,
return InkWell(
child: GridItem(
item: gridItem,
desiredItemWidth: desiredItemWidth,
),
onTap: () {
if (!gridItem.fake) {
Navigator.push(
context,
MaterialPageRoute(builder: (context) {
if (items[index].category == "Movie") {
return MovieDetailView(
itemModel: gridItem,
);
}
if (items[index].category == "Show") {
return ShowDetailView(
itemModel: gridItem,
);
}

throw ArgumentError("Server models not correct");
}),
);
}
if (items[index].category == "Show") {
return ShowDetailView(
itemModel: gridItem,
);
}

throw ArgumentError("Server models not correct");
}),
},
);
},
);
Expand All @@ -95,7 +108,7 @@ class Gallery extends StatelessWidget {
);
}

Future<List<InventoryItem>> getGridItems() async {
Future<List<InventoryItem>> getInventoryItems() async {
InventoryApi inventoryApi = InventoryApi();

var items = await inventoryApi.listItems("Movie");
Expand Down

0 comments on commit a1f21ce

Please sign in to comment.