-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #82 from pvdthings/dev
Release: Item Repair Page
- Loading branch information
Showing
14 changed files
with
275 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
apps/librarian/lib/modules/things/maintenance/providers/items.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import 'package:flutter_riverpod/flutter_riverpod.dart'; | ||
import 'package:librarian_app/core/api/models/item_model.dart'; | ||
import 'package:librarian_app/modules/things/providers/items.dart'; | ||
import 'package:librarian_app/modules/things/providers/things_repository_provider.dart'; | ||
|
||
final items = Provider((ref) async { | ||
final items = await ref.watch(allItems); | ||
final things = (await ref.watch(thingsRepositoryProvider)); | ||
final hiddenMap = {for (final e in things) e.id: e.hidden}; | ||
|
||
return RepairItemsViewModel( | ||
damagedItems: items | ||
.where((item) => item.condition == damaged) | ||
.map((item) => RepairItemModel( | ||
item: item, | ||
isThingHidden: hiddenMap[item.thingId], | ||
)) | ||
.toList(), | ||
inRepairItems: items | ||
.where((item) => item.condition == inRepair) | ||
.map((item) => RepairItemModel( | ||
item: item, | ||
isThingHidden: hiddenMap[item.thingId], | ||
)) | ||
.toList(), | ||
); | ||
}); | ||
|
||
const damaged = 'Damaged'; | ||
const inRepair = 'In Repair'; | ||
|
||
class RepairItemsViewModel { | ||
const RepairItemsViewModel({ | ||
required this.damagedItems, | ||
required this.inRepairItems, | ||
}); | ||
|
||
final List<RepairItemModel> damagedItems; | ||
final List<RepairItemModel> inRepairItems; | ||
} | ||
|
||
class RepairItemModel { | ||
const RepairItemModel({ | ||
required this.item, | ||
this.isThingHidden, | ||
}); | ||
|
||
final ItemModel item; | ||
final bool? isThingHidden; | ||
} |
169 changes: 169 additions & 0 deletions
169
apps/librarian/lib/modules/things/maintenance/view.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,169 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_riverpod/flutter_riverpod.dart'; | ||
import 'package:librarian_app/modules/things/maintenance/providers/items.dart'; | ||
import 'package:librarian_app/utils/pluralize.dart'; | ||
import 'package:librarian_app/widgets/no_image.dart'; | ||
import 'package:skeletonizer/skeletonizer.dart'; | ||
|
||
import '../providers/item_details_orchestrator.dart'; | ||
|
||
class MaintenanceView extends ConsumerWidget { | ||
const MaintenanceView({super.key}); | ||
|
||
@override | ||
Widget build(BuildContext context, WidgetRef ref) { | ||
return FutureBuilder( | ||
future: ref.watch(items), | ||
builder: (context, snapshot) { | ||
final damagedItems = snapshot.data?.damagedItems ?? []; | ||
final inRepairItems = snapshot.data?.inRepairItems ?? []; | ||
|
||
return Skeletonizer( | ||
enabled: snapshot.connectionState == ConnectionState.waiting, | ||
child: MaintenanceKanban( | ||
damagedItems: damagedItems, | ||
inRepairItems: inRepairItems, | ||
onTapItem: (item) { | ||
final orchestrator = ref.read(itemDetailsOrchestrator); | ||
orchestrator.openItem( | ||
context, | ||
item: item.item, | ||
hiddenLocked: item.isThingHidden ?? false, | ||
); | ||
}, | ||
), | ||
); | ||
}, | ||
); | ||
} | ||
} | ||
|
||
class MaintenanceKanban extends StatelessWidget { | ||
const MaintenanceKanban({ | ||
super.key, | ||
required this.damagedItems, | ||
required this.inRepairItems, | ||
this.onTapItem, | ||
}); | ||
|
||
final List<RepairItemModel> damagedItems; | ||
final List<RepairItemModel> inRepairItems; | ||
final void Function(RepairItemModel)? onTapItem; | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return GridView.count( | ||
childAspectRatio: 1 / 1, | ||
crossAxisCount: 2, | ||
crossAxisSpacing: 4, | ||
children: [ | ||
KanbanColumn( | ||
title: 'Damaged', | ||
items: damagedItems, | ||
onTapItem: onTapItem, | ||
), | ||
KanbanColumn( | ||
title: 'In Repair', | ||
items: inRepairItems, | ||
onTapItem: onTapItem, | ||
), | ||
], | ||
); | ||
} | ||
} | ||
|
||
class KanbanColumn extends StatelessWidget { | ||
const KanbanColumn({ | ||
super.key, | ||
required this.title, | ||
required this.items, | ||
this.onTapItem, | ||
}); | ||
|
||
final String title; | ||
final List<RepairItemModel> items; | ||
final void Function(RepairItemModel)? onTapItem; | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Card.outlined( | ||
clipBehavior: Clip.antiAlias, | ||
color: Colors.transparent, | ||
child: Column( | ||
crossAxisAlignment: CrossAxisAlignment.start, | ||
children: [ | ||
ListTile( | ||
title: Text( | ||
title, | ||
style: Theme.of(context).textTheme.titleLarge, | ||
), | ||
trailing: Text(pluralize(items.length, 'Item')), | ||
), | ||
const Divider(height: 1), | ||
Expanded( | ||
child: Padding( | ||
padding: const EdgeInsets.all(8.0), | ||
child: GridView.count( | ||
crossAxisCount: 4, | ||
children: items | ||
.map((item) => ItemCard( | ||
number: item.item.number, | ||
imageUrl: item.item.imageUrls.firstOrNull, | ||
onTap: () => onTapItem?.call(item), | ||
)) | ||
.toList(), | ||
), | ||
), | ||
), | ||
], | ||
), | ||
); | ||
} | ||
} | ||
|
||
class ItemCard extends StatelessWidget { | ||
const ItemCard({ | ||
super.key, | ||
required this.number, | ||
this.imageUrl, | ||
this.onTap, | ||
}); | ||
|
||
final int number; | ||
final String? imageUrl; | ||
final void Function()? onTap; | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Card( | ||
clipBehavior: Clip.antiAlias, | ||
color: Theme.of(context).colorScheme.secondaryContainer, | ||
child: InkWell( | ||
onTap: onTap, | ||
child: Column( | ||
crossAxisAlignment: CrossAxisAlignment.stretch, | ||
children: [ | ||
Expanded( | ||
child: Container( | ||
color: Theme.of(context).canvasColor.withOpacity(0.5), | ||
child: imageUrl != null | ||
? Image.network( | ||
imageUrl!, | ||
fit: BoxFit.cover, | ||
) | ||
: const NoImage(), | ||
), | ||
), | ||
Padding( | ||
padding: const EdgeInsets.all(8.0), | ||
child: Text( | ||
'#$number', | ||
style: Theme.of(context).textTheme.titleMedium, | ||
), | ||
), | ||
], | ||
), | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import 'package:flutter_riverpod/flutter_riverpod.dart'; | ||
|
||
import 'things_repository_provider.dart'; | ||
|
||
final allItems = Provider((ref) async { | ||
ref.watch(thingsRepositoryProvider); | ||
return await ref.read(thingsRepositoryProvider.notifier).getItems(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
String pluralize(int count, String word) { | ||
var string = '$count $word'; | ||
|
||
if (count > 1 || count == 0) { | ||
string += 's'; | ||
} | ||
|
||
return string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters