2
0
mirror of https://github.com/inventree/inventree-app.git synced 2025-04-28 05:26:47 +00:00

Remove typeahead library

This commit is contained in:
Oliver 2021-07-26 23:04:43 +10:00
parent 978cefd6bf
commit 08eb6fc4b1
6 changed files with 71 additions and 85 deletions

View File

@ -187,6 +187,7 @@ class APIFormField {
label: label, label: label,
hint: helpText, hint: helpText,
onChanged: null, onChanged: null,
autoFocusSearchBox: true,
showClearButton: !required, showClearButton: !required,
itemAsString: (dynamic item) { itemAsString: (dynamic item) {
return item['display_name']; return item['display_name'];

View File

@ -285,11 +285,17 @@ class InvenTreeModel {
return results; return results;
} }
// TODO - handle possible error cases: dynamic data;
// - No data receieved
// - Data is not a list of maps
for (var d in response.data) { if (response.data is List) {
data = response.data;
} else if (response.data.containsKey('results')) {
data = response.data['results'];
} else {
data = [];
}
for (var d in data) {
// Create a new object (of the current class type // Create a new object (of the current class type
InvenTreeModel obj = createFromJson(d); InvenTreeModel obj = createFromJson(d);

View File

@ -1,9 +1,6 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_typeahead/flutter_typeahead.dart';
import 'package:image_picker/image_picker.dart'; import 'package:image_picker/image_picker.dart';
import 'package:inventree/api.dart';
import 'package:inventree/l10.dart'; import 'package:inventree/l10.dart';
import 'dart:async'; import 'dart:async';

View File

@ -1,4 +1,5 @@
import 'package:inventree/barcode.dart'; import 'package:inventree/barcode.dart';
import 'package:inventree/inventree/model.dart';
import 'package:inventree/inventree/stock.dart'; import 'package:inventree/inventree/stock.dart';
import 'package:inventree/inventree/part.dart'; import 'package:inventree/inventree/part.dart';
import 'package:inventree/widget/dialogs.dart'; import 'package:inventree/widget/dialogs.dart';
@ -17,7 +18,7 @@ import 'package:inventree/l10.dart';
import 'package:inventree/api.dart'; import 'package:inventree/api.dart';
import 'package:flutter_typeahead/flutter_typeahead.dart'; import 'package:dropdown_search/dropdown_search.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import '../api_form.dart'; import '../api_form.dart';
@ -270,7 +271,7 @@ class _StockItemDisplayState extends RefreshableState<StockDetailWidget> {
} }
void _transferStock(InvenTreeStockLocation location) async { void _transferStock(int locationId) async {
double quantity = double.tryParse(_quantityController.text) ?? item.quantity; double quantity = double.tryParse(_quantityController.text) ?? item.quantity;
String notes = _notesController.text; String notes = _notesController.text;
@ -278,7 +279,7 @@ class _StockItemDisplayState extends RefreshableState<StockDetailWidget> {
_quantityController.clear(); _quantityController.clear();
_notesController.clear(); _notesController.clear();
var result = await item.transferStock(location.pk, quantity: quantity, notes: notes); var result = await item.transferStock(locationId, quantity: quantity, notes: notes);
refresh(); refresh();
@ -287,22 +288,22 @@ class _StockItemDisplayState extends RefreshableState<StockDetailWidget> {
} }
} }
void _transferStockDialog() async { void _transferStockDialog(BuildContext context) async {
var locations = await InvenTreeStockLocation().list(); var locations = await InvenTreeStockLocation().list();
final _selectedController = TextEditingController(); final _selectedController = TextEditingController();
InvenTreeStockLocation? selectedLocation; int? location_pk;
_quantityController.text = "${item.quantityString}"; _quantityController.text = "${item.quantityString}";
showFormDialog(L10().transferStock, showFormDialog(L10().transferStock,
key: _moveStockKey, key: _moveStockKey,
callback: () { callback: () {
var _loc = selectedLocation; var _pk = location_pk;
if (_loc != null) { if (_pk != null) {
_transferStock(_loc); _transferStock(_pk);
} }
}, },
fields: <Widget>[ fields: <Widget>[
@ -311,47 +312,57 @@ class _StockItemDisplayState extends RefreshableState<StockDetailWidget> {
controller: _quantityController, controller: _quantityController,
max: item.quantity, max: item.quantity,
), ),
TypeAheadFormField( DropdownSearch<dynamic>(
textFieldConfiguration: TextFieldConfiguration( mode: Mode.BOTTOM_SHEET,
controller: _selectedController, showSelectedItem: false,
autofocus: true, autoFocusSearchBox: true,
decoration: InputDecoration( selectedItem: null,
hintText: L10().searchLocation, errorBuilder: (context, entry, exception) {
border: OutlineInputBorder() print("entry: $entry");
) print(exception.toString());
),
suggestionsCallback: (pattern) async {
List<InvenTreeStockLocation> suggestions = [];
for (var loc in locations) { return Text(
if (loc.matchAgainstString(pattern)) { exception.toString(),
suggestions.add(loc as InvenTreeStockLocation); style: TextStyle(
} fontSize: 10,
)
);
},
onFind: (String filter) async {
Map<String, String> _filters = {
"search": filter,
"offset": "0",
"limit": "25"
};
final List<InvenTreeModel> results = await InvenTreeStockLocation().list(filters: _filters);
List<dynamic> items = [];
for (InvenTreeModel loc in results) {
if (loc is InvenTreeStockLocation) {
items.add(loc.jsondata);
} }
return suggestions;
},
validator: (value) {
if (selectedLocation == null) {
return L10().selectLocation;
}
return null;
},
onSuggestionSelected: (suggestion) {
selectedLocation = suggestion as InvenTreeStockLocation;
_selectedController.text = selectedLocation!.pathstring;
},
onSaved: (value) {
},
itemBuilder: (context, suggestion) {
var location = suggestion as InvenTreeStockLocation;
return ListTile(
title: Text("${location.pathstring}"),
subtitle: Text("${location.description}"),
);
} }
return items;
},
label: L10().stockLocation,
hint: L10().searchLocation,
onChanged: null,
itemAsString: (dynamic location) {
return location['pathstring'];
},
onSaved: (dynamic location) {
if (location == null) {
location_pk = null;
} else {
location_pk = location['pk'];
}
},
isFilteredOnline: true,
showSearchBox: true,
), ),
], ],
); );
@ -556,7 +567,7 @@ class _StockItemDisplayState extends RefreshableState<StockDetailWidget> {
return tiles; return tiles;
} }
List<Widget> actionTiles() { List<Widget> actionTiles(BuildContext context) {
List<Widget> tiles = []; List<Widget> tiles = [];
tiles.add(headerTile()); tiles.add(headerTile());
@ -610,7 +621,7 @@ class _StockItemDisplayState extends RefreshableState<StockDetailWidget> {
ListTile( ListTile(
title: Text(L10().transferStock), title: Text(L10().transferStock),
leading: FaIcon(FontAwesomeIcons.exchangeAlt), leading: FaIcon(FontAwesomeIcons.exchangeAlt),
onTap: _transferStockDialog, onTap: () { _transferStockDialog(context); },
) )
); );
@ -694,7 +705,7 @@ class _StockItemDisplayState extends RefreshableState<StockDetailWidget> {
return ListView( return ListView(
children: ListTile.divideTiles( children: ListTile.divideTiles(
context: context, context: context,
tiles: actionTiles() tiles: actionTiles(context)
).toList() ).toList()
); );
default: default:

View File

@ -174,27 +174,6 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "3.1.2" version: "3.1.2"
flutter_keyboard_visibility:
dependency: transitive
description:
name: flutter_keyboard_visibility
url: "https://pub.dartlang.org"
source: hosted
version: "5.0.2"
flutter_keyboard_visibility_platform_interface:
dependency: transitive
description:
name: flutter_keyboard_visibility_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.0"
flutter_keyboard_visibility_web:
dependency: transitive
description:
name: flutter_keyboard_visibility_web
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.0"
flutter_launcher_icons: flutter_launcher_icons:
dependency: "direct dev" dependency: "direct dev"
description: description:
@ -233,13 +212,6 @@ packages:
description: flutter description: flutter
source: sdk source: sdk
version: "0.0.0" version: "0.0.0"
flutter_typeahead:
dependency: "direct main"
description:
name: flutter_typeahead
url: "https://pub.dartlang.org"
source: hosted
version: "3.1.3"
flutter_web_plugins: flutter_web_plugins:
dependency: transitive dependency: transitive
description: flutter description: flutter

View File

@ -30,7 +30,6 @@ dependencies:
font_awesome_flutter: ^9.1.0 # FontAwesome icon set font_awesome_flutter: ^9.1.0 # FontAwesome icon set
flutter_speed_dial: ^3.0.5 # FAB menu elements flutter_speed_dial: ^3.0.5 # FAB menu elements
sentry_flutter: 5.0.0 # Error reporting sentry_flutter: 5.0.0 # Error reporting
flutter_typeahead: ^3.1.0 # Auto-complete input field
image_picker: ^0.8.0 # Select or take photos image_picker: ^0.8.0 # Select or take photos
url_launcher: 6.0.0 # Open link in system browser url_launcher: 6.0.0 # Open link in system browser
flutter_markdown: ^0.6.2 # Rendering markdown flutter_markdown: ^0.6.2 # Rendering markdown