import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:manager_app/Components/check_input_container.dart'; import 'package:manager_app/Components/color_picker_input_container.dart'; import 'package:manager_app/Components/message_notification.dart'; import 'package:manager_app/Components/number_input_container.dart'; import 'package:manager_app/Components/rounded_button.dart'; import 'package:manager_app/Components/string_input_container.dart'; import 'package:manager_app/Models/managerContext.dart'; import 'package:manager_app/app_context.dart'; import 'package:manager_app/constants.dart'; import 'package:manager_api_new/api.dart'; import '../../Components/resource_input_container.dart'; import 'dropDown_configuration.dart'; showChangeInfo (String text, DeviceDTO inputDevice, AppConfigurationLinkDTO appConfiguration, Function onGetResult, int maxLines, BuildContext mainContext, dynamic appContext) async { Size size = MediaQuery.of(mainContext).size; var result = await showDialog( builder: (BuildContext context) => AlertDialog( shape: RoundedRectangleBorder( borderRadius: BorderRadius.all(Radius.circular(20.0)) ), title: Center(child: Text(text)), content: Container( width: size.width * 0.5, height: size.height * 0.5, constraints: BoxConstraints(minWidth: 400, minHeight: 500), child: Column( children: [ Row( mainAxisAlignment: MainAxisAlignment.spaceAround, children: [ Container( width: size.width * 0.3, height: size.height * 0.15, child: StringInputContainer( label: "Nom:", initialValue: inputDevice.name, onChanged: (value) { inputDevice.name = value; }, maxLength: 20, ), ), Row( children: [ Align( alignment: AlignmentDirectional.centerStart, child: Text("Configuration:", style: TextStyle(fontSize: 25, fontWeight: FontWeight.w300)) ), Container( height: size.height * 0.1, child: FutureBuilder( future: getConfigurations(appContext), builder: (context, AsyncSnapshot snapshot) { if (snapshot.connectionState == ConnectionState.done) { if (snapshot.data.length > 0) { return Row( children: [ Padding( padding: const EdgeInsets.all(8.0), child: DropDownConfig( configurations: snapshot.data, selectedConfigurationId: inputDevice.configurationId!, onChange: (ConfigurationDTO configurationOut) { inputDevice.configuration = configurationOut.label; inputDevice.configurationId = configurationOut.id; }, ), ), ], ); } else { return Text("Aucune configuration trouvée"); } } else if (snapshot.connectionState == ConnectionState.none) { return Text("No data"); } else { return Center( child: Container( child: Text("Loading..") ) ); } } ), ), ], ), ], ), Row( mainAxisAlignment: MainAxisAlignment.spaceAround, children: [ ColorPickerInputContainer( label: "Couleur principale :", fontSize: 20, color: appConfiguration.primaryColor, onChanged: (value) { appConfiguration.primaryColor = value; }, ), ColorPickerInputContainer( label: "Couleur fond d'écran :", fontSize: 20, color: appConfiguration.secondaryColor, onChanged: (value) { appConfiguration.secondaryColor = value; }, ), ResourceInputContainer( label: "Loader :", initialValue: appConfiguration.loaderImageId, color: kPrimaryColor, imageFit: BoxFit.fitHeight, onChanged: (ResourceDTO resource) async { if(resource.id == null) { appConfiguration.loaderImageId = null; appConfiguration.loaderImageUrl = null; } else { appConfiguration.loaderImageId = resource.id; appConfiguration.loaderImageUrl = resource.url; } }, ), ], ), Row( mainAxisAlignment: MainAxisAlignment.spaceAround, children: [ Container( height: 100, child: NumberInputContainer( label: "Place des sections (%) :", initialValue: appConfiguration.screenPercentageSectionsMainPage ?? 0, isSmall: true, maxLength: 3, onChanged: (value) { try { appConfiguration.screenPercentageSectionsMainPage = int.parse(value); } catch (e) { print('Screen percentage value not a number'); showNotification(Colors.orange, kWhite, 'Cela doit être un chiffre', context, null); } }, ), ), Container( height: 100, child: NumberInputContainer( label: "Pourcentage des arrondis (0-50) :", initialValue: appConfiguration.roundedValue ?? 0, isSmall: true, maxLength: 2, onChanged: (value) { try { appConfiguration.roundedValue = int.parse(value); } catch (e) { print('Rounded value not a number'); showNotification(Colors.orange, kWhite, 'Cela doit être un chiffre', context, null); } }, ), ), ], ), Row( mainAxisAlignment: MainAxisAlignment.spaceAround, children: [ CheckInputContainer( icon: Icons.image, label: "Fond pour les images des sections :", fontSize: 20, isChecked: appConfiguration.isSectionImageBackground, onChanged: (value) { appConfiguration.isSectionImageBackground = value; }, ), CheckInputContainer( icon: Icons.watch_later_outlined, label: "Heure :", fontSize: 20, isChecked: appConfiguration.isHour, onChanged: (value) { appConfiguration.isHour = value; }, ), CheckInputContainer( icon: Icons.date_range, label: "Date :", fontSize: 20, isChecked: appConfiguration.isDate, onChanged: (value) { appConfiguration.isDate = value; }, ), ] ), ], ), ), actions: [ Row( mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ Container( width: 180, height: 70, child: RoundedButton( text: "Annuler", icon: Icons.undo, color: kSecond, press: () { Navigator.of(context).pop(); }, fontSize: 20, ), ), Container( width: 180, height: 70, child: RoundedButton( text: "Changer", icon: Icons.check, color: kPrimaryColor, textColor: kWhite, press: () { onGetResult(inputDevice, appConfiguration); Navigator.of(context).pop(); }, fontSize: 20, ), ), ], ), ], ), context: mainContext ); } getConfigurationsElement(DeviceDTO inputDevice, data, Function onGetResult) { List widgets = []; for(var configuration in data as List) { var widget = new InkWell( onTap: () { inputDevice.configuration = configuration.label; inputDevice.configurationId = configuration.id; }, child: Ink( color: inputDevice.configurationId == configuration.id ? kPrimaryColor : null, child: ListTile( leading: Icon(Icons.account_tree_rounded), title: Text(configuration.label!), ), ), ); widgets.add(widget); } return widgets; } Future?> getConfigurations(AppContext appContext) async { List? configurations = await (appContext.getContext() as ManagerAppContext).clientAPI!.configurationApi!.configurationGet(instanceId: (appContext.getContext() as ManagerAppContext).instanceId); //print("number of configurations " + configurations.length.toString()); if(configurations != null) { configurations.forEach((element) { //print(element); }); } return configurations; }