update menu
This commit is contained in:
parent
dc2ef710f8
commit
4ab7b56046
@ -26,12 +26,14 @@ class Body extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _BodyState extends State<Body> {
|
class _BodyState extends State<Body> {
|
||||||
late int currentPosition;
|
|
||||||
late MenuSection devices;
|
late MenuSection devices;
|
||||||
late MenuSection configurations;
|
late MenuSection configurations;
|
||||||
late MenuSection resources;
|
late MenuSection resources;
|
||||||
|
|
||||||
Menu menu = Menu(title: "MyInfoMate");
|
Menu menu = Menu(title: "MyInfoMate");
|
||||||
|
Widget? selectedElement = null;
|
||||||
|
|
||||||
|
final ValueNotifier<int?> currentPosition = ValueNotifier<int?>(null);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
@ -46,6 +48,22 @@ class _BodyState extends State<Body> {
|
|||||||
resources = MenuSection(name: "Ressources", type: "resources", menuId: 6, subMenu: []);
|
resources = MenuSection(name: "Ressources", type: "resources", menuId: 6, subMenu: []);
|
||||||
|
|
||||||
menu.sections = [devices, configurations, resources];
|
menu.sections = [devices, configurations, resources];
|
||||||
|
|
||||||
|
if(currentPosition.value == null) {
|
||||||
|
if (widget.instance.isMobile!) {
|
||||||
|
currentPosition.value = 1;
|
||||||
|
} else if (widget.instance.isTablet!) {
|
||||||
|
currentPosition.value = 2;
|
||||||
|
} else if (widget.instance.isWeb!) {
|
||||||
|
currentPosition.value = 3;
|
||||||
|
} else {
|
||||||
|
currentPosition.value = 4;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
//currentPosition = managerAppContext.currentPositionMenu!;
|
||||||
|
}
|
||||||
|
|
||||||
|
selectedElement = initElementToShow(currentPosition.value!, menu);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget buildMenu(BuildContext context, AppContext appContext, ManagerAppContext managerAppContext, bool isDrawer) {
|
Widget buildMenu(BuildContext context, AppContext appContext, ManagerAppContext managerAppContext, bool isDrawer) {
|
||||||
@ -66,37 +84,27 @@ class _BodyState extends State<Body> {
|
|||||||
children: menu.sections!.map((section) {
|
children: menu.sections!.map((section) {
|
||||||
if (section.subMenu.isEmpty) {
|
if (section.subMenu.isEmpty) {
|
||||||
return ListTile(
|
return ListTile(
|
||||||
title: Text(section.name, style: TextStyle(color: section.menuId == currentPosition ? kPrimaryColor : kBodyTextColor, fontSize: 20)),
|
title: Text(section.name, style: TextStyle(color: section.menuId == currentPosition.value ? kPrimaryColor : kBodyTextColor, fontSize: 20)),
|
||||||
selected: currentPosition == section.menuId,
|
selected: currentPosition == section.menuId,
|
||||||
onTap: () {
|
onTap: () {
|
||||||
setState(() {
|
currentPosition.value = section.menuId;
|
||||||
currentPosition = section.menuId;
|
|
||||||
selectedElement = initElementToShow(currentPosition, menu);
|
|
||||||
managerAppContext.currentPositionMenu = currentPosition;
|
|
||||||
appContext.setContext(managerAppContext);
|
|
||||||
});
|
|
||||||
if (isDrawer) Navigator.of(context).pop(); // Close drawer on mobile
|
if (isDrawer) Navigator.of(context).pop(); // Close drawer on mobile
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
return ExpansionTile(
|
return ExpansionTile(
|
||||||
iconColor: currentPosition >= 1 && currentPosition <= 4 ? kPrimaryColor : kBodyTextColor,
|
iconColor: currentPosition.value! >= 1 && currentPosition.value! <= 4 ? kPrimaryColor : kBodyTextColor,
|
||||||
collapsedIconColor: currentPosition >= 1 && currentPosition <= 4 ? kPrimaryColor : kBodyTextColor,
|
collapsedIconColor: currentPosition.value! >= 1 && currentPosition.value! <= 4 ? kPrimaryColor : kBodyTextColor,
|
||||||
title: Text(section.name, style: TextStyle(color: currentPosition >= 1 && currentPosition <= 4 ? kPrimaryColor : kBodyTextColor, fontSize: 20)),
|
title: Text(section.name, style: TextStyle(color: currentPosition.value! >= 1 && currentPosition.value! <= 4 ? kPrimaryColor : kBodyTextColor, fontSize: 20)),
|
||||||
children: section.subMenu.map((subSection) {
|
children: section.subMenu.map((subSection) {
|
||||||
return ListTile(
|
return ListTile(
|
||||||
title: Padding(
|
title: Padding(
|
||||||
padding: const EdgeInsets.only(left: 16.0),
|
padding: const EdgeInsets.only(left: 16.0),
|
||||||
child: Text(subSection.name, style: TextStyle(color: subSection.menuId == currentPosition ? kPrimaryColor : kBodyTextColor, fontSize: 18)),
|
child: Text(subSection.name, style: TextStyle(color: subSection.menuId == currentPosition.value! ? kPrimaryColor : kBodyTextColor, fontSize: 18)),
|
||||||
),
|
),
|
||||||
selected: currentPosition == subSection.menuId,
|
selected: currentPosition == subSection.menuId,
|
||||||
onTap: () {
|
onTap: () {
|
||||||
setState(() {
|
currentPosition.value = subSection.menuId;
|
||||||
currentPosition = subSection.menuId;
|
|
||||||
selectedElement = initElementToShow(currentPosition, menu);
|
|
||||||
managerAppContext.currentPositionMenu = currentPosition;
|
|
||||||
appContext.setContext(managerAppContext);
|
|
||||||
});
|
|
||||||
if (isDrawer) Navigator.of(context).pop();
|
if (isDrawer) Navigator.of(context).pop();
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
@ -142,29 +150,12 @@ class _BodyState extends State<Body> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
late Widget selectedElement;
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final appContext = Provider.of<AppContext>(context);
|
final appContext = Provider.of<AppContext>(context);
|
||||||
ManagerAppContext managerAppContext = appContext.getContext();
|
ManagerAppContext managerAppContext = appContext.getContext();
|
||||||
|
|
||||||
if(managerAppContext.currentPositionMenu == null) {
|
|
||||||
if (widget.instance.isMobile!) {
|
|
||||||
currentPosition = 1;
|
|
||||||
} else if (widget.instance.isTablet!) {
|
|
||||||
currentPosition = 2;
|
|
||||||
} else if (widget.instance.isWeb!) {
|
|
||||||
currentPosition = 3;
|
|
||||||
} else {
|
|
||||||
currentPosition = 4;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
currentPosition = managerAppContext.currentPositionMenu!;
|
|
||||||
}
|
|
||||||
|
|
||||||
selectedElement = initElementToShow(currentPosition, menu);
|
|
||||||
|
|
||||||
Size size = MediaQuery.of(context).size;
|
Size size = MediaQuery.of(context).size;
|
||||||
bool isMobile = size.width < 700;
|
bool isMobile = size.width < 700;
|
||||||
|
|
||||||
@ -181,15 +172,31 @@ class _BodyState extends State<Body> {
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
: null,
|
: null,
|
||||||
drawer: isMobile ? Drawer(child: buildMenu(context, appContext, managerAppContext, true)) : null,
|
drawer: isMobile ? ValueListenableBuilder<int?>(
|
||||||
|
valueListenable: currentPosition,
|
||||||
|
builder: (context, value, _) {
|
||||||
|
return Drawer(child: buildMenu(context, appContext, managerAppContext, true));
|
||||||
|
}
|
||||||
|
) : null,
|
||||||
body: Row(
|
body: Row(
|
||||||
children: [
|
children: [
|
||||||
if (!isMobile)
|
if (!isMobile)
|
||||||
buildMenu(context, appContext, managerAppContext, false),
|
ValueListenableBuilder<int?>(
|
||||||
|
valueListenable: currentPosition,
|
||||||
|
builder: (context, value, _) {
|
||||||
|
return buildMenu(context, appContext, managerAppContext, false);
|
||||||
|
}
|
||||||
|
),
|
||||||
Expanded(
|
Expanded(
|
||||||
child: Padding(
|
child: ValueListenableBuilder<int?>(
|
||||||
|
valueListenable: currentPosition,
|
||||||
|
builder: (context, value, _) {
|
||||||
|
selectedElement = initElementToShow(currentPosition.value!, menu);
|
||||||
|
return Padding(
|
||||||
padding: const EdgeInsets.all(8.0),
|
padding: const EdgeInsets.all(8.0),
|
||||||
child: selectedElement,
|
child: selectedElement,
|
||||||
|
);
|
||||||
|
}
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
|||||||
85
lib/Screens/app_configuration_link_screen.dart
Normal file
85
lib/Screens/app_configuration_link_screen.dart
Normal file
@ -0,0 +1,85 @@
|
|||||||
|
import 'package:auto_size_text/auto_size_text.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:manager_app/Components/common_loader.dart';
|
||||||
|
import 'package:manager_app/Models/managerContext.dart';
|
||||||
|
import 'package:manager_app/Screens/Devices/device_element.dart';
|
||||||
|
import 'package:manager_app/app_context.dart';
|
||||||
|
import 'package:manager_app/constants.dart';
|
||||||
|
import 'package:manager_api_new/api.dart';
|
||||||
|
import 'package:provider/provider.dart';
|
||||||
|
|
||||||
|
class AppConfigurationLinkScreen extends StatefulWidget {
|
||||||
|
AppConfigurationLinkScreen({Key? key}) : super(key: key);
|
||||||
|
|
||||||
|
@override
|
||||||
|
_AppConfigurationLinkScreenState createState() => _AppConfigurationLinkScreenState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _AppConfigurationLinkScreenState extends State<AppConfigurationLinkScreen> {
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final appContext = Provider.of<AppContext>(context);
|
||||||
|
Size size = MediaQuery.of(context).size;
|
||||||
|
ManagerAppContext managerAppContext = appContext.getContext();
|
||||||
|
return Container(
|
||||||
|
child: Align(
|
||||||
|
alignment: AlignmentDirectional.topCenter,
|
||||||
|
child: SingleChildScrollView(
|
||||||
|
child: Column(
|
||||||
|
children: [
|
||||||
|
FutureBuilder(
|
||||||
|
future: getAppConfigurationLink(appContext),
|
||||||
|
builder: (context, AsyncSnapshot<dynamic> snapshot) {
|
||||||
|
if (snapshot.connectionState == ConnectionState.done) {
|
||||||
|
return GridView.builder(
|
||||||
|
shrinkWrap: true,
|
||||||
|
gridDelegate: new SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 6),
|
||||||
|
itemCount: snapshot.data.length,
|
||||||
|
itemBuilder: (BuildContext context, int index) {
|
||||||
|
return Container(
|
||||||
|
padding: const EdgeInsets.all(15),
|
||||||
|
margin: EdgeInsets.symmetric(vertical: 15, horizontal: 15),
|
||||||
|
child: Align(
|
||||||
|
alignment: Alignment.center,
|
||||||
|
child: DeviceElement(deviceDTO: snapshot.data[index]), //getElement()
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
} else if (snapshot.connectionState == ConnectionState.none) {
|
||||||
|
return Text("No data");
|
||||||
|
} else {
|
||||||
|
return Center(
|
||||||
|
child: Container(
|
||||||
|
height: size.height * 0.2,
|
||||||
|
child: CommonLoader()
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> updateMainInfos(DeviceDTO deviceToUpdate, dynamic appContext) async {
|
||||||
|
ManagerAppContext managerAppContext = appContext.getContext();
|
||||||
|
await managerAppContext.clientAPI!.deviceApi!.deviceUpdateMainInfos(deviceToUpdate);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<List<AppConfigurationLinkDTO>?> getAppConfigurationLink(AppContext appContext) async {
|
||||||
|
List<DeviceDTO>? devices = await (appContext.getContext() as ManagerAppContext).clientAPI!.apiApi!.deviceGet(instanceId: (appContext.getContext() as ManagerAppContext).instanceId);
|
||||||
|
//print("number of devices " + devices.length.toString());
|
||||||
|
|
||||||
|
if(devices != null) {
|
||||||
|
devices.forEach((element) {
|
||||||
|
//print(element);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return devices;
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user