mirror of
https://github.com/inventree/inventree-app.git
synced 2025-04-28 05:26:47 +00:00
Expansion state is now saved on the session level, not per widget
This commit is contained in:
parent
c7fbe99f53
commit
aa8a3602e8
@ -27,7 +27,7 @@ void main() async {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
|
||||
// Load login details
|
||||
InvenTreeUserPreferences().loadLoginDetails();
|
||||
InvenTreePreferences().loadLoginDetails();
|
||||
|
||||
runApp(MyApp());
|
||||
}
|
||||
|
@ -2,20 +2,37 @@ import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'api.dart';
|
||||
|
||||
|
||||
class InvenTreeUserPreferences {
|
||||
class InvenTreePreferences {
|
||||
|
||||
static const String _SERVER = 'server';
|
||||
static const String _USERNAME = 'username';
|
||||
static const String _PASSWORD = 'password';
|
||||
|
||||
// Ensure we only ever create a single instance of the preferences class
|
||||
static final InvenTreeUserPreferences _api = new InvenTreeUserPreferences._internal();
|
||||
/* The following settings are not stored to persistent storage,
|
||||
* instead they are only used as 'session preferences'.
|
||||
* They are kept here as a convenience only.
|
||||
*/
|
||||
|
||||
factory InvenTreeUserPreferences() {
|
||||
// Expand subcategory list in PartCategory view
|
||||
bool expandCategoryList = false;
|
||||
|
||||
// Expand part list in PartCategory view
|
||||
bool expandPartList = true;
|
||||
|
||||
// Expand sublocation list in StockLocation view
|
||||
bool expandLocationList = false;
|
||||
|
||||
// Expand item list in StockLocation view
|
||||
bool expandStockList = true;
|
||||
|
||||
// Ensure we only ever create a single instance of the preferences class
|
||||
static final InvenTreePreferences _api = new InvenTreePreferences._internal();
|
||||
|
||||
factory InvenTreePreferences() {
|
||||
return _api;
|
||||
}
|
||||
|
||||
InvenTreeUserPreferences._internal();
|
||||
InvenTreePreferences._internal();
|
||||
|
||||
// Load saved login details, and attempt connection
|
||||
void loadLoginDetails() async {
|
||||
|
@ -130,7 +130,7 @@ class _InvenTreeLoginSettingsState extends State<InvenTreeLoginSettingsWidget> {
|
||||
if (_formKey.currentState.validate()) {
|
||||
_formKey.currentState.save();
|
||||
|
||||
await InvenTreeUserPreferences().saveLoginDetails(_server, _username, _password);
|
||||
await InvenTreePreferences().saveLoginDetails(_server, _username, _password);
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
|
||||
import 'package:InvenTree/api.dart';
|
||||
import 'package:InvenTree/inventree/part.dart';
|
||||
import 'package:InvenTree/preferences.dart';
|
||||
|
||||
import 'package:InvenTree/widget/part_display.dart';
|
||||
import 'package:InvenTree/widget/drawer.dart';
|
||||
@ -83,9 +84,6 @@ class _CategoryDisplayState extends State<CategoryDisplayWidget> {
|
||||
});
|
||||
}
|
||||
|
||||
bool _subcategoriesExpanded = false;
|
||||
bool _partListExpanded = true;
|
||||
|
||||
Widget getCategoryDescriptionCard() {
|
||||
if (category == null) {
|
||||
return Card(
|
||||
@ -144,10 +142,10 @@ class _CategoryDisplayState extends State<CategoryDisplayWidget> {
|
||||
|
||||
switch (index) {
|
||||
case 0:
|
||||
_subcategoriesExpanded = !isExpanded;
|
||||
InvenTreePreferences().expandCategoryList = !isExpanded;
|
||||
break;
|
||||
case 1:
|
||||
_partListExpanded = !isExpanded;
|
||||
InvenTreePreferences().expandPartList = !isExpanded;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@ -163,13 +161,13 @@ class _CategoryDisplayState extends State<CategoryDisplayWidget> {
|
||||
trailing: Text("${_subcategories.length}"),
|
||||
onTap: () {
|
||||
setState(() {
|
||||
_subcategoriesExpanded = !_subcategoriesExpanded;
|
||||
InvenTreePreferences().expandCategoryList = !InvenTreePreferences().expandCategoryList;
|
||||
});
|
||||
},
|
||||
);
|
||||
},
|
||||
body: SubcategoryList(_subcategories),
|
||||
isExpanded: _subcategoriesExpanded && _subcategories.length > 0,
|
||||
isExpanded: InvenTreePreferences().expandCategoryList && _subcategories.length > 0,
|
||||
),
|
||||
ExpansionPanel(
|
||||
headerBuilder: (BuildContext context, bool isExpanded) {
|
||||
@ -179,13 +177,13 @@ class _CategoryDisplayState extends State<CategoryDisplayWidget> {
|
||||
trailing: Text("${_parts.length}"),
|
||||
onTap: () {
|
||||
setState(() {
|
||||
_partListExpanded = !_partListExpanded;
|
||||
InvenTreePreferences().expandPartList = !InvenTreePreferences().expandPartList;
|
||||
});
|
||||
},
|
||||
);
|
||||
},
|
||||
body: PartList(_parts),
|
||||
isExpanded: _partListExpanded && _parts.length > 0,
|
||||
isExpanded: InvenTreePreferences().expandPartList && _parts.length > 0,
|
||||
)
|
||||
],
|
||||
),
|
||||
|
@ -1,5 +1,6 @@
|
||||
import 'package:InvenTree/api.dart';
|
||||
import 'package:InvenTree/inventree/stock.dart';
|
||||
import 'package:InvenTree/preferences.dart';
|
||||
import 'package:InvenTree/widget/drawer.dart';
|
||||
import 'package:InvenTree/widget/stock_display.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
@ -91,9 +92,6 @@ class _LocationDisplayState extends State<LocationDisplayWidget> {
|
||||
});
|
||||
}
|
||||
|
||||
bool _locationListExpanded = false;
|
||||
bool _stockListExpanded = true;
|
||||
|
||||
Widget locationDescriptionCard() {
|
||||
if (location == null) {
|
||||
return Card(
|
||||
@ -150,10 +148,10 @@ class _LocationDisplayState extends State<LocationDisplayWidget> {
|
||||
setState(() {
|
||||
switch (index) {
|
||||
case 0:
|
||||
_locationListExpanded = !isExpanded;
|
||||
InvenTreePreferences().expandLocationList = !isExpanded;
|
||||
break;
|
||||
case 1:
|
||||
_stockListExpanded = !isExpanded;
|
||||
InvenTreePreferences().expandStockList = !isExpanded;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@ -170,13 +168,13 @@ class _LocationDisplayState extends State<LocationDisplayWidget> {
|
||||
trailing: Text("${_sublocations.length}"),
|
||||
onTap: () {
|
||||
setState(() {
|
||||
_locationListExpanded = !_locationListExpanded;
|
||||
InvenTreePreferences().expandLocationList = !InvenTreePreferences().expandLocationList;
|
||||
});
|
||||
},
|
||||
);
|
||||
},
|
||||
body: SublocationList(_sublocations),
|
||||
isExpanded: _locationListExpanded && _sublocations.length > 0,
|
||||
isExpanded: InvenTreePreferences().expandLocationList && _sublocations.length > 0,
|
||||
),
|
||||
ExpansionPanel(
|
||||
headerBuilder: (BuildContext context, bool isExpanded) {
|
||||
@ -186,13 +184,13 @@ class _LocationDisplayState extends State<LocationDisplayWidget> {
|
||||
trailing: Text("${_items.length}"),
|
||||
onTap: () {
|
||||
setState(() {
|
||||
_stockListExpanded = !_stockListExpanded;
|
||||
InvenTreePreferences().expandStockList = !InvenTreePreferences().expandStockList;
|
||||
});
|
||||
},
|
||||
);
|
||||
},
|
||||
body: StockList(_items),
|
||||
isExpanded: _stockListExpanded && _items.length > 0,
|
||||
isExpanded: InvenTreePreferences().expandStockList && _items.length > 0,
|
||||
)
|
||||
]
|
||||
),
|
||||
|
Loading…
x
Reference in New Issue
Block a user