-
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 #68 from pvdthings/dev
Release: Librarian - Automatically Hide Damaged Item
- Loading branch information
Showing
4 changed files
with
140 additions
and
44 deletions.
There are no files selected for viewing
86 changes: 86 additions & 0 deletions
86
apps/librarian/lib/modules/things/details/inventory/item_details/condition_dropdown.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,86 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:librarian_app/widgets/hint_text.dart'; | ||
|
||
class ConditionDropdown extends StatelessWidget { | ||
const ConditionDropdown({ | ||
super.key, | ||
required this.editable, | ||
required this.onChanged, | ||
required this.value, | ||
}); | ||
|
||
final bool editable; | ||
final String? value; | ||
final void Function(ConditionDropdownOption?) onChanged; | ||
|
||
static final options = [ | ||
ConditionDropdownOption( | ||
label: 'None', | ||
value: null, | ||
), | ||
ConditionDropdownOption( | ||
label: 'Like New', | ||
value: 'Like New', | ||
), | ||
ConditionDropdownOption( | ||
label: 'Lightly Used', | ||
value: 'Lightly Used', | ||
), | ||
ConditionDropdownOption( | ||
label: 'Heavily Used', | ||
value: 'Heavily Used', | ||
), | ||
ConditionDropdownOption( | ||
label: 'Damaged', | ||
value: 'Damaged', | ||
hidden: true, | ||
), | ||
ConditionDropdownOption( | ||
label: 'In Repair', | ||
value: 'In Repair', | ||
hidden: true, | ||
), | ||
]; | ||
|
||
static bool isDamagedCondition(String? value) { | ||
return value == 'Damaged' || value == 'In Repair'; | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return DropdownButtonFormField<ConditionDropdownOption>( | ||
decoration: const InputDecoration( | ||
labelText: 'Condition', | ||
), | ||
items: editable | ||
? options | ||
.map((option) => DropdownMenuItem( | ||
value: option, | ||
child: Row( | ||
children: [ | ||
Text(option.label), | ||
const SizedBox(width: 16.0), | ||
if (option.hidden != null && option.hidden!) | ||
const HintText('Hidden'), | ||
], | ||
), | ||
)) | ||
.toList() | ||
: null, | ||
onChanged: onChanged, | ||
value: options.firstWhere((i) => i.value == value), | ||
); | ||
} | ||
} | ||
|
||
class ConditionDropdownOption { | ||
final String label; | ||
final String? value; | ||
final bool? hidden; | ||
|
||
ConditionDropdownOption({ | ||
required this.label, | ||
required this.value, | ||
this.hidden, | ||
}); | ||
} |
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