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 { Body({Key key}) : super(key: key); @override _BodyState createState() => _BodyState(); } class _BodyState extends State { bool isChecked = false; int currentPosition = 0; var selectedElement; //MenuSection devices = new MenuSection(name: "Test", type: "devices", order: 0); MenuSection configurations = new MenuSection(name: "Visites", type: "configurations", order: 0); MenuSection resources = new MenuSection(name: "Ressources", type: "resources", order: 1); Menu menu = new Menu(title: "MyMuseum"); @override Widget build(BuildContext context) { final appContext = Provider.of(context); Size size = MediaQuery.of(context).size; menu.sections = []; //menu.sections.add(devices); menu.sections.add(configurations); menu.sections.add(resources); selectedElement = initElementToShow(currentPosition, menu); return Background( child: Row( children: [ // 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: [ 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: [ for (var section in menu.sections) InkWell( onTap: () => { setState(() { currentPosition = section.order; selectedElement = initElementToShow(currentPosition, menu); }) }, 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().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 route) => false // For pushAndRemoveUntil ); }); }, color: kPrimaryColor, ), ], ), ) ) ], ), ), // Main Container Container( width: size.width * 0.85, 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() ); break; case 'configurations' : return Padding( padding: const EdgeInsets.all(8.0), child: ConfigurationsScreen() ); break; case 'resources' : return Padding( padding: const EdgeInsets.all(8.0), child: ResourcesScreen( resourceTypes: [ ResourceType.Audio, ResourceType.Image, ResourceType.ImageUrl ] ) ); break; default: return Text('Hellow default'); break; } }