feat: enhance ProductPickerField to use rawName for initial query in receipt import
This commit is contained in:
@@ -91,6 +91,7 @@ class ProductPickerField extends StatelessWidget {
|
||||
}
|
||||
|
||||
Future<void> _openPicker(BuildContext context) async {
|
||||
// Skapa controller utanför showSheet för att undvika reset vid rebuild
|
||||
final result = await ProductPickerField.showSheet(
|
||||
context,
|
||||
products: products,
|
||||
@@ -121,6 +122,8 @@ class ProductPickerField extends StatelessWidget {
|
||||
isScrollControlled: true,
|
||||
useSafeArea: true,
|
||||
builder: (sheetContext) {
|
||||
// Skapa controller EN gång per öppnad ark — inte inuti StatefulBuilder
|
||||
final controller = TextEditingController(text: initialQuery ?? '');
|
||||
var query = initialQuery ?? '';
|
||||
|
||||
return StatefulBuilder(
|
||||
@@ -155,7 +158,7 @@ class ProductPickerField extends StatelessWidget {
|
||||
padding: const EdgeInsets.fromLTRB(16, 0, 16, 8),
|
||||
child: TextField(
|
||||
autofocus: true,
|
||||
controller: TextEditingController(text: initialQuery ?? ''),
|
||||
controller: controller,
|
||||
decoration: const InputDecoration(
|
||||
hintText: 'Sök produkt...',
|
||||
prefixIcon: Icon(Icons.search),
|
||||
|
||||
@@ -98,13 +98,14 @@ class _EditDialogState extends State<_EditDialog> {
|
||||
_productName = item.suggestedProductName;
|
||||
});
|
||||
} else if (aiCategory != null) {
|
||||
// Öppna pickern med kategorinamnet sökt
|
||||
// Öppna pickern med råtexten från kvittot som sökord — kategorinamnet
|
||||
// matchar inte produktnamn, men rawName gör det troligtvis
|
||||
ProductPickerField.showSheet(
|
||||
context,
|
||||
products: widget.products,
|
||||
value: _productId,
|
||||
label: 'Produkt',
|
||||
initialQuery: aiCategory,
|
||||
initialQuery: item.rawName,
|
||||
).then((id) {
|
||||
if (id != null && mounted) {
|
||||
setState(() {
|
||||
|
||||
Reference in New Issue
Block a user