Thomas Fransolet 4818a1af52 Configuration (create, update, del) + Section (create, update, del)
more test to be sure for section but should be ok
2025-05-13 17:12:04 +02:00

238 lines
9.3 KiB
Dart

import 'dart:html';
import 'package:auto_size_text/auto_size_text.dart';
import 'package:flutter/material.dart';
import 'package:manager_app/Models/managerContext.dart';
import 'package:manager_app/Models/menu.dart';
import 'package:manager_app/Models/menuSection.dart';
import 'package:manager_app/Screens/Configurations/configurations_screen.dart';
import 'package:manager_app/Screens/Devices/devices_screen.dart';
import 'package:manager_app/Screens/Main/components/background.dart';
import 'package:manager_app/Screens/Resources/resources_screen.dart';
import 'package:manager_app/Screens/login_screen.dart';
import 'package:manager_app/app_context.dart';
import 'package:manager_app/constants.dart';
import 'package:manager_app/main.dart';
import 'package:manager_api_new/api.dart';
import 'package:provider/provider.dart';
class Body extends StatefulWidget {
final bool showDevice;
Body({
Key? key,
required this.showDevice
}) : super(key: key);
@override
_BodyState createState() => _BodyState();
}
class _BodyState extends State<Body> {
bool isChecked = false;
int currentPosition = 0;
var selectedElement;
late MenuSection devices;
late MenuSection configurations;
late MenuSection resources;
Menu menu = new Menu(title: "MyInfoMate");
@override
void initState() {
devices = new MenuSection(name: "Tablettes", type: "devices", order: 0);
configurations = new MenuSection(name: "Configurations", type: "configurations", order: widget.showDevice ? 1 : 0); // TODO Renommer spécifiquement en Visites pour St Heribert
resources = new MenuSection(name: "Ressources", type: "resources", order: widget.showDevice ? 2 : 1);
//tabsToShow.add(new Tab(text: "Vidéo en ligne"));
super.initState();
}
@override
Widget build(BuildContext context) {
final appContext = Provider.of<AppContext>(context);
Size size = MediaQuery.of(context).size;
menu.sections = <MenuSection>[];
if(widget.showDevice) // pour ne pas perturber francoise
{
menu.sections!.add(devices);
}
menu.sections!.add(configurations);
menu.sections!.add(resources);
ManagerAppContext managerAppContext = appContext.getContext();
currentPosition = managerAppContext.currentPositionMenu ?? currentPosition;
selectedElement = initElementToShow(currentPosition, menu);
return Background(
child: Row(
children: [
if(true) //!ResponsiveBreakpoints.of(context).equals(TABLET)
// MENU
Container(
width: size.width * 0.15,
decoration: BoxDecoration(
color: kSecond,
borderRadius: BorderRadius.only(topRight: Radius.circular(20), bottomRight: Radius.circular(20)),
boxShadow: [
BoxShadow(
color: kSecond.withOpacity(0.3),
spreadRadius: 0.5,
blurRadius: 0.5,
offset: Offset(0, 1.5), // changes position of shadow
),
],
),
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Padding(
padding: const EdgeInsets.all(8.0),
child: Container(
alignment: AlignmentDirectional.bottomStart,
child: AutoSizeText(
menu.title,
style: new TextStyle(color: kPrimaryColor, fontSize: 30, fontWeight: FontWeight.w400, fontFamily: "Helvetica"),
maxLines: 1,
),
),
),
Container(
height: size.height * 0.2,
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
for (var section in menu.sections!)
InkWell(
onTap: () => {
setState(() {
currentPosition = section.order;
selectedElement = initElementToShow(currentPosition, menu);
managerAppContext.currentPositionMenu = currentPosition;
appContext.setContext(managerAppContext);
})
},
child: Container(
alignment: AlignmentDirectional.bottomStart,
decoration: BoxDecoration(
border: currentPosition == section.order ? Border(
right: BorderSide(
color: kPrimaryColor,
width: 4,
),
): null,
),
child: Padding(
padding: const EdgeInsets.only(left: 10),
child: AutoSizeText(
section.name,
style: new TextStyle(color: kBodyTextColor, fontSize: 25, fontWeight: FontWeight.w300, fontFamily: "Helvetica"),
maxLines: 1,
),
),
),
),
]
),
),
SizedBox(
height: size.height * 0.35,
),
Container(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
children: [
AutoSizeText(
(appContext.getContext() as ManagerAppContext).email!,
style: new TextStyle(color: kBodyTextColor, fontSize: 20, fontWeight: FontWeight.w300, fontFamily: "Helvetica"),
maxLines: 1,
),
IconButton(
icon: Icon(Icons.logout),
onPressed: () async {
var session = await loadJsonSessionFile();
setState(() {
print("Logout");
Storage localStorage = window.localStorage;
localStorage.clear();
ManagerAppContext managerAppContext = appContext.getContext();
managerAppContext.accessToken = null;
appContext.setContext(managerAppContext);
Navigator.pushAndRemoveUntil(
context,
MaterialPageRoute(
builder: (context) {
return LoginScreen(session: session);
},
),
(Route<dynamic> route) => false // For pushAndRemoveUntil
);
});
},
color: kPrimaryColor,
),
],
),
)
)
],
),
),
// Main Container
Container(
width: size.width * 0.85,//!ResponsiveBreakpoints.of(context).equals(TABLET) ? size.width * 0.85 : size.width,
child: Padding(
padding: const EdgeInsets.all(0.0),
child: selectedElement),
),
]
),
);
}
}
initElementToShow(int currentPosition, Menu menu) {
MenuSection elementToShow = menu.sections!.where((s) => s.order == currentPosition).first;
switch (elementToShow.type) {
case 'devices' :
return Padding(
padding: const EdgeInsets.all(8.0),
child: DevicesScreen()
);
case 'configurations' :
return Padding(
padding: const EdgeInsets.all(8.0),
child: ConfigurationsScreen()
);
case 'resources' :
return Padding(
padding: const EdgeInsets.all(8.0),
child: ResourcesScreen(
resourceTypes: [
ResourceType.Audio,
ResourceType.Image,
ResourceType.ImageUrl,
ResourceType.Video,
ResourceType.VideoUrl,
ResourceType.Pdf,
ResourceType.Json,
ResourceType.JsonUrl
]
)
);
default:
return Text('Hellow default');
}
}