Skip to content

Commit

Permalink
use error text instead of existing item dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
dillonfagan committed Nov 18, 2024
1 parent a001634 commit 7bec2c0
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class ConnectedThingSearchField extends StatelessWidget {

class ThingSearchController extends ChangeNotifier {
final BuildContext context;
final List<ItemModel> items;
final InventoryRepository repository;
final void Function(ItemModel) onMatchFound;

Expand All @@ -61,13 +62,22 @@ class ThingSearchController extends ChangeNotifier {

ThingSearchController({
required this.context,
required this.items,
required this.repository,
required this.onMatchFound,
});

Future<void> search(String value) async {
final itemNumber = int.parse(value);

if (items.any((t) => t.number == itemNumber)) {
errorText = '#$value is already added to this loan.';
notifyListeners();
return;
}

isLoading = true;
final match = await repository.getItem(number: int.parse(value));
final match = await repository.getItem(number: itemNumber);
isLoading = false;

if (match == null) {
Expand All @@ -79,8 +89,9 @@ class ThingSearchController extends ChangeNotifier {
if (!match.available) {
errorText = '#$value is unavailable.';
notifyListeners();
} else {
onMatchFound(match);
return;
}

onMatchFound(match);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import 'package:librarian_app/modules/things/providers/things_repository_provide
import 'package:librarian_app/widgets/item_card.dart';

import 'connected_thing_search_field.dart';
import 'existing_item_dialog.dart';
import 'eye_protection_dialog.dart';
import 'suggested_things_dialog.dart';

Expand All @@ -27,33 +26,24 @@ Step buildItemsStep({
ConnectedThingSearchField(
controller: ThingSearchController(
context: context,
onMatchFound: (thing) {
if (items.any((t) => t.id == thing.id)) {
showDialog(
context: context,
builder: (context) {
return ExistingItemDialog(number: thing.number);
},
);
return;
}

onAddItem(thing);
items: items,
onMatchFound: (item) {
onAddItem(item);

if (thing.eyeProtection && !didPromptForEyeProtection) {
if (item.eyeProtection && !didPromptForEyeProtection) {
showDialog(
context: context,
builder: (_) => const EyeProtectionDialog(),
);
onPromptForEyeProtection();
}

if (thing.linkedThingIds.isNotEmpty) {
if (item.linkedThingIds.isNotEmpty) {
showDialog(
context: context,
builder: (_) => SuggestedThingsDialog(
thingName: thing.name,
thingIds: thing.linkedThingIds,
thingName: item.name,
thingIds: item.linkedThingIds,
),
);
}
Expand Down

0 comments on commit 7bec2c0

Please sign in to comment.