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();
|
WidgetsFlutterBinding.ensureInitialized();
|
||||||
|
|
||||||
// Load login details
|
// Load login details
|
||||||
InvenTreeUserPreferences().loadLoginDetails();
|
InvenTreePreferences().loadLoginDetails();
|
||||||
|
|
||||||
runApp(MyApp());
|
runApp(MyApp());
|
||||||
}
|
}
|
||||||
|
@ -2,20 +2,37 @@ import 'package:shared_preferences/shared_preferences.dart';
|
|||||||
import 'api.dart';
|
import 'api.dart';
|
||||||
|
|
||||||
|
|
||||||
class InvenTreeUserPreferences {
|
class InvenTreePreferences {
|
||||||
|
|
||||||
static const String _SERVER = 'server';
|
static const String _SERVER = 'server';
|
||||||
static const String _USERNAME = 'username';
|
static const String _USERNAME = 'username';
|
||||||
static const String _PASSWORD = 'password';
|
static const String _PASSWORD = 'password';
|
||||||
|
|
||||||
// Ensure we only ever create a single instance of the preferences class
|
/* The following settings are not stored to persistent storage,
|
||||||
static final InvenTreeUserPreferences _api = new InvenTreeUserPreferences._internal();
|
* 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;
|
return _api;
|
||||||
}
|
}
|
||||||
|
|
||||||
InvenTreeUserPreferences._internal();
|
InvenTreePreferences._internal();
|
||||||
|
|
||||||
// Load saved login details, and attempt connection
|
// Load saved login details, and attempt connection
|
||||||
void loadLoginDetails() async {
|
void loadLoginDetails() async {
|
||||||
|
@ -130,7 +130,7 @@ class _InvenTreeLoginSettingsState extends State<InvenTreeLoginSettingsWidget> {
|
|||||||
if (_formKey.currentState.validate()) {
|
if (_formKey.currentState.validate()) {
|
||||||
_formKey.currentState.save();
|
_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/api.dart';
|
||||||
import 'package:InvenTree/inventree/part.dart';
|
import 'package:InvenTree/inventree/part.dart';
|
||||||
|
import 'package:InvenTree/preferences.dart';
|
||||||
|
|
||||||
import 'package:InvenTree/widget/part_display.dart';
|
import 'package:InvenTree/widget/part_display.dart';
|
||||||
import 'package:InvenTree/widget/drawer.dart';
|
import 'package:InvenTree/widget/drawer.dart';
|
||||||
@ -83,9 +84,6 @@ class _CategoryDisplayState extends State<CategoryDisplayWidget> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
bool _subcategoriesExpanded = false;
|
|
||||||
bool _partListExpanded = true;
|
|
||||||
|
|
||||||
Widget getCategoryDescriptionCard() {
|
Widget getCategoryDescriptionCard() {
|
||||||
if (category == null) {
|
if (category == null) {
|
||||||
return Card(
|
return Card(
|
||||||
@ -144,10 +142,10 @@ class _CategoryDisplayState extends State<CategoryDisplayWidget> {
|
|||||||
|
|
||||||
switch (index) {
|
switch (index) {
|
||||||
case 0:
|
case 0:
|
||||||
_subcategoriesExpanded = !isExpanded;
|
InvenTreePreferences().expandCategoryList = !isExpanded;
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
_partListExpanded = !isExpanded;
|
InvenTreePreferences().expandPartList = !isExpanded;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
@ -163,13 +161,13 @@ class _CategoryDisplayState extends State<CategoryDisplayWidget> {
|
|||||||
trailing: Text("${_subcategories.length}"),
|
trailing: Text("${_subcategories.length}"),
|
||||||
onTap: () {
|
onTap: () {
|
||||||
setState(() {
|
setState(() {
|
||||||
_subcategoriesExpanded = !_subcategoriesExpanded;
|
InvenTreePreferences().expandCategoryList = !InvenTreePreferences().expandCategoryList;
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
body: SubcategoryList(_subcategories),
|
body: SubcategoryList(_subcategories),
|
||||||
isExpanded: _subcategoriesExpanded && _subcategories.length > 0,
|
isExpanded: InvenTreePreferences().expandCategoryList && _subcategories.length > 0,
|
||||||
),
|
),
|
||||||
ExpansionPanel(
|
ExpansionPanel(
|
||||||
headerBuilder: (BuildContext context, bool isExpanded) {
|
headerBuilder: (BuildContext context, bool isExpanded) {
|
||||||
@ -179,13 +177,13 @@ class _CategoryDisplayState extends State<CategoryDisplayWidget> {
|
|||||||
trailing: Text("${_parts.length}"),
|
trailing: Text("${_parts.length}"),
|
||||||
onTap: () {
|
onTap: () {
|
||||||
setState(() {
|
setState(() {
|
||||||
_partListExpanded = !_partListExpanded;
|
InvenTreePreferences().expandPartList = !InvenTreePreferences().expandPartList;
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
body: PartList(_parts),
|
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/api.dart';
|
||||||
import 'package:InvenTree/inventree/stock.dart';
|
import 'package:InvenTree/inventree/stock.dart';
|
||||||
|
import 'package:InvenTree/preferences.dart';
|
||||||
import 'package:InvenTree/widget/drawer.dart';
|
import 'package:InvenTree/widget/drawer.dart';
|
||||||
import 'package:InvenTree/widget/stock_display.dart';
|
import 'package:InvenTree/widget/stock_display.dart';
|
||||||
import 'package:flutter/cupertino.dart';
|
import 'package:flutter/cupertino.dart';
|
||||||
@ -91,9 +92,6 @@ class _LocationDisplayState extends State<LocationDisplayWidget> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
bool _locationListExpanded = false;
|
|
||||||
bool _stockListExpanded = true;
|
|
||||||
|
|
||||||
Widget locationDescriptionCard() {
|
Widget locationDescriptionCard() {
|
||||||
if (location == null) {
|
if (location == null) {
|
||||||
return Card(
|
return Card(
|
||||||
@ -150,10 +148,10 @@ class _LocationDisplayState extends State<LocationDisplayWidget> {
|
|||||||
setState(() {
|
setState(() {
|
||||||
switch (index) {
|
switch (index) {
|
||||||
case 0:
|
case 0:
|
||||||
_locationListExpanded = !isExpanded;
|
InvenTreePreferences().expandLocationList = !isExpanded;
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
_stockListExpanded = !isExpanded;
|
InvenTreePreferences().expandStockList = !isExpanded;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
@ -170,13 +168,13 @@ class _LocationDisplayState extends State<LocationDisplayWidget> {
|
|||||||
trailing: Text("${_sublocations.length}"),
|
trailing: Text("${_sublocations.length}"),
|
||||||
onTap: () {
|
onTap: () {
|
||||||
setState(() {
|
setState(() {
|
||||||
_locationListExpanded = !_locationListExpanded;
|
InvenTreePreferences().expandLocationList = !InvenTreePreferences().expandLocationList;
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
body: SublocationList(_sublocations),
|
body: SublocationList(_sublocations),
|
||||||
isExpanded: _locationListExpanded && _sublocations.length > 0,
|
isExpanded: InvenTreePreferences().expandLocationList && _sublocations.length > 0,
|
||||||
),
|
),
|
||||||
ExpansionPanel(
|
ExpansionPanel(
|
||||||
headerBuilder: (BuildContext context, bool isExpanded) {
|
headerBuilder: (BuildContext context, bool isExpanded) {
|
||||||
@ -186,13 +184,13 @@ class _LocationDisplayState extends State<LocationDisplayWidget> {
|
|||||||
trailing: Text("${_items.length}"),
|
trailing: Text("${_items.length}"),
|
||||||
onTap: () {
|
onTap: () {
|
||||||
setState(() {
|
setState(() {
|
||||||
_stockListExpanded = !_stockListExpanded;
|
InvenTreePreferences().expandStockList = !InvenTreePreferences().expandStockList;
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
body: StockList(_items),
|
body: StockList(_items),
|
||||||
isExpanded: _stockListExpanded && _items.length > 0,
|
isExpanded: InvenTreePreferences().expandStockList && _items.length > 0,
|
||||||
)
|
)
|
||||||
]
|
]
|
||||||
),
|
),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user