diff --git a/lib/Screens/Main/components/body.dart b/lib/Screens/Main/components/body.dart
index 89e9b8f..a002704 100644
--- a/lib/Screens/Main/components/body.dart
+++ b/lib/Screens/Main/components/body.dart
@@ -26,12 +26,14 @@ class Body extends StatefulWidget {
}
class _BodyState extends State
{
- late int currentPosition;
late MenuSection devices;
late MenuSection configurations;
late MenuSection resources;
Menu menu = Menu(title: "MyInfoMate");
+ Widget? selectedElement = null;
+
+ final ValueNotifier currentPosition = ValueNotifier(null);
@override
void initState() {
@@ -46,6 +48,22 @@ class _BodyState extends State {
resources = MenuSection(name: "Ressources", type: "resources", menuId: 6, subMenu: []);
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) {
@@ -66,37 +84,27 @@ class _BodyState extends State {
children: menu.sections!.map((section) {
if (section.subMenu.isEmpty) {
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,
onTap: () {
- setState(() {
- currentPosition = section.menuId;
- selectedElement = initElementToShow(currentPosition, menu);
- managerAppContext.currentPositionMenu = currentPosition;
- appContext.setContext(managerAppContext);
- });
+ currentPosition.value = section.menuId;
if (isDrawer) Navigator.of(context).pop(); // Close drawer on mobile
},
);
} else {
return ExpansionTile(
- iconColor: currentPosition >= 1 && currentPosition <= 4 ? kPrimaryColor : kBodyTextColor,
- collapsedIconColor: currentPosition >= 1 && currentPosition <= 4 ? kPrimaryColor : kBodyTextColor,
- title: Text(section.name, style: TextStyle(color: currentPosition >= 1 && currentPosition <= 4 ? kPrimaryColor : kBodyTextColor, fontSize: 20)),
+ iconColor: currentPosition.value! >= 1 && currentPosition.value! <= 4 ? kPrimaryColor : kBodyTextColor,
+ collapsedIconColor: currentPosition.value! >= 1 && currentPosition.value! <= 4 ? kPrimaryColor : kBodyTextColor,
+ title: Text(section.name, style: TextStyle(color: currentPosition.value! >= 1 && currentPosition.value! <= 4 ? kPrimaryColor : kBodyTextColor, fontSize: 20)),
children: section.subMenu.map((subSection) {
return ListTile(
title: Padding(
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,
onTap: () {
- setState(() {
- currentPosition = subSection.menuId;
- selectedElement = initElementToShow(currentPosition, menu);
- managerAppContext.currentPositionMenu = currentPosition;
- appContext.setContext(managerAppContext);
- });
+ currentPosition.value = subSection.menuId;
if (isDrawer) Navigator.of(context).pop();
},
);
@@ -142,29 +150,12 @@ class _BodyState extends State {
);
}
- late Widget selectedElement;
@override
Widget build(BuildContext context) {
final appContext = Provider.of(context);
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;
bool isMobile = size.width < 700;
@@ -181,15 +172,31 @@ class _BodyState extends State {
),
)
: null,
- drawer: isMobile ? Drawer(child: buildMenu(context, appContext, managerAppContext, true)) : null,
+ drawer: isMobile ? ValueListenableBuilder(
+ valueListenable: currentPosition,
+ builder: (context, value, _) {
+ return Drawer(child: buildMenu(context, appContext, managerAppContext, true));
+ }
+ ) : null,
body: Row(
children: [
if (!isMobile)
- buildMenu(context, appContext, managerAppContext, false),
+ ValueListenableBuilder(
+ valueListenable: currentPosition,
+ builder: (context, value, _) {
+ return buildMenu(context, appContext, managerAppContext, false);
+ }
+ ),
Expanded(
- child: Padding(
- padding: const EdgeInsets.all(8.0),
- child: selectedElement,
+ child: ValueListenableBuilder(
+ valueListenable: currentPosition,
+ builder: (context, value, _) {
+ selectedElement = initElementToShow(currentPosition.value!, menu);
+ return Padding(
+ padding: const EdgeInsets.all(8.0),
+ child: selectedElement,
+ );
+ }
),
),
],
diff --git a/lib/Screens/app_configuration_link_screen.dart b/lib/Screens/app_configuration_link_screen.dart
new file mode 100644
index 0000000..3572b72
--- /dev/null
+++ b/lib/Screens/app_configuration_link_screen.dart
@@ -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 {
+ @override
+ Widget build(BuildContext context) {
+ final appContext = Provider.of(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 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 updateMainInfos(DeviceDTO deviceToUpdate, dynamic appContext) async {
+ ManagerAppContext managerAppContext = appContext.getContext();
+ await managerAppContext.clientAPI!.deviceApi!.deviceUpdateMainInfos(deviceToUpdate);
+}
+
+Future?> getAppConfigurationLink(AppContext appContext) async {
+ List? 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;
+}