This repository has been archived by the owner on May 28, 2024. It is now read-only.
-
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 #80 from pvdthings/dev
Item Details
- Loading branch information
Showing
12 changed files
with
360 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_riverpod/flutter_riverpod.dart'; | ||
import 'package:librarian_app/src/features/inventory/providers/edited_item_details_providers.dart'; | ||
import 'package:librarian_app/src/features/inventory/widgets/inventory_details/items_card/item_details.dart'; | ||
|
||
import '../models/item_model.dart'; | ||
|
||
class ItemDetailsPage extends ConsumerWidget { | ||
const ItemDetailsPage({ | ||
super.key, | ||
required this.item, | ||
required this.hiddenLocked, | ||
}); | ||
|
||
final ItemModel item; | ||
final bool hiddenLocked; | ||
|
||
@override | ||
Widget build(BuildContext context, WidgetRef ref) { | ||
return WillPopScope( | ||
onWillPop: () async { | ||
ref.read(itemDetailsEditorProvider).discardChanges(); | ||
return true; | ||
}, | ||
child: Scaffold( | ||
appBar: AppBar( | ||
title: Text('#${item.number} ${item.name}'), | ||
), | ||
body: Padding( | ||
padding: const EdgeInsets.all(16.0), | ||
child: ItemDetails(item: item, hiddenLocked: hiddenLocked), | ||
), | ||
floatingActionButton: _FloatingActionSaveButton(itemId: item.id), | ||
), | ||
); | ||
} | ||
} | ||
|
||
class _FloatingActionSaveButton extends ConsumerWidget { | ||
const _FloatingActionSaveButton({required this.itemId}); | ||
|
||
final String itemId; | ||
|
||
@override | ||
Widget build(BuildContext context, WidgetRef ref) { | ||
return Visibility( | ||
visible: ref.watch(unsavedChangesProvider), | ||
child: FloatingActionButton( | ||
onPressed: ref.watch(unsavedChangesProvider) | ||
? () { | ||
ref | ||
.read(itemDetailsEditorProvider) | ||
.save(itemId) | ||
.then((_) => Navigator.of(context).pop()); | ||
} | ||
: null, | ||
child: const Icon(Icons.save), | ||
), | ||
); | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
lib/src/features/inventory/providers/edited_item_details_providers.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,46 @@ | ||
import 'package:flutter_riverpod/flutter_riverpod.dart'; | ||
import 'package:librarian_app/src/features/inventory/providers/things_repository_provider.dart'; | ||
|
||
final brandProvider = StateProvider<String?>((ref) => null); | ||
|
||
final descriptionProvider = StateProvider<String?>((ref) => null); | ||
|
||
final hiddenProvider = StateProvider<bool?>((ref) => null); | ||
|
||
final estimatedValueProvider = StateProvider<double?>((ref) => null); | ||
|
||
final conditionProvider = StateProvider<String?>((ref) => null); | ||
|
||
final unsavedChangesProvider = Provider<bool>((ref) { | ||
return ref.watch(brandProvider) != null || | ||
ref.watch(descriptionProvider) != null || | ||
ref.watch(hiddenProvider) != null || | ||
ref.watch(estimatedValueProvider) != null || | ||
ref.watch(conditionProvider) != null; | ||
}); | ||
|
||
class ItemDetailsEditor { | ||
ItemDetailsEditor(this.ref); | ||
|
||
final ProviderRef ref; | ||
|
||
Future<void> save(String id) async { | ||
await ref.read(thingsRepositoryProvider.notifier).updateItem(id, | ||
brand: ref.read(brandProvider), | ||
condition: ref.read(conditionProvider), | ||
description: ref.read(descriptionProvider), | ||
estimatedValue: ref.read(estimatedValueProvider), | ||
hidden: ref.read(hiddenProvider)); | ||
discardChanges(); | ||
} | ||
|
||
void discardChanges() { | ||
ref.read(brandProvider.notifier).state = null; | ||
ref.read(conditionProvider.notifier).state = null; | ||
ref.read(descriptionProvider.notifier).state = null; | ||
ref.read(estimatedValueProvider.notifier).state = null; | ||
ref.read(hiddenProvider.notifier).state = null; | ||
} | ||
} | ||
|
||
final itemDetailsEditorProvider = Provider((ref) => ItemDetailsEditor(ref)); |
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
111 changes: 111 additions & 0 deletions
111
lib/src/features/inventory/widgets/inventory_details/items_card/item_details.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,111 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter/services.dart'; | ||
import 'package:flutter_riverpod/flutter_riverpod.dart'; | ||
import 'package:librarian_app/src/features/common/widgets/checkbox_field.dart'; | ||
import 'package:librarian_app/src/features/common/widgets/input_decoration.widget.dart'; | ||
import 'package:librarian_app/src/features/inventory/models/item_model.dart'; | ||
import 'package:librarian_app/src/features/inventory/providers/edited_item_details_providers.dart'; | ||
import 'package:librarian_app/src/utils/format.dart'; | ||
|
||
class ItemDetails extends ConsumerWidget { | ||
const ItemDetails({ | ||
super.key, | ||
required this.item, | ||
required this.hiddenLocked, | ||
}); | ||
|
||
final ItemModel item; | ||
final bool hiddenLocked; | ||
|
||
@override | ||
Widget build(BuildContext context, WidgetRef ref) { | ||
return Column( | ||
crossAxisAlignment: CrossAxisAlignment.start, | ||
mainAxisSize: MainAxisSize.max, | ||
children: [ | ||
Builder( | ||
builder: (context) { | ||
final checkbox = CheckboxField( | ||
title: 'Hidden', | ||
value: ref.watch(hiddenProvider) ?? item.hidden, | ||
onChanged: hiddenLocked | ||
? null | ||
: (value) { | ||
ref.read(hiddenProvider.notifier).state = value; | ||
}, | ||
); | ||
|
||
if (!hiddenLocked) { | ||
return checkbox; | ||
} | ||
|
||
return Tooltip( | ||
message: 'Unable to unhide because the thing is hidden.', | ||
child: checkbox, | ||
); | ||
}, | ||
), | ||
const SizedBox(height: 24), | ||
TextFormField( | ||
controller: TextEditingController(text: item.brand), | ||
decoration: inputDecoration.copyWith( | ||
labelText: 'Brand', | ||
hintText: 'Generic', | ||
), | ||
onChanged: (value) { | ||
ref.read(brandProvider.notifier).state = value; | ||
}, | ||
), | ||
const SizedBox(height: 16), | ||
TextFormField( | ||
controller: TextEditingController(text: item.description), | ||
decoration: inputDecoration.copyWith(labelText: 'Description'), | ||
onChanged: (value) { | ||
ref.read(descriptionProvider.notifier).state = value; | ||
}, | ||
), | ||
const SizedBox(height: 16), | ||
TextFormField( | ||
controller: | ||
TextEditingController(text: formatNumber(item.estimatedValue)), | ||
decoration: inputDecoration.copyWith( | ||
labelText: 'Estimated Value (\$)', | ||
prefixText: '\$ ', | ||
), | ||
inputFormatters: [FilteringTextInputFormatter.digitsOnly], | ||
keyboardType: TextInputType.number, | ||
onChanged: (value) { | ||
ref.read(estimatedValueProvider.notifier).state = | ||
double.tryParse(value); | ||
}, | ||
), | ||
const SizedBox(height: 16), | ||
DropdownButtonFormField( | ||
decoration: inputDecoration.copyWith(labelText: 'Condition'), | ||
items: const [ | ||
DropdownMenuItem( | ||
value: 'Like New', | ||
child: Text('Like New'), | ||
), | ||
DropdownMenuItem( | ||
value: 'Lightly Used', | ||
child: Text('Lightly Used'), | ||
), | ||
DropdownMenuItem( | ||
value: 'Heavily Used', | ||
child: Text('Heavily Used'), | ||
), | ||
DropdownMenuItem( | ||
value: 'Damaged', | ||
child: Text('Damaged'), | ||
), | ||
], | ||
onChanged: (value) { | ||
ref.read(conditionProvider.notifier).state = value; | ||
}, | ||
value: item.condition, | ||
), | ||
], | ||
); | ||
} | ||
} |
Oops, something went wrong.
df65408
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
librarian-app – ./
librarian-app-pvdthings.vercel.app
librarian-app.vercel.app
librarian-app-git-main-pvdthings.vercel.app