diff --git a/Dockerfile b/Dockerfile index 60b80ec..0a0c86d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -16,7 +16,7 @@ RUN flutter upgrade RUN mkdir /app/ COPY . /app/ WORKDIR /app/ -RUN flutter build web --no-sound-null-safety +RUN flutter build web #--no-sound-null-safety # Stage 2 - Create the run-time image FROM nginx:1.21.1-alpine diff --git a/lib/Components/audio_input_container.dart b/lib/Components/audio_input_container.dart index 5969e93..2281716 100644 --- a/lib/Components/audio_input_container.dart +++ b/lib/Components/audio_input_container.dart @@ -1,6 +1,7 @@ import 'package:auto_size_text/auto_size_text.dart'; import 'package:flutter/material.dart'; import 'package:manager_app/Components/loading_common.dart'; +import 'package:manager_app/Models/managerContext.dart'; import 'package:manager_app/app_context.dart'; import 'package:manager_app/constants.dart'; import 'package:manager_app/Screens/Resources/select_resource_modal.dart'; @@ -10,17 +11,17 @@ import 'package:provider/provider.dart'; class AudioInputContainer extends StatefulWidget { final Color color; final String label; - final String initialValue; + final String? initialValue; final ValueChanged onChanged; final BoxFit imageFit; final bool isSmall; final double fontSize; const AudioInputContainer({ - Key key, + Key? key, this.color = kSecond, - this.label, + required this.label, this.initialValue, - this.onChanged, + required this.onChanged, this.imageFit = BoxFit.cover, this.isSmall = false, this.fontSize = 20 @@ -31,7 +32,7 @@ class AudioInputContainer extends StatefulWidget { } class _AudioInputContainerState extends State { - String resourceIdToShow; + String? resourceIdToShow; @override void initState() { @@ -48,7 +49,7 @@ class _AudioInputContainerState extends State { Align( alignment: AlignmentDirectional.centerStart, child: AutoSizeText( - widget.label, + widget.label!, style: TextStyle(fontSize: widget.fontSize, fontWeight: FontWeight.w300), maxLines: 2, maxFontSize: widget.fontSize, @@ -64,7 +65,7 @@ class _AudioInputContainerState extends State { height: size.width *0.08, child: InkWell( onTap: () async { - ResourceDTO result = await showSelectResourceModal( + ResourceDTO? result = await showSelectResourceModal( "Sélectionner une ressource", 1, [ResourceType.Audio], @@ -93,13 +94,13 @@ class _AudioInputContainerState extends State { Size size = MediaQuery.of(context).size; final appContext = Provider.of(context); return FutureBuilder( - future: getResource(resourceIdToShow, appContext), - builder: (context, AsyncSnapshot snapshot) { + future: getResource(resourceIdToShow!, appContext), + builder: (context, AsyncSnapshot snapshot) { if (snapshot.connectionState == ConnectionState.done) { if (snapshot.data != null) { return Container( - decoration: boxDecoration(snapshot.data, appContext), - child: Center(child: AutoSizeText(snapshot.data.label, textAlign: TextAlign.center)), + decoration: boxDecoration(snapshot.data!, appContext), + child: Center(child: AutoSizeText(snapshot.data!.label!, textAlign: TextAlign.center)), ); } else { return Text("No data"); @@ -137,9 +138,9 @@ class _AudioInputContainerState extends State { } } - Future getResource(String resourceIdToShow, dynamic appContext) async { + Future getResource(String resourceIdToShow, dynamic appContext) async { // Just in resource tab detail not here - ResourceDTO resource = await appContext.getContext().clientAPI.resourceApi.resourceGetDetail(resourceIdToShow); + ResourceDTO? resource = await (appContext.getContext() as ManagerAppContext).clientAPI!.resourceApi!.resourceGetDetail(resourceIdToShow); return resource; } diff --git a/lib/Components/audio_player.dart b/lib/Components/audio_player.dart index b3dfe10..8411d4d 100644 --- a/lib/Components/audio_player.dart +++ b/lib/Components/audio_player.dart @@ -10,7 +10,7 @@ import 'package:just_audio/just_audio.dart'; class AudioPlayerFloatingContainer extends StatefulWidget { - const AudioPlayerFloatingContainer({Key key, this.audioBytes, this.isAuto}) : super(key: key); + const AudioPlayerFloatingContainer({Key? key, required this.audioBytes, required this.isAuto}) : super(key: key); final Uint8List audioBytes; final bool isAuto; @@ -21,12 +21,12 @@ class AudioPlayerFloatingContainer extends StatefulWidget { class _AudioPlayerFloatingContainerState extends State { AudioPlayer player = AudioPlayer(); - Uint8List audiobytes; + late Uint8List audiobytes; bool isplaying = false; bool audioplayed = false; int currentpos = 0; int maxduration = 100; - Duration durationAudio; + Duration? durationAudio; String currentpostlabel = "00:00"; @override @@ -34,22 +34,24 @@ class _AudioPlayerFloatingContainerState extends State player.duration.inMilliseconds) { + if(currentpos > player.duration!.inMilliseconds) { print("RESET ALL"); player.stop(); player.seek(const Duration(seconds: 0)); @@ -226,7 +228,7 @@ class LoadedSource extends StreamAudioSource { LoadedSource(this.bytes); @override - Future request([int start, int end]) async { + Future request([int? start, int? end]) async { start ??= 0; end ??= bytes.length; return StreamAudioResponse( diff --git a/lib/Components/check_input_container.dart b/lib/Components/check_input_container.dart index 67cd4ea..812adee 100644 --- a/lib/Components/check_input_container.dart +++ b/lib/Components/check_input_container.dart @@ -4,17 +4,17 @@ import 'package:flutter/material.dart'; import '../constants.dart'; class CheckInputContainer extends StatefulWidget { - final bool isChecked; - final IconData icon; + final bool? isChecked; + final IconData? icon; final String label; final ValueChanged onChanged; final double fontSize; const CheckInputContainer({ - Key key, + Key? key, this.isChecked, this.icon, - this.label, - this.onChanged, + required this.label, + required this.onChanged, this.fontSize = 20 }) : super(key: key); @@ -23,7 +23,7 @@ class CheckInputContainer extends StatefulWidget { } class _CheckInputContainerState extends State { - bool isChecked; + bool? isChecked; @override void initState() { @@ -72,11 +72,11 @@ class _CheckInputContainerState extends State { value: isChecked, checkColor: Colors.white, activeColor: kPrimaryColor, - onChanged: (bool value) { + onChanged: (bool? value) { setState(() { isChecked = value; }); - widget.onChanged(value); + widget.onChanged(value!); }, ), ), diff --git a/lib/Components/color_picker_input_container.dart b/lib/Components/color_picker_input_container.dart index 84ef32f..3963d23 100644 --- a/lib/Components/color_picker_input_container.dart +++ b/lib/Components/color_picker_input_container.dart @@ -3,16 +3,16 @@ import 'package:flutter/material.dart'; import 'package:manager_app/Components/color_picker.dart'; class ColorPickerInputContainer extends StatefulWidget { - final String color; + final String? color; final String label; final double fontSize; final ValueChanged onChanged; const ColorPickerInputContainer({ - Key key, + Key? key, this.color, - this.label, + required this.label, this.fontSize = 25, - this.onChanged, + required this.onChanged, }) : super(key: key); @override @@ -20,12 +20,12 @@ class ColorPickerInputContainer extends StatefulWidget { } class _ColorPickerInputContainerState extends State { - Color colorVar; + Color? colorVar; @override void initState() { setState(() { - colorVar = widget.color == null ? new Color(0x12345678) : new Color(int.parse(widget.color.split('(0x')[1].split(')')[0], radix: 16)); + colorVar = widget.color == null ? new Color(0x12345678) : new Color(int.parse(widget.color!.split('(0x')[1].split(')')[0], radix: 16)); }); super.initState(); } @@ -50,7 +50,7 @@ class _ColorPickerInputContainerState extends State { child: InkWell( onTap: () { showColorPicker( - colorVar, + colorVar!, (Color color) { setState(() { colorVar = color; diff --git a/lib/Components/image_input_container.dart b/lib/Components/image_input_container.dart index f762652..b61a8fa 100644 --- a/lib/Components/image_input_container.dart +++ b/lib/Components/image_input_container.dart @@ -1,6 +1,7 @@ import 'package:auto_size_text/auto_size_text.dart'; import 'package:flutter/material.dart'; import 'package:manager_app/Components/loading_common.dart'; +import 'package:manager_app/Models/managerContext.dart'; import 'package:manager_app/app_context.dart'; import 'package:manager_app/constants.dart'; import 'package:manager_app/Screens/Resources/select_resource_modal.dart'; @@ -10,17 +11,17 @@ import 'package:provider/provider.dart'; class ImageInputContainer extends StatefulWidget { final Color color; final String label; - final String initialValue; + final String? initialValue; final ValueChanged onChanged; final BoxFit imageFit; final bool isSmall; final double fontSize; const ImageInputContainer({ - Key key, + Key? key, this.color = kSecond, - this.label, + required this.label, this.initialValue, - this.onChanged, + required this.onChanged, this.imageFit = BoxFit.cover, this.isSmall = false, this.fontSize = 25 @@ -31,7 +32,7 @@ class ImageInputContainer extends StatefulWidget { } class _ImageInputContainerState extends State { - String resourceIdToShow; + String? resourceIdToShow; @override void initState() { @@ -64,7 +65,7 @@ class _ImageInputContainerState extends State { height: size.width *0.08, child: InkWell( onTap: () async { - ResourceDTO result = await showSelectResourceModal( + ResourceDTO? result = await showSelectResourceModal( "Sélectionner une ressource", 1, [ResourceType.Image, ResourceType.ImageUrl], @@ -88,12 +89,12 @@ class _ImageInputContainerState extends State { ); } - getElement(String initialValue, BuildContext context, bool isSmall) { + getElement(String? initialValue, BuildContext context, bool isSmall) { if (resourceIdToShow != null) { Size size = MediaQuery.of(context).size; final appContext = Provider.of(context); return FutureBuilder( - future: getResource(resourceIdToShow, appContext), + future: getResource(resourceIdToShow!, appContext), builder: (context, AsyncSnapshot snapshot) { if (snapshot.connectionState == ConnectionState.done) { if (snapshot.data != null) { @@ -101,7 +102,15 @@ class _ImageInputContainerState extends State { decoration: boxDecoration(snapshot.data, appContext), ); } else { - return Text("No data"); + return Center( + child: Container( + decoration: boxDecoration(null, appContext), + child: Padding( + padding: const EdgeInsets.all(8.0), + child: Text("Aucune image"), + ) + ) + ); } } else if (snapshot.connectionState == ConnectionState.none) { @@ -136,22 +145,22 @@ class _ImageInputContainerState extends State { } } - Future getResource(String resourceIdToShow, dynamic appContext) async { - ResourceDTO resource = await appContext.getContext().clientAPI.resourceApi.resourceGetDetail(resourceIdToShow); + Future getResource(String resourceIdToShow, dynamic appContext) async { + ResourceDTO? resource = await (appContext.getContext() as ManagerAppContext).clientAPI!.resourceApi!.resourceGetDetail(resourceIdToShow); return resource; } - boxDecoration(ResourceDTO resourceDTO, appContext) { + boxDecoration(ResourceDTO? resourceDTO, AppContext appContext) { return BoxDecoration( shape: BoxShape.rectangle, color: kWhite, borderRadius: BorderRadius.circular(30.0), - image: new DecorationImage( + image: resourceDTO != null ? resourceDTO.type != null ? new DecorationImage( fit: widget.imageFit, - image: resourceDTO.type != null ? new NetworkImage( - resourceDTO.type == ResourceType.Image ? appContext.getContext().clientAPI.resourceApi.apiClient.basePath+"/api/Resource/"+ resourceDTO.id : resourceDTO.data, - ) : null, - ), + image: new NetworkImage( + resourceDTO.type! == ResourceType.Image ? (appContext.getContext() as ManagerAppContext).clientAPI!.resourceApi!.apiClient.basePath+"/api/Resource/"+ resourceDTO.id! : resourceDTO.data!, + ), + ) : null : null, boxShadow: [ BoxShadow( spreadRadius: 0.5, diff --git a/lib/Components/loading.dart b/lib/Components/loading.dart index 8853516..52202cc 100644 --- a/lib/Components/loading.dart +++ b/lib/Components/loading.dart @@ -2,7 +2,7 @@ import 'package:flare_flutter/flare_actor.dart'; import 'package:flutter/material.dart'; class Loading extends StatelessWidget { - Loading({Key key}) : super(key: key); + Loading({Key? key}) : super(key: key); @override Widget build(BuildContext context) { diff --git a/lib/Components/loading_common.dart b/lib/Components/loading_common.dart index 4b40fa5..106cbc2 100644 --- a/lib/Components/loading_common.dart +++ b/lib/Components/loading_common.dart @@ -2,14 +2,14 @@ import 'package:flutter/material.dart'; import 'package:manager_app/constants.dart'; class LoadingCommon extends StatefulWidget { - const LoadingCommon({Key key}) : super(key: key); + const LoadingCommon({Key? key}) : super(key: key); @override State createState() => _LoadingCommonState(); } class _LoadingCommonState extends State with TickerProviderStateMixin { - AnimationController _controller; + AnimationController? _controller; @override void initState() { @@ -22,25 +22,25 @@ class _LoadingCommonState extends State with TickerProviderStateM @override void dispose() { - _controller.dispose(); + _controller!.dispose(); super.dispose(); } @override Widget build(BuildContext context) { Size size = MediaQuery.of(context).size; - _controller.forward(from: 0.0); - _controller.addListener(() { - if (_controller.isCompleted) { - _controller.reverse(); + _controller!.forward(from: 0.0); + _controller!.addListener(() { + if (_controller!.isCompleted) { + _controller!.reverse(); } - if(_controller.isDismissed){ - _controller.forward(); + if(_controller!.isDismissed){ + _controller!.forward(); } }); return Center( child: RotationTransition( - turns: Tween(begin: 0.0, end: 3.0).animate(_controller), + turns: Tween(begin: 0.0, end: 3.0).animate(_controller!), child: Icon(Icons.museum_outlined, color: kPrimaryColor, size: size.height*0.1), ), ); diff --git a/lib/Components/message_notification.dart b/lib/Components/message_notification.dart index 3cca683..0709399 100644 --- a/lib/Components/message_notification.dart +++ b/lib/Components/message_notification.dart @@ -1,6 +1,6 @@ import 'package:flutter/material.dart'; -showNotification (Color backgroundColor, Color textColor, String text, BuildContext context, int duration) { +showNotification (Color backgroundColor, Color textColor, String text, BuildContext context, int? duration) { final snackBar = SnackBar( behavior: SnackBarBehavior.floating, duration: duration == null ? Duration(milliseconds: 1500) : Duration(milliseconds: duration), diff --git a/lib/Components/multi_input_modal.dart b/lib/Components/multi_input_modal.dart index ca6148e..700ab41 100644 --- a/lib/Components/multi_input_modal.dart +++ b/lib/Components/multi_input_modal.dart @@ -93,7 +93,7 @@ showMultiStringInput (String label, String modalLabel, bool isTitle, List newValues) { List translations = []; ManagerAppContext managerAppContext = appContext.getContext(); - for(var language in managerAppContext.selectedConfiguration.languages) { + for(var language in managerAppContext.selectedConfiguration!.languages!) { translations.add( Padding( padding: const EdgeInsets.all(8.0), @@ -122,7 +122,7 @@ getTranslations(BuildContext context, AppContext appContext, String label, bool label: label, color: kWhite, isTitle: isTitle, - initialValue: newValues.where((element) => element.language == language).first.value, + initialValue: newValues.where((element) => element.language == language).first.value!, onChanged: (value) { newValues.where((element) => element.language == language).first.value = value; }, diff --git a/lib/Components/multi_select_container.dart b/lib/Components/multi_select_container.dart index 3892e5a..2e6a0d3 100644 --- a/lib/Components/multi_select_container.dart +++ b/lib/Components/multi_select_container.dart @@ -12,14 +12,14 @@ class MultiSelectContainer extends StatelessWidget { final bool isAtLeastOne; final ValueChanged> onChanged; const MultiSelectContainer({ - Key key, + Key? key, this.color = kSecond, - this.label, - this.values, - this.initialValue, - this.isMultiple, + required this.label, + required this.values, + required this.initialValue, + required this.isMultiple, this.isAtLeastOne = false, - this.onChanged, + required this.onChanged, }) : super(key: key); @override @@ -64,7 +64,7 @@ class MultiSelectChip extends StatefulWidget { this.selectedValues, this.isMultiple, this.isAtLeastOne, - {this.onSelectionChanged} // +added + {required this.onSelectionChanged} // +added ); @override _MultiSelectChipState createState() => _MultiSelectChipState(); diff --git a/lib/Components/multi_select_dropdown_container.dart b/lib/Components/multi_select_dropdown_container.dart index 2957fa7..a8acee1 100644 --- a/lib/Components/multi_select_dropdown_container.dart +++ b/lib/Components/multi_select_dropdown_container.dart @@ -16,15 +16,15 @@ class MultiSelectDropdownContainer extends StatelessWidget { final double fontSize; final ValueChanged> onChanged; const MultiSelectDropdownContainer({ - Key key, + Key? key, this.color = kSecond, - this.label, - this.values, - this.initialValue, - this.isMultiple, + required this.label, + required this.values, + required this.initialValue, + required this.isMultiple, this.isAtLeastOne = false, this.fontSize = 25, - this.onChanged, + required this.onChanged, }) : super(key: key); @override @@ -63,6 +63,11 @@ class MultiSelectDropdownContainer extends StatelessWidget { onSelectionChanged: (selectedList) { onChanged(selectedList); }, + onConfirm: (List test) + { + print("onConfirm MultiSelectDialogField"); + print(test); + }, ), ), ), diff --git a/lib/Components/multi_string_input_container.dart b/lib/Components/multi_string_input_container.dart index a44a80f..e67d77e 100644 --- a/lib/Components/multi_string_input_container.dart +++ b/lib/Components/multi_string_input_container.dart @@ -17,14 +17,14 @@ class MultiStringContainer extends StatelessWidget { final bool isAudio; final double fontSize; const MultiStringContainer({ - Key key, + Key? key, this.color = kSecond, - this.label, - this.modalLabel, - this.initialValue, - this.onGetResult, - this.maxLines, - this.isTitle, + required this.label, + required this.modalLabel, + required this.initialValue, + required this.onGetResult, + required this.maxLines, + required this.isTitle, this.isAudio = false, this.fontSize = 25, }) : super(key: key); @@ -61,7 +61,7 @@ class MultiStringContainer extends StatelessWidget { languages.forEach((value) { if(initials.map((iv) => iv.language).contains(value)) { - newValues.add(TranslationDTO.fromJson(jsonDecode(jsonEncode(initials.firstWhere((element) => element.language == value))))); + newValues.add(TranslationDTO.fromJson(jsonDecode(jsonEncode(initials.firstWhere((element) => element.language == value)))!)!); } else { // New language newValues.add(TranslationDTO(language: value, value: null)); diff --git a/lib/Components/number_input_container.dart b/lib/Components/number_input_container.dart index 3b9caac..3e0d20a 100644 --- a/lib/Components/number_input_container.dart +++ b/lib/Components/number_input_container.dart @@ -14,11 +14,11 @@ class NumberInputContainer extends StatelessWidget { final double fontSize; final double fontSizeText; const NumberInputContainer({ - Key key, + Key? key, this.color = kSecond, - this.label, - this.initialValue, - this.onChanged, + required this.label, + required this.initialValue, + required this.onChanged, this.isUrl = false, this.isSmall = false, this.maxLength = 50, diff --git a/lib/Components/resource_tab.dart b/lib/Components/resource_tab.dart index 3fbc104..39de2ed 100644 --- a/lib/Components/resource_tab.dart +++ b/lib/Components/resource_tab.dart @@ -12,10 +12,10 @@ class ResourceTab extends StatefulWidget { final Function onFileUpload; final Function onFileUploadWeb; const ResourceTab({ - Key key, - this.resourceDTO, - this.onFileUpload, - this.onFileUploadWeb, + Key? key, + required this.resourceDTO, + required this.onFileUpload, + required this.onFileUploadWeb, }) : super(key: key); @override @@ -23,7 +23,7 @@ class ResourceTab extends StatefulWidget { } class _ResourceTabState extends State with SingleTickerProviderStateMixin { - TabController _tabController; + TabController? _tabController; List tabsToShow = []; @override @@ -34,7 +34,7 @@ class _ResourceTabState extends State with SingleTickerProviderStat //tabsToShow.add(new Tab(text: "Vidéo en ligne")); _tabController = new TabController(length: 3, vsync: this); - _tabController.addListener(_handleTabSelection); + _tabController!.addListener(_handleTabSelection); super.initState(); } @@ -67,7 +67,7 @@ class _ResourceTabState extends State with SingleTickerProviderStat } void _handleTabSelection() { - switch(_tabController.index) { + switch(_tabController!.index) { case 0: setState(() { widget.resourceDTO.data = null; @@ -98,11 +98,11 @@ getContent(ResourceDTO resourceDTO, Function onFileUpload, Function onFileUpload new Padding( padding: EdgeInsets.symmetric(horizontal: 8, vertical: 16), child: UploadImageContainer( - onChanged: (List files) { + onChanged: (List? files) { onFileUpload(files); resourceDTO.type = ResourceType.Image; }, - onChangedWeb: (List files) { + onChangedWeb: (List? files) { onFileUploadWeb(files); resourceDTO.type = ResourceType.Image; }, diff --git a/lib/Components/rounded_button.dart b/lib/Components/rounded_button.dart index dc0d285..08268f6 100644 --- a/lib/Components/rounded_button.dart +++ b/lib/Components/rounded_button.dart @@ -5,20 +5,20 @@ import 'package:manager_app/constants.dart'; class RoundedButton extends StatelessWidget { final String text; final Function press; - final IconData icon; + final IconData? icon; final Color color, textColor; final double fontSize; - final double vertical; - final double horizontal; + final double? vertical; + final double? horizontal; const RoundedButton({ - Key key, - this.text, - this.press, + Key? key, + required this.text, + required this.press, this.icon, this.color = kPrimaryColor, this.textColor = kWhite, - this.fontSize, + required this.fontSize, this.vertical, this.horizontal }) : super(key: key); @@ -28,7 +28,7 @@ class RoundedButton extends StatelessWidget { //Size size = MediaQuery.of(context).size; return TextButton( style: ButtonStyle( - padding: MaterialStateProperty.resolveWith((states) => EdgeInsets.symmetric(vertical: this.vertical != null ? this.vertical : 25, horizontal: this.horizontal != null ? this.horizontal : (icon == null ? 85 : 30))), + padding: MaterialStateProperty.resolveWith((states) => EdgeInsets.symmetric(vertical: this.vertical != null ? this.vertical! : 25, horizontal: this.horizontal != null ? this.horizontal!: (icon == null ? 85 : 30))), backgroundColor: MaterialStateColor.resolveWith((states) => color), shape: MaterialStateProperty.all( RoundedRectangleBorder( diff --git a/lib/Components/rounded_input_field.dart b/lib/Components/rounded_input_field.dart index 7b4a656..805481f 100644 --- a/lib/Components/rounded_input_field.dart +++ b/lib/Components/rounded_input_field.dart @@ -4,25 +4,25 @@ import 'package:manager_app/Components/text_field_container.dart'; import 'package:manager_app/constants.dart'; class RoundedInputField extends StatelessWidget { - final String hintText; - final IconData icon; + final String? hintText; + final IconData? icon; final ValueChanged onChanged; - final String initialValue; + final String? initialValue; final Color color, textColor, iconColor; - final int maxLength; + final int? maxLength; final bool isEmail; final double fontSize; - final String autofill; + final String? autofill; final bool isInt; const RoundedInputField({ - Key key, + Key? key, this.hintText, this.initialValue, this.icon, this.color = kSecond, this.textColor = kBlack, this.iconColor = kPrimaryColor, - this.onChanged, + required this.onChanged, this.maxLength, // 50 this.isEmail = false, this.fontSize = 20, @@ -39,7 +39,7 @@ class RoundedInputField extends StatelessWidget { initialValue: initialValue, cursorColor: textColor, maxLength: maxLength, - autofillHints: [autofill], + autofillHints: autofill != null ? [autofill!] : [], keyboardType: isEmail ? TextInputType.emailAddress : isInt ? TextInputType.number : TextInputType.text, inputFormatters: !isInt ? [] : [ FilteringTextInputFormatter.digitsOnly diff --git a/lib/Components/rounded_password_field.dart b/lib/Components/rounded_password_field.dart index 0959f7c..469ce1c 100644 --- a/lib/Components/rounded_password_field.dart +++ b/lib/Components/rounded_password_field.dart @@ -6,9 +6,9 @@ class RoundedPasswordField extends StatefulWidget { final ValueChanged onChanged; final String initialValue; const RoundedPasswordField({ - Key key, - this.onChanged, - this.initialValue + Key? key, + required this.onChanged, + required this.initialValue }) : super(key: key); @override diff --git a/lib/Components/slider_input_container.dart b/lib/Components/slider_input_container.dart index d9b0e7c..22f87ca 100644 --- a/lib/Components/slider_input_container.dart +++ b/lib/Components/slider_input_container.dart @@ -9,13 +9,13 @@ class SliderInputContainer extends StatefulWidget { final int max; final ValueChanged onChanged; const SliderInputContainer({ - Key key, + Key? key, this.color = kSecond, - this.label, - this.initialValue, - this.min, - this.max, - this.onChanged, + required this.label, + required this.initialValue, + required this.min, + required this.max, + required this.onChanged, }) : super(key: key); @override @@ -23,7 +23,7 @@ class SliderInputContainer extends StatefulWidget { } class _SliderInputContainerState extends State { - double currentValue; + double? currentValue; @override void initState() { @@ -43,7 +43,7 @@ class _SliderInputContainerState extends State { Padding( padding: const EdgeInsets.all(10.0), child: Slider( - value: currentValue, + value: currentValue!, onChanged: (value) { setState(() => currentValue = value); widget.onChanged(value); diff --git a/lib/Components/string_input_container.dart b/lib/Components/string_input_container.dart index 0b73f92..9244996 100644 --- a/lib/Components/string_input_container.dart +++ b/lib/Components/string_input_container.dart @@ -4,9 +4,9 @@ import 'package:manager_app/Components/rounded_input_field.dart'; import 'package:manager_app/constants.dart'; class StringInputContainer extends StatelessWidget { - final Color color; + final Color? color; final String label; - final String initialValue; + final String? initialValue; final ValueChanged onChanged; final bool isUrl; final bool isSmall; @@ -14,11 +14,11 @@ class StringInputContainer extends StatelessWidget { final double fontSize; final double fontSizeText; const StringInputContainer({ - Key key, + Key? key, this.color = kSecond, - this.label, - this.initialValue, - this.onChanged, + required this.label, + this.initialValue = "", + required this.onChanged, this.isUrl = false, this.isSmall = false, this.maxLength = 50, @@ -29,6 +29,7 @@ class StringInputContainer extends StatelessWidget { @override Widget build(BuildContext context) { Size size = MediaQuery.of(context).size; + return Container( child: Row( children: [ @@ -47,7 +48,7 @@ class StringInputContainer extends StatelessWidget { child: Container( width: isUrl ? size.width *0.6 : isSmall ? size.width *0.1 : size.width *0.2, child: RoundedInputField( - color: color, + color: color!, textColor: kBlack, fontSize: fontSizeText, initialValue: initialValue, diff --git a/lib/Components/text_field_container.dart b/lib/Components/text_field_container.dart index a39a53b..fc0e94e 100644 --- a/lib/Components/text_field_container.dart +++ b/lib/Components/text_field_container.dart @@ -5,8 +5,8 @@ class TextFieldContainer extends StatelessWidget { final Widget child; final Color color; const TextFieldContainer({ - Key key, - this.child, + Key? key, + required this.child, this.color = kSecond, }) : super(key: key); diff --git a/lib/Components/text_form_input_container.dart b/lib/Components/text_form_input_container.dart index 3765b18..24a6b06 100644 --- a/lib/Components/text_form_input_container.dart +++ b/lib/Components/text_form_input_container.dart @@ -9,13 +9,13 @@ class TextFormInputContainer extends StatelessWidget { final int maxLines; final ValueChanged onChanged; const TextFormInputContainer({ - Key key, + Key? key, this.color = kSecond, - this.label, - this.initialValue, - this.isTitle, + required this.label, + required this.initialValue, + required this.isTitle, this.maxLines = 5, - this.onChanged + required this.onChanged }) : super(key: key); @override diff --git a/lib/Components/translation_tab.dart b/lib/Components/translation_tab.dart index e9737e4..21ccc31 100644 --- a/lib/Components/translation_tab.dart +++ b/lib/Components/translation_tab.dart @@ -5,9 +5,9 @@ class TranslationTab extends StatefulWidget { final List translations; final int maxLines; const TranslationTab({ - Key key, - this.translations, - this.maxLines, + Key? key, + required this.translations, + required this.maxLines, }) : super(key: key); @override @@ -15,7 +15,7 @@ class TranslationTab extends StatefulWidget { } class _TranslationTabState extends State with SingleTickerProviderStateMixin { - TabController _tabController; + TabController? _tabController; @override void initState() { diff --git a/lib/Components/upload_audio_container.dart b/lib/Components/upload_audio_container.dart index d40c636..4c86a40 100644 --- a/lib/Components/upload_audio_container.dart +++ b/lib/Components/upload_audio_container.dart @@ -8,9 +8,9 @@ class UploadAudioContainer extends StatefulWidget { final ValueChanged> onChanged; final ValueChanged> onChangedWeb; const UploadAudioContainer({ - Key key, - this.onChanged, - this.onChangedWeb, + Key? key, + required this.onChanged, + required this.onChangedWeb, }) : super(key: key); @override @@ -19,8 +19,8 @@ class UploadAudioContainer extends StatefulWidget { class _UploadAudioContainerState extends State with SingleTickerProviderStateMixin { var filePath; - File fileToShow; - String fileToShowWeb; + File? fileToShow; + String? fileToShowWeb; @override void initState() { @@ -42,7 +42,7 @@ class _UploadAudioContainerState extends State with Single } Future filePicker() async { - FilePickerResult result; + FilePickerResult? result; if (kIsWeb) { result = await FilePicker.platform.pickFiles( type: FileType.custom, @@ -68,13 +68,15 @@ class _UploadAudioContainerState extends State with Single allowedExtensions: ['mp3'], ); - List files = result.paths.map((path) => File(path)).toList(); - var file = files[0]; - setState(() { - filePath = file.path; // Only show one picture - fileToShow = file; // Only show one picture - widget.onChanged(files); - }); + if(result != null) { + List files = result.paths.map((path) => File(path!)).toList(); + var file = files[0]; + setState(() { + filePath = file.path; // Only show one picture + fileToShow = file; // Only show one picture + widget.onChanged(files); + }); + } } /*final file = OpenFilePicker() ..filterSpecification = { diff --git a/lib/Components/upload_image_container.dart b/lib/Components/upload_image_container.dart index ad2d561..7b7ccd0 100644 --- a/lib/Components/upload_image_container.dart +++ b/lib/Components/upload_image_container.dart @@ -5,12 +5,12 @@ import 'package:flutter/material.dart'; import 'package:flutter/foundation.dart' show kIsWeb; class UploadImageContainer extends StatefulWidget { - final ValueChanged> onChanged; - final ValueChanged> onChangedWeb; + final ValueChanged?> onChanged; + final ValueChanged?> onChangedWeb; const UploadImageContainer({ - Key key, - this.onChanged, - this.onChangedWeb, + Key? key, + required this.onChanged, + required this.onChangedWeb, }) : super(key: key); @override @@ -19,8 +19,8 @@ class UploadImageContainer extends StatefulWidget { class _UploadImageContainerState extends State with SingleTickerProviderStateMixin { var filePath; - File fileToShow; - String fileToShowWeb; + File? fileToShow; + String? fileToShowWeb; @override void initState() { @@ -42,7 +42,7 @@ class _UploadImageContainerState extends State with Single } Future filePicker() async { - FilePickerResult result; + FilePickerResult? result; if (kIsWeb) { result = await FilePicker.platform.pickFiles( type: FileType.custom, @@ -68,13 +68,15 @@ class _UploadImageContainerState extends State with Single allowedExtensions: ['jpg', 'jpeg', 'png'], ); - List files = result.paths.map((path) => File(path)).toList(); - var file = files[0]; - setState(() { - filePath = file.path; // Only show one picture - fileToShow = file; // Only show one picture - widget.onChanged(files); - }); + if (result != null) { + List files = result.paths.map((path) => File(path!)).toList(); + var file = files[0]; + setState(() { + filePath = file.path; // Only show one picture + fileToShow = file; // Only show one picture + widget.onChanged(files); + }); + } } /*final file = OpenFilePicker() ..filterSpecification = { @@ -136,11 +138,13 @@ class _UploadImageContainerState extends State with Single if (kIsWeb) { return null; } else { - return Image.file( - fileToShow, - height: 200, - fit:BoxFit.scaleDown - ); + if(fileToShow != null) { + return Image.file( + fileToShow!, + height: 200, + fit:BoxFit.scaleDown + ); + } } } } diff --git a/lib/Components/upload_online_resources_container.dart b/lib/Components/upload_online_resources_container.dart index a72de1e..48ded7e 100644 --- a/lib/Components/upload_online_resources_container.dart +++ b/lib/Components/upload_online_resources_container.dart @@ -7,9 +7,9 @@ class UploadOnlineResourceContainer extends StatefulWidget { final ResourceDTO resourceDTO; final ValueChanged onChanged; const UploadOnlineResourceContainer({ - Key key, - this.resourceDTO, - this.onChanged, + Key? key, + required this.resourceDTO, + required this.onChanged, }) : super(key: key); @override @@ -17,7 +17,7 @@ class UploadOnlineResourceContainer extends StatefulWidget { } class _UploadOnlineResourceContainerState extends State with SingleTickerProviderStateMixin { - String urlResourceToShow; + String? urlResourceToShow; @override void initState() { @@ -64,11 +64,11 @@ class _UploadOnlineResourceContainerState extends State storeConfiguration(ExportConfigurationDTO exportConfigurationDTO) async { final path = await _localPath; - new File('$path/'+exportConfigurationDTO.label+'.json').createSync(recursive: true); + new File('$path/'+exportConfigurationDTO.label!+'.json').createSync(recursive: true); // Write the file - File file = File('$path/'+exportConfigurationDTO.label+'.json'); + File file = File('$path/'+exportConfigurationDTO.label!+'.json'); return file.writeAsString(jsonEncode(exportConfigurationDTO.toJson())); } - Future importConfiguration(FilePickerResult filePickerResult, String path, Client client, context) async { + Future importConfiguration(FilePickerResult filePickerResult, String? path, Client client, context) async { var fileTest = filePickerResult.files[0]; - String fileContent = utf8.decode(fileTest.bytes); - ExportConfigurationDTO export = ExportConfigurationDTO.fromJson(jsonDecode(fileContent)); + String fileContent = utf8.decode(fileTest.bytes!); + ExportConfigurationDTO export = ExportConfigurationDTO.fromJson(jsonDecode(fileContent))!; try { - String test = await client.configurationApi.configurationImport(export); - if (test.contains("successfully")) { + String? test = await client.configurationApi!.configurationImport(export); + if (test != null && test.contains("successfully")) { showNotification(kSuccess, kWhite, 'La configuration a été importée avec succès', context, null); } else { showNotification(kPrimaryColor, kWhite, 'Une erreur est survenue lors de l''import de la configuration', context, null); @@ -76,7 +76,7 @@ class FileHelper { var encrypter = Encrypter(AES(key)); if (session.password != null) { - session.password = encrypter.decrypt64(session.password, iv: iv); + session.password = encrypter.decrypt64(session.password!, iv: iv); } return session; diff --git a/lib/Helpers/PDFHelper.dart b/lib/Helpers/PDFHelper.dart index 10690ac..65c8201 100644 --- a/lib/Helpers/PDFHelper.dart +++ b/lib/Helpers/PDFHelper.dart @@ -23,10 +23,10 @@ class PDFHelper { child: pw.Column( children: [ - pw.Text(section.label.replaceAll(RegExp("[^A-Za-z0-9---():!éàèëêäâç' ]"), '')), //style: pw.TextStyle(font: ttf, fontSize: 30) + pw.Text(section.label!.replaceAll(RegExp("[^A-Za-z0-9---():!éàèëêäâç' ]"), '')), //style: pw.TextStyle(font: ttf, fontSize: 30) pw.Padding(padding: const pw.EdgeInsets.only(top: 20)), pw.BarcodeWidget( - data: section.id, + data: section.id!, width: 150, height: 150, barcode: pw.Barcode.qrCode(), diff --git a/lib/Models/Model.dart b/lib/Models/Model.dart index e39a1dc..7b7f592 100644 --- a/lib/Models/Model.dart +++ b/lib/Models/Model.dart @@ -7,7 +7,7 @@ import 'package:password_credential/entity/result.dart'; class Model with ChangeNotifier { final _credentials = Credentials(); - bool hasCredentialFeature = false; + bool? hasCredentialFeature = false; var idEdit = TextEditingController(); var passwordEdit = TextEditingController(); @@ -26,11 +26,11 @@ class Model with ChangeNotifier { Future get(Mediation mediation) async { var credential = await _credentials.get(mediation: mediation); if (credential != null) { - idEdit.text = credential.id; - passwordEdit.text = credential.password; + idEdit.text = credential.id!; + passwordEdit.text = credential.password!; notifyListeners(); } - return credential; + return credential!; } Future delete() async { diff --git a/lib/Models/managerContext.dart b/lib/Models/managerContext.dart index 4b5fff1..bc30390 100644 --- a/lib/Models/managerContext.dart +++ b/lib/Models/managerContext.dart @@ -4,15 +4,15 @@ import 'package:manager_api_new/api.dart'; class ManagerAppContext with ChangeNotifier{ - String email; - String instanceId; - String host; - String accessToken; - Client clientAPI; - String currentRoute; - ConfigurationDTO selectedConfiguration; - SectionDTO selectedSection; - bool isLoading = false; + String? email; + String? instanceId; + String? host; + String? accessToken; + Client? clientAPI; + String? currentRoute; + ConfigurationDTO? selectedConfiguration; + SectionDTO? selectedSection; + bool? isLoading = false; ManagerAppContext({this.email, this.accessToken, this.currentRoute}); diff --git a/lib/Models/menu.dart b/lib/Models/menu.dart index c905bbc..e4ac236 100644 --- a/lib/Models/menu.dart +++ b/lib/Models/menu.dart @@ -2,9 +2,9 @@ import 'package:manager_app/Models/menuSection.dart'; class Menu { String title; - List sections; + List? sections; - Menu({this.title, this.sections}); + Menu({required this.title, this.sections}); factory Menu.fromJson(Map json) { return new Menu( diff --git a/lib/Models/menuSection.dart b/lib/Models/menuSection.dart index ed2e89e..e06a450 100644 --- a/lib/Models/menuSection.dart +++ b/lib/Models/menuSection.dart @@ -3,7 +3,7 @@ class MenuSection { String type; int order; - MenuSection({this.name, this.type, this.order}); + MenuSection({required this.name, required this.type, required this.order}); factory MenuSection.fromJson(Map json) { return new MenuSection( diff --git a/lib/Models/resourceTypeModel.dart b/lib/Models/resourceTypeModel.dart index c9b83eb..58329a0 100644 --- a/lib/Models/resourceTypeModel.dart +++ b/lib/Models/resourceTypeModel.dart @@ -4,7 +4,7 @@ class ResourceTypeModel { String label; ResourceType type; - ResourceTypeModel({this.label, this.type}); + ResourceTypeModel({required this.label, required this.type}); factory ResourceTypeModel.fromJson(Map json) { return new ResourceTypeModel( diff --git a/lib/Models/session.dart b/lib/Models/session.dart index a33910a..3174eea 100644 --- a/lib/Models/session.dart +++ b/lib/Models/session.dart @@ -1,10 +1,10 @@ class Session { bool rememberMe; - String host; - String email; - String password; + String? host; + String? email; + String? password; - Session({this.rememberMe, this.host, this.email, this.password}); + Session({required this.rememberMe, this.host, this.email, this.password}); factory Session.fromJson(Map json) { return new Session( diff --git a/lib/Screens/Configurations/Section/SubSection/Article/article_config.dart b/lib/Screens/Configurations/Section/SubSection/Article/article_config.dart index b09993b..5c83641 100644 --- a/lib/Screens/Configurations/Section/SubSection/Article/article_config.dart +++ b/lib/Screens/Configurations/Section/SubSection/Article/article_config.dart @@ -13,16 +13,16 @@ import 'package:provider/provider.dart'; class ArticleConfig extends StatefulWidget { - final String color; - final String label; + final String? color; + final String? label; final String initialValue; final ValueChanged onChanged; const ArticleConfig({ - Key key, + Key? key, this.color, this.label, - this.initialValue, - this.onChanged, + required this.initialValue, + required this.onChanged, }) : super(key: key); @override @@ -30,16 +30,16 @@ class ArticleConfig extends StatefulWidget { } class _ArticleConfigState extends State { - ArticleDTO articleDTO; + late ArticleDTO articleDTO; @override void initState() { super.initState(); - articleDTO = ArticleDTO.fromJson(json.decode(widget.initialValue)); - List test = new List.from(articleDTO.images); + articleDTO = ArticleDTO.fromJson(json.decode(widget.initialValue))!; + List test = new List.from(articleDTO.images!); articleDTO.images = test; - articleDTO.images.sort((a, b) => a.order.compareTo(b.order)); + articleDTO.images!.sort((a, b) => a.order!.compareTo(b.order!)); } @override @@ -53,11 +53,11 @@ class _ArticleConfigState extends State { if (newIndex > oldIndex) { newIndex -= 1; } - final ImageDTO item = articleDTO.images.removeAt(oldIndex); - articleDTO.images.insert(newIndex, item); + final ImageDTO item = articleDTO.images!.removeAt(oldIndex); + articleDTO.images!.insert(newIndex, item); var i = 0; - articleDTO.images.forEach((image) { + articleDTO.images!.forEach((image) { image.order = i; i++; }); @@ -83,11 +83,11 @@ class _ArticleConfigState extends State { label: "Contenu affiché :", modalLabel: "Contenu", color: kPrimaryColor, - initialValue: articleDTO != null ? articleDTO.content : [], + initialValue: articleDTO != null ? articleDTO.content! : [], isTitle: false, onGetResult: (value) { setState(() { - if (articleDTO.content != value) { + if (articleDTO.content! != value) { articleDTO.content = value; //save(true, articleDTO, appContext); widget.onChanged(jsonEncode(articleDTO).toString()); @@ -117,7 +117,7 @@ class _ArticleConfigState extends State { isAudio: true, modalLabel: "Audio", color: kPrimaryColor, - initialValue: articleDTO != null ? articleDTO.audioIds : [], + initialValue: articleDTO != null ? articleDTO.audioIds! : [], isTitle: false, onGetResult: (value) { setState(() { @@ -165,10 +165,10 @@ class _ArticleConfigState extends State { scrollDirection: Axis.horizontal, padding: const EdgeInsets.symmetric(vertical: 20.0), children: List.generate( - articleDTO.images.length, + articleDTO.images!.length, (index) { return ListViewCardImage( - articleDTO.images, + articleDTO.images!, index, Key('$index'), appContext, @@ -212,8 +212,8 @@ class _ArticleConfigState extends State { if (result != null) { setState(() { - result.order = articleDTO.images.length; - articleDTO.images.add(result); + result.order = articleDTO.images!.length; + articleDTO.images!.add(result); widget.onChanged(jsonEncode(articleDTO).toString()); }); } diff --git a/lib/Screens/Configurations/Section/SubSection/Article/download_pdf.dart b/lib/Screens/Configurations/Section/SubSection/Article/download_pdf.dart index 4c42953..3e0d120 100644 --- a/lib/Screens/Configurations/Section/SubSection/Article/download_pdf.dart +++ b/lib/Screens/Configurations/Section/SubSection/Article/download_pdf.dart @@ -6,8 +6,8 @@ import 'package:manager_api_new/api.dart'; class DownloadPDF extends StatefulWidget { final List sections; const DownloadPDF({ - Key key, - this.sections, + Key? key, + required this.sections, }) : super(key: key); @override diff --git a/lib/Screens/Configurations/Section/SubSection/Map/geopoint_image_list.dart b/lib/Screens/Configurations/Section/SubSection/Map/geopoint_image_list.dart index 8cfb3b4..b9618c5 100644 --- a/lib/Screens/Configurations/Section/SubSection/Map/geopoint_image_list.dart +++ b/lib/Screens/Configurations/Section/SubSection/Map/geopoint_image_list.dart @@ -1,4 +1,5 @@ import 'package:flutter/material.dart'; +import 'package:manager_app/Models/managerContext.dart'; import 'package:manager_app/Screens/Configurations/Section/SubSection/Map/listView_card_geoPoint_images.dart'; import 'package:manager_app/Screens/Resources/select_resource_modal.dart'; import 'package:manager_app/app_context.dart'; @@ -10,9 +11,9 @@ class GeoPointImageList extends StatefulWidget { final List images; final ValueChanged> onChanged; const GeoPointImageList({ - Key key, - this.images, - this.onChanged, + Key? key, + required this.images, + required this.onChanged, }) : super(key: key); @override @@ -20,7 +21,7 @@ class GeoPointImageList extends StatefulWidget { } class _GeoPointImageListState extends State { - List imagesGeo; + late List imagesGeo; @override void initState() { @@ -96,7 +97,7 @@ class _GeoPointImageListState extends State { ); if (result != null) { setState(() { - ImageGeoPoint newImage = new ImageGeoPoint(imageResourceId: result.id, imageSource: result.type == ResourceType.ImageUrl ? result.data : appContext.getContext().clientAPI.resourceApi.apiClient.basePath+"/api/Resource/"+ result.id); + ImageGeoPoint newImage = new ImageGeoPoint(imageResourceId: result.id, imageSource: result.type == ResourceType.ImageUrl ? result.data : (appContext.getContext() as ManagerAppContext).clientAPI!.resourceApi!.apiClient.basePath+"/api/Resource/"+ result.id); //print("REULT IMAGES = "); //print(newImage); imagesGeo.add(newImage); diff --git a/lib/Screens/Configurations/Section/SubSection/Map/listView_card_geoPoint_images.dart b/lib/Screens/Configurations/Section/SubSection/Map/listView_card_geoPoint_images.dart index c025cff..8bb6d63 100644 --- a/lib/Screens/Configurations/Section/SubSection/Map/listView_card_geoPoint_images.dart +++ b/lib/Screens/Configurations/Section/SubSection/Map/listView_card_geoPoint_images.dart @@ -82,10 +82,10 @@ class _ListViewCardGeoPointImagesState extends State children: [ Center( child: Image.network( - imageGeoPoint.imageSource, + imageGeoPoint.imageSource!, fit:BoxFit.scaleDown, loadingBuilder: (BuildContext context, Widget child, - ImageChunkEvent loadingProgress) { + ImageChunkEvent? loadingProgress) { if (loadingProgress == null) { return child; } @@ -94,7 +94,7 @@ class _ListViewCardGeoPointImagesState extends State color: kPrimaryColor, value: loadingProgress.expectedTotalBytes != null ? loadingProgress.cumulativeBytesLoaded / - loadingProgress.expectedTotalBytes + loadingProgress.expectedTotalBytes! : null, ), ); diff --git a/lib/Screens/Configurations/Section/SubSection/Map/map_config.dart b/lib/Screens/Configurations/Section/SubSection/Map/map_config.dart index 0d3fd5a..94ed1f4 100644 --- a/lib/Screens/Configurations/Section/SubSection/Map/map_config.dart +++ b/lib/Screens/Configurations/Section/SubSection/Map/map_config.dart @@ -4,6 +4,7 @@ import 'package:manager_app/Components/fetch_section_icon.dart'; import 'package:manager_app/Components/image_input_container.dart'; import 'package:manager_app/Components/multi_select_container.dart'; import 'package:manager_app/Components/slider_input_container.dart'; +import 'package:manager_app/Models/managerContext.dart'; import 'package:manager_app/Screens/Configurations/Section/SubSection/Map/showNewOrUpdateGeoPoint.dart'; import 'package:manager_app/app_context.dart'; import 'package:manager_app/constants.dart'; @@ -13,16 +14,16 @@ import 'dart:convert'; import 'package:provider/provider.dart'; class MapConfig extends StatefulWidget { - final String color; - final String label; + final String? color; + final String? label; final String initialValue; final ValueChanged onChanged; const MapConfig({ - Key key, + Key? key, this.color, this.label, - this.initialValue, - this.onChanged, + required this.initialValue, + required this.onChanged, }) : super(key: key); @override @@ -30,19 +31,19 @@ class MapConfig extends StatefulWidget { } class _MapConfigState extends State { - MapDTO mapDTO; + late MapDTO mapDTO; String mapType= "hybrid"; @override void initState() { super.initState(); - mapDTO = MapDTO.fromJson(json.decode(widget.initialValue)); - List test = new List.from(mapDTO.points); + mapDTO = MapDTO.fromJson(json.decode(widget.initialValue))!; + List test = new List.from(mapDTO.points!); mapDTO.points = test; if(mapDTO.mapType != null) { - switch(mapDTO.mapType.value) { + switch(mapDTO.mapType!.value) { case 0: mapType = "none"; break; @@ -96,7 +97,7 @@ class _MapConfigState extends State { mapDTO.iconResourceId = null; } else { mapDTO.iconResourceId = resource.id; - mapDTO.iconSource = resource.type == ResourceType.ImageUrl ? resource.data : appContext.getContext().clientAPI.resourceApi.apiClient.basePath+"/api/Resource/"+ resource.id; + mapDTO.iconSource = resource.type == ResourceType.ImageUrl ? resource.data : (appContext.getContext() as ManagerAppContext).clientAPI!.resourceApi!.apiClient.basePath+"/api/Resource/"+ resource.id!; } widget.onChanged(jsonEncode(mapDTO).toString()); }, @@ -119,7 +120,7 @@ class _MapConfigState extends State { // Zoom SliderInputContainer( label: "Zoom:", - initialValue: mapDTO.zoom != null ? mapDTO.zoom.toDouble() : 18, + initialValue: mapDTO.zoom != null ? mapDTO.zoom!.toDouble() : 18, color: kPrimaryColor, min: 0, max: 30, @@ -145,14 +146,14 @@ class _MapConfigState extends State { child: GridView.builder( shrinkWrap: true, gridDelegate: new SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 8), - itemCount: mapDTO.points.length, + itemCount: mapDTO.points!.length, itemBuilder: (BuildContext context, int index) { return Container( - decoration: boxDecoration(mapDTO.points[index], appContext), + decoration: boxDecoration(mapDTO.points![index], appContext), padding: const EdgeInsets.all(5), margin: EdgeInsets.symmetric(vertical: 10, horizontal: 10), - child: getElement(index, mapDTO.points[index], size, appContext), + child: getElement(index, mapDTO.points![index], size, appContext), ); } ), @@ -174,7 +175,7 @@ class _MapConfigState extends State { null, (GeoPointDTO geoPoint) { setState(() { - mapDTO.points.add(geoPoint); + mapDTO.points!.add(geoPoint); widget.onChanged(jsonEncode(mapDTO).toString()); }); }, @@ -213,7 +214,7 @@ class _MapConfigState extends State { ); } - getElement(int index, GeoPointDTO point, Size size, AppContext appContext) { + getElement(int index, GeoPointDTO? point, Size size, AppContext appContext) { return Container( width: double.infinity, height: double.infinity, @@ -223,7 +224,7 @@ class _MapConfigState extends State { child: Padding( padding: const EdgeInsets.all(8.0), child: AutoSizeText( - point.title == null ? "" : point.title[0].value, + point != null ? point.title == null ? "" : point.title![0].value! : "", style: new TextStyle(fontSize: 20), maxLines: 2, textAlign: TextAlign.center, @@ -245,10 +246,10 @@ class _MapConfigState extends State { child: InkWell( onTap: () { showNewOrUpdateGeoPoint( - mapDTO.points[index], + mapDTO.points![index], (GeoPointDTO geoPoint) { setState(() { - mapDTO.points[index] = geoPoint; + mapDTO.points![index] = geoPoint; widget.onChanged(jsonEncode(mapDTO).toString()); }); }, @@ -268,7 +269,7 @@ class _MapConfigState extends State { child: InkWell( onTap: () { setState(() { - mapDTO.points.removeAt(index); + mapDTO.points!.removeAt(index); }); widget.onChanged(jsonEncode(mapDTO).toString()); }, diff --git a/lib/Screens/Configurations/Section/SubSection/Map/showNewOrUpdateGeoPoint.dart b/lib/Screens/Configurations/Section/SubSection/Map/showNewOrUpdateGeoPoint.dart index f99c094..3e1d2ed 100644 --- a/lib/Screens/Configurations/Section/SubSection/Map/showNewOrUpdateGeoPoint.dart +++ b/lib/Screens/Configurations/Section/SubSection/Map/showNewOrUpdateGeoPoint.dart @@ -9,7 +9,7 @@ import 'package:manager_app/app_context.dart'; import 'package:manager_app/constants.dart'; import 'package:manager_api_new/api.dart'; -void showNewOrUpdateGeoPoint(GeoPointDTO inputGeoPointDTO, Function getResult, AppContext appContext, BuildContext context) { +void showNewOrUpdateGeoPoint(GeoPointDTO? inputGeoPointDTO, Function getResult, AppContext appContext, BuildContext context) { GeoPointDTO geoPointDTO = new GeoPointDTO(); if (inputGeoPointDTO != null) { @@ -20,12 +20,12 @@ void showNewOrUpdateGeoPoint(GeoPointDTO inputGeoPointDTO, Function getResult, A geoPointDTO.images = []; ManagerAppContext managerAppContext = appContext.getContext(); - managerAppContext.selectedConfiguration.languages.forEach((element) { + managerAppContext.selectedConfiguration!.languages!.forEach((element) { var translationDTO = new TranslationDTO(); translationDTO.language = element; translationDTO.value = ""; - geoPointDTO.title.add(translationDTO); - geoPointDTO.description.add(translationDTO); + geoPointDTO.title!.add(translationDTO); + geoPointDTO.description!.add(translationDTO); }); } @@ -87,7 +87,7 @@ void showNewOrUpdateGeoPoint(GeoPointDTO inputGeoPointDTO, Function getResult, A ], ), child: GeoPointImageList( - images: geoPointDTO.images, + images: geoPointDTO.images!, onChanged: (List imagesOutput) { geoPointDTO.images = imagesOutput; }, @@ -152,7 +152,7 @@ void showNewOrUpdateGeoPoint(GeoPointDTO inputGeoPointDTO, Function getResult, A getTranslations(BuildContext context, AppContext appContext, GeoPointDTO geoPointDTO) { List translations = []; ManagerAppContext managerAppContext = appContext.getContext(); - for(var language in managerAppContext.selectedConfiguration.languages) { + for(var language in managerAppContext.selectedConfiguration!.languages!) { translations.add( Padding( padding: const EdgeInsets.all(8.0), @@ -181,18 +181,18 @@ getTranslations(BuildContext context, AppContext appContext, GeoPointDTO geoPoin label: "Titre:", color: kWhite, isTitle: true, - initialValue: geoPointDTO.title.where((element) => element.language == language).first.value, + initialValue: geoPointDTO.title!.where((element) => element.language == language).first.value!, onChanged: (value) { - geoPointDTO.title.where((element) => element.language == language).first.value = value; + geoPointDTO.title!.where((element) => element.language == language).first.value = value; }, ), TextFormInputContainer( label: "Description:", color: kWhite, isTitle: false, - initialValue: geoPointDTO.description.where((element) => element.language == language).first.value, + initialValue: geoPointDTO.description!.where((element) => element.language == language).first.value!, onChanged: (value) { - geoPointDTO.description.where((element) => element.language == language).first.value = value; + geoPointDTO.description!.where((element) => element.language == language).first.value = value; }, ), ], diff --git a/lib/Screens/Configurations/Section/SubSection/Menu/listView_card_subSection.dart b/lib/Screens/Configurations/Section/SubSection/Menu/listView_card_subSection.dart index 92aea6f..f0c924e 100644 --- a/lib/Screens/Configurations/Section/SubSection/Menu/listView_card_subSection.dart +++ b/lib/Screens/Configurations/Section/SubSection/Menu/listView_card_subSection.dart @@ -59,7 +59,7 @@ class _ListViewCardSubSection extends State { showEditSubSection( widget.listItems[widget.index], (SectionDTO value) async { - var result = await (appContext.getContext() as ManagerAppContext).clientAPI.sectionApi.sectionUpdate(value); + var result = await (appContext.getContext() as ManagerAppContext).clientAPI!.sectionApi!.sectionUpdate(value); setState(() { widget.listItems[widget.index] = value; widget.onChanged(widget.listItems); @@ -109,7 +109,7 @@ class _ListViewCardSubSection extends State { Align( alignment: Alignment.center, child: AutoSizeText( - sectionDTO.label, + sectionDTO.label!, style: new TextStyle(fontSize: 15), maxLines: 2, textAlign: TextAlign.center, diff --git a/lib/Screens/Configurations/Section/SubSection/Menu/menu_config.dart b/lib/Screens/Configurations/Section/SubSection/Menu/menu_config.dart index 4fab589..ea3d893 100644 --- a/lib/Screens/Configurations/Section/SubSection/Menu/menu_config.dart +++ b/lib/Screens/Configurations/Section/SubSection/Menu/menu_config.dart @@ -1,6 +1,7 @@ import 'package:auto_size_text/auto_size_text.dart'; import 'package:flutter/material.dart'; import 'package:manager_app/Components/fetch_section_icon.dart'; +import 'package:manager_app/Models/managerContext.dart'; import 'package:manager_app/Screens/Configurations/Section/SubSection/Menu/listView_card_subSection.dart'; import 'package:manager_app/Screens/Configurations/new_section_popup.dart'; import 'package:manager_app/app_context.dart'; @@ -11,16 +12,16 @@ import 'dart:convert'; import 'package:provider/provider.dart'; class MenuConfig extends StatefulWidget { - final String color; - final String label; + final String? color; + final String? label; final String initialValue; final ValueChanged onChanged; const MenuConfig({ - Key key, + Key? key, this.color, this.label, - this.initialValue, - this.onChanged, + required this.initialValue, + required this.onChanged, }) : super(key: key); @override @@ -28,14 +29,14 @@ class MenuConfig extends StatefulWidget { } class _MenuConfigState extends State { - MenuDTO menuDTO; + late MenuDTO menuDTO; @override void initState() { super.initState(); - menuDTO = MenuDTO.fromJson(json.decode(widget.initialValue)); - List test = new List.from(menuDTO.sections); + menuDTO = MenuDTO.fromJson(json.decode(widget.initialValue))!; + List test = new List.from(menuDTO.sections!); menuDTO.sections = test; } @@ -55,8 +56,8 @@ class _MenuConfigState extends State { if (newIndex > oldIndex) { newIndex -= 1; } - final SectionDTO item = menuDTO.sections.removeAt(oldIndex); - menuDTO.sections.insert(newIndex, item); + final SectionDTO item = menuDTO.sections!.removeAt(oldIndex); + menuDTO.sections!.insert(newIndex, item); /*var i = 0; menuDTO.sections.forEach((image) { @@ -81,10 +82,10 @@ class _MenuConfigState extends State { scrollDirection: Axis.horizontal, padding: const EdgeInsets.symmetric(vertical: 20.0), children: List.generate( - menuDTO.sections.length, + menuDTO.sections!.length, (index) { return ListViewCardSubSection( - menuDTO.sections, + menuDTO.sections!, index, Key('$index'), appContext, @@ -107,7 +108,7 @@ class _MenuConfigState extends State { child: InkWell( onTap: () { showNewSection( - appContext.getContext().selectedConfiguration.id, + (appContext.getContext() as ManagerAppContext).selectedConfiguration!.id!, appContext, context, true, @@ -115,7 +116,7 @@ class _MenuConfigState extends State { setState(() { //print("RECEIVED new swubssection"); //print(newSubsection); - menuDTO.sections.add(newSubsection); + menuDTO.sections!.add(newSubsection); widget.onChanged(jsonEncode(menuDTO).toString()); }); }, @@ -160,7 +161,7 @@ class _MenuConfigState extends State { Align( alignment: Alignment.center, child: AutoSizeText( - sectionDTO.label, + sectionDTO.label!, style: new TextStyle(fontSize: 15), maxLines: 2, textAlign: TextAlign.center, @@ -196,7 +197,7 @@ class _MenuConfigState extends State { child: InkWell( onTap: () { setState(() { - menuDTO.sections.removeAt(index); + menuDTO.sections!.removeAt(index); widget.onChanged(jsonEncode(menuDTO).toString()); }); }, diff --git a/lib/Screens/Configurations/Section/SubSection/Menu/showEditSubSection.dart b/lib/Screens/Configurations/Section/SubSection/Menu/showEditSubSection.dart index a238b88..55fd67d 100644 --- a/lib/Screens/Configurations/Section/SubSection/Menu/showEditSubSection.dart +++ b/lib/Screens/Configurations/Section/SubSection/Menu/showEditSubSection.dart @@ -52,7 +52,7 @@ void showEditSubSection(SectionDTO subSectionDTO, Function getResult, AppContext subSectionDTO.imageSource = null; } else { subSectionDTO.imageId = resource.id; - subSectionDTO.imageSource = resource.type == ResourceType.ImageUrl ? resource.data : appContext.getContext().clientAPI.resourceApi.apiClient.basePath+"/api/Resource/"+ resource.id; + subSectionDTO.imageSource = resource.type == ResourceType.ImageUrl ? resource.data : (appContext.getContext() as ManagerAppContext).clientAPI!.resourceApi!.apiClient.basePath+"/api/Resource/"+ resource.id!; } }, isSmall: true, @@ -133,7 +133,7 @@ getSpecificData(SectionDTO sectionDTO, BuildContext context, AppContext appConte switch(sectionDTO.type) { case SectionType.Map: return MapConfig( - initialValue: sectionDTO.data, + initialValue: sectionDTO.data!, onChanged: (String data) { //print("Received info in parent"); //print(data); @@ -145,7 +145,7 @@ getSpecificData(SectionDTO sectionDTO, BuildContext context, AppContext appConte width: MediaQuery.of(context).size.width * 0.5, height: MediaQuery.of(context).size.height * 0.5, child: SliderConfig( - initialValue: sectionDTO.data, + initialValue: sectionDTO.data!, onChanged: (String data) { //print("Received info in parent"); //print(data); @@ -157,14 +157,14 @@ getSpecificData(SectionDTO sectionDTO, BuildContext context, AppContext appConte case SectionType.Web: return WebOrVideoConfig( label: sectionDTO.type == SectionType.Video ? "Url de la vidéo:": "Url du site web:", - initialValue: sectionDTO.data, + initialValue: sectionDTO.data!, onChanged: (String data) { sectionDTO.data = data; }, ); case SectionType.Menu: return MenuConfig( - initialValue: sectionDTO.data, + initialValue: sectionDTO.data!, onChanged: (String data) { //print("Received info in parent"); //print(data); @@ -173,7 +173,7 @@ getSpecificData(SectionDTO sectionDTO, BuildContext context, AppContext appConte ); case SectionType.Quizz: return QuizzConfig( - initialValue: sectionDTO.data, + initialValue: sectionDTO.data!, onChanged: (String data) { //print("Received info in parent"); //print(data); @@ -186,7 +186,7 @@ getSpecificData(SectionDTO sectionDTO, BuildContext context, AppContext appConte getTranslations(BuildContext context, AppContext appContext, SectionDTO subSectionDTO) { List translations = []; ManagerAppContext managerAppContext = appContext.getContext(); - for(var language in managerAppContext.selectedConfiguration.languages) { + for(var language in managerAppContext.selectedConfiguration!.languages!) { translations.add( SingleChildScrollView( child: Padding( @@ -216,18 +216,18 @@ getTranslations(BuildContext context, AppContext appContext, SectionDTO subSecti color: kWhite, isTitle: true, maxLines: 1, - initialValue: subSectionDTO.title.where((element) => element.language == language).first.value, + initialValue: subSectionDTO.title!.where((element) => element.language == language).first.value!, onChanged: (value) { - subSectionDTO.title.where((element) => element.language == language).first.value = value; + subSectionDTO.title!.where((element) => element.language == language).first.value = value; }, ), TextFormInputContainer( label: "Description:", color: kWhite, isTitle: false, - initialValue: subSectionDTO.description.where((element) => element.language == language).first.value, + initialValue: subSectionDTO.description!.where((element) => element.language == language).first.value!, onChanged: (value) { - subSectionDTO.description.where((element) => element.language == language).first.value = value; + subSectionDTO.description!.where((element) => element.language == language).first.value = value; }, ), ], diff --git a/lib/Screens/Configurations/Section/SubSection/Quizz/new_update_question_quizz.dart b/lib/Screens/Configurations/Section/SubSection/Quizz/new_update_question_quizz.dart index 7d84916..5620579 100644 --- a/lib/Screens/Configurations/Section/SubSection/Quizz/new_update_question_quizz.dart +++ b/lib/Screens/Configurations/Section/SubSection/Quizz/new_update_question_quizz.dart @@ -10,7 +10,7 @@ import 'package:manager_app/app_context.dart'; import 'package:manager_app/constants.dart'; import 'package:manager_api_new/api.dart'; -Future showNewOrUpdateQuestionQuizz(QuestionDTO inputQuestionDTO, AppContext appContext, BuildContext context, String text) async { +Future showNewOrUpdateQuestionQuizz(QuestionDTO? inputQuestionDTO, AppContext appContext, BuildContext context, String text) async { QuestionDTO questionDTO = new QuestionDTO(); if (inputQuestionDTO != null) { @@ -19,12 +19,12 @@ Future showNewOrUpdateQuestionQuizz(QuestionDTO inputQuestionDTO, A questionDTO.label = []; ManagerAppContext managerAppContext = appContext.getContext(); - managerAppContext.selectedConfiguration.languages.forEach((element) { + managerAppContext.selectedConfiguration!.languages!.forEach((element) { var translationMessageDTO = new TranslationDTO(); translationMessageDTO.language = element; translationMessageDTO.value = ""; - questionDTO.label.add(translationMessageDTO); + questionDTO.label!.add(translationMessageDTO); }); } @@ -59,7 +59,7 @@ Future showNewOrUpdateQuestionQuizz(QuestionDTO inputQuestionDTO, A questionDTO.source_ = null; } else { questionDTO.resourceId = resource.id; - questionDTO.source_ = resource.type == ResourceType.ImageUrl ? resource.data : appContext.getContext().clientAPI.resourceApi.apiClient.basePath+"/api/Resource/"+ resource.id; + questionDTO.source_ = resource.type == ResourceType.ImageUrl ? resource.data : (appContext.getContext() as ManagerAppContext).clientAPI!.resourceApi!.apiClient.basePath+"/api/Resource/"+ resource.id!; } }, isSmall: true @@ -92,7 +92,7 @@ Future showNewOrUpdateQuestionQuizz(QuestionDTO inputQuestionDTO, A ], ), child: QuizzResponseList( - responses: questionDTO.responses, + responses: questionDTO.responses!, onChanged: (List responsesOutput) { questionDTO.responses = responsesOutput; }, @@ -135,7 +135,7 @@ Future showNewOrUpdateQuestionQuizz(QuestionDTO inputQuestionDTO, A color: kPrimaryColor, textColor: kWhite, press: () { - if(!questionDTO.label.any((label) => label.value == null || label.value.trim() == "")) { + if(!questionDTO.label!.any((label) => label.value == null || label.value!.trim() == "")) { Navigator.pop(dialogContext, questionDTO); } else { showNotification(kPrimaryColor, kWhite, "La traduction n'est pas complète", context, null); @@ -156,7 +156,7 @@ Future showNewOrUpdateQuestionQuizz(QuestionDTO inputQuestionDTO, A getTranslations(BuildContext context, AppContext appContext, QuestionDTO questionDTO) { List translations = []; ManagerAppContext managerAppContext = appContext.getContext(); - for(var language in managerAppContext.selectedConfiguration.languages) { + for(var language in managerAppContext.selectedConfiguration!.languages!) { translations.add( Padding( padding: const EdgeInsets.all(8.0), @@ -185,9 +185,9 @@ getTranslations(BuildContext context, AppContext appContext, QuestionDTO questio label: "Question:", color: kWhite, isTitle: false, - initialValue: questionDTO.label.where((element) => element.language == language).first.value, + initialValue: questionDTO.label!.where((element) => element.language == language).first.value!, onChanged: (value) { - questionDTO.label.where((element) => element.language == language).first.value = value; + questionDTO.label!.where((element) => element.language == language).first.value = value; }, ), ], diff --git a/lib/Screens/Configurations/Section/SubSection/Quizz/new_update_response_quizz.dart b/lib/Screens/Configurations/Section/SubSection/Quizz/new_update_response_quizz.dart index 10a4519..d9643ec 100644 --- a/lib/Screens/Configurations/Section/SubSection/Quizz/new_update_response_quizz.dart +++ b/lib/Screens/Configurations/Section/SubSection/Quizz/new_update_response_quizz.dart @@ -8,7 +8,7 @@ import 'package:manager_app/app_context.dart'; import 'package:manager_app/constants.dart'; import 'package:manager_api_new/api.dart'; -Future showNewOrUpdateResponseQuizz(ResponseDTO inputResponseDTO, AppContext appContext, BuildContext context, String text) async { +Future showNewOrUpdateResponseQuizz(ResponseDTO? inputResponseDTO, AppContext appContext, BuildContext context, String text) async { ResponseDTO responseDTO = new ResponseDTO(); if (inputResponseDTO != null) { @@ -17,12 +17,12 @@ Future showNewOrUpdateResponseQuizz(ResponseDTO inputResponseDTO, A responseDTO.label = []; ManagerAppContext managerAppContext = appContext.getContext(); - managerAppContext.selectedConfiguration.languages.forEach((element) { + managerAppContext.selectedConfiguration!.languages!.forEach((element) { var translationMessageDTO = new TranslationDTO(); translationMessageDTO.language = element; translationMessageDTO.value = ""; - responseDTO.label.add(translationMessageDTO); + responseDTO.label!.add(translationMessageDTO); }); } @@ -107,7 +107,7 @@ Future showNewOrUpdateResponseQuizz(ResponseDTO inputResponseDTO, A color: kPrimaryColor, textColor: kWhite, press: () { - if(!responseDTO.label.any((label) => label.value == null || label.value.trim() == "")) { + if(!responseDTO.label!.any((label) => label.value == null || label.value!.trim() == "")) { Navigator.pop(dialogContext, responseDTO); } else { showNotification(kPrimaryColor, kWhite, "La traduction n'est pas complète", context, null); @@ -128,7 +128,7 @@ Future showNewOrUpdateResponseQuizz(ResponseDTO inputResponseDTO, A getTranslations(BuildContext context, AppContext appContext, ResponseDTO responseDTO) { List translations = []; ManagerAppContext managerAppContext = appContext.getContext(); - for(var language in managerAppContext.selectedConfiguration.languages) { + for(var language in managerAppContext.selectedConfiguration!.languages!) { translations.add( Padding( padding: const EdgeInsets.all(8.0), @@ -157,9 +157,9 @@ getTranslations(BuildContext context, AppContext appContext, ResponseDTO respons label: "Réponse:", color: kWhite, isTitle: true, - initialValue: responseDTO.label.where((element) => element.language == language).first.value, + initialValue: responseDTO.label!.where((element) => element.language == language).first.value!, onChanged: (value) { - responseDTO.label.where((element) => element.language == language).first.value = value; + responseDTO.label!.where((element) => element.language == language).first.value = value; }, ), ], diff --git a/lib/Screens/Configurations/Section/SubSection/Quizz/new_update_score_quizz.dart b/lib/Screens/Configurations/Section/SubSection/Quizz/new_update_score_quizz.dart index 019d196..4e08b62 100644 --- a/lib/Screens/Configurations/Section/SubSection/Quizz/new_update_score_quizz.dart +++ b/lib/Screens/Configurations/Section/SubSection/Quizz/new_update_score_quizz.dart @@ -8,7 +8,7 @@ import 'package:manager_app/app_context.dart'; import 'package:manager_app/constants.dart'; import 'package:manager_api_new/api.dart'; -Future showNewOrUpdateScoreQuizz(LevelDTO inputLevelDTO, AppContext appContext, BuildContext context, String text) async { +Future showNewOrUpdateScoreQuizz(LevelDTO? inputLevelDTO, AppContext appContext, BuildContext context, String text) async { LevelDTO levelDTO = new LevelDTO(); if (inputLevelDTO != null) { @@ -17,12 +17,12 @@ Future showNewOrUpdateScoreQuizz(LevelDTO inputLevelDTO, AppContext ap levelDTO.label = []; ManagerAppContext managerAppContext = appContext.getContext(); - managerAppContext.selectedConfiguration.languages.forEach((element) { + managerAppContext.selectedConfiguration!.languages!.forEach((element) { var translationMessageDTO = new TranslationDTO(); translationMessageDTO.language = element; translationMessageDTO.value = ""; - levelDTO.label.add(translationMessageDTO); + levelDTO.label!.add(translationMessageDTO); }); } @@ -53,7 +53,7 @@ Future showNewOrUpdateScoreQuizz(LevelDTO inputLevelDTO, AppContext ap levelDTO.source_ = null; } else { levelDTO.resourceId = resource.id; - levelDTO.source_ = resource.type == ResourceType.ImageUrl ? resource.data : appContext.getContext().clientAPI.resourceApi.apiClient.basePath+"/api/Resource/"+ resource.id; + levelDTO.source_ = resource.type == ResourceType.ImageUrl ? resource.data : (appContext.getContext() as ManagerAppContext).clientAPI!.resourceApi!.apiClient.basePath+"/api/Resource/"+ resource.id!; } }, isSmall: true @@ -121,7 +121,7 @@ Future showNewOrUpdateScoreQuizz(LevelDTO inputLevelDTO, AppContext ap getTranslations(BuildContext context, AppContext appContext, LevelDTO levelDTO) { List translations = []; ManagerAppContext managerAppContext = appContext.getContext(); - for(var language in managerAppContext.selectedConfiguration.languages) { + for(var language in managerAppContext.selectedConfiguration!.languages!) { translations.add( Padding( padding: const EdgeInsets.all(8.0), @@ -150,9 +150,9 @@ getTranslations(BuildContext context, AppContext appContext, LevelDTO levelDTO) label: "Message:", color: kWhite, isTitle: false, - initialValue: levelDTO.label.where((element) => element.language == language).first.value, + initialValue: levelDTO.label!.where((element) => element.language == language).first.value!, onChanged: (value) { - levelDTO.label.where((element) => element.language == language).first.value = value; + levelDTO.label!.where((element) => element.language == language).first.value = value; }, ), ], diff --git a/lib/Screens/Configurations/Section/SubSection/Quizz/quizz_answer_list.dart b/lib/Screens/Configurations/Section/SubSection/Quizz/quizz_answer_list.dart index b8f673a..12f9bf3 100644 --- a/lib/Screens/Configurations/Section/SubSection/Quizz/quizz_answer_list.dart +++ b/lib/Screens/Configurations/Section/SubSection/Quizz/quizz_answer_list.dart @@ -11,9 +11,9 @@ class QuizzResponseList extends StatefulWidget { final List responses; final ValueChanged> onChanged; const QuizzResponseList({ - Key key, - this.responses, - this.onChanged, + Key? key, + required this.responses, + required this.onChanged, }) : super(key: key); @override @@ -21,7 +21,7 @@ class QuizzResponseList extends StatefulWidget { } class _QuizzResponseListState extends State { - List responsesMiddle; + late List responsesMiddle; @override void initState() { @@ -138,7 +138,7 @@ class _QuizzResponseListState extends State { child: Padding( padding: const EdgeInsets.all(2.0), child: AutoSizeText( - response.label == null ? "" : response.label[0].value, + response.label == null ? "" : response.label![0].value!, style: new TextStyle(fontSize: 15), maxLines: 2, textAlign: TextAlign.center, @@ -161,9 +161,9 @@ class _QuizzResponseListState extends State { value: response.isGood, checkColor: Colors.white, activeColor: kPrimaryColor, - onChanged: (bool value) { + onChanged: (bool? value) { setState(() { - response.isGood = !response.isGood; + response.isGood = !response.isGood!; widget.onChanged(responsesMiddle); }); }, @@ -183,7 +183,7 @@ class _QuizzResponseListState extends State { if (result != null) { setState(() { - responsesMiddle[response.order] = result; + responsesMiddle[response.order!] = result; widget.onChanged(responsesMiddle); }); } @@ -203,7 +203,7 @@ class _QuizzResponseListState extends State { child: InkWell( onTap: () { setState(() { - responsesMiddle.removeAt(response.order); + responsesMiddle.removeAt(response.order!); widget.onChanged(responsesMiddle); }); }, diff --git a/lib/Screens/Configurations/Section/SubSection/Quizz/quizz_config.dart b/lib/Screens/Configurations/Section/SubSection/Quizz/quizz_config.dart index 074645f..dba6c42 100644 --- a/lib/Screens/Configurations/Section/SubSection/Quizz/quizz_config.dart +++ b/lib/Screens/Configurations/Section/SubSection/Quizz/quizz_config.dart @@ -12,16 +12,16 @@ import 'new_update_question_quizz.dart'; import 'new_update_score_quizz.dart'; class QuizzConfig extends StatefulWidget { - final String color; - final String label; + final String? color; + final String? label; final String initialValue; final ValueChanged onChanged; const QuizzConfig({ - Key key, + Key? key, this.color, this.label, - this.initialValue, - this.onChanged, + required this.initialValue, + required this.onChanged, }) : super(key: key); @override @@ -29,15 +29,15 @@ class QuizzConfig extends StatefulWidget { } class _QuizzConfigState extends State { - QuizzDTO quizzDTO; + late QuizzDTO quizzDTO; @override void initState() { super.initState(); - quizzDTO = QuizzDTO.fromJson(json.decode(widget.initialValue)); - List test = new List.from(quizzDTO.questions); + quizzDTO = QuizzDTO.fromJson(json.decode(widget.initialValue))!; + List test = new List.from(quizzDTO.questions!); quizzDTO.questions = test; - quizzDTO.questions.sort((a, b) => a.order.compareTo(b.order)); + quizzDTO.questions!.sort((a, b) => a.order!.compareTo(b.order!)); } @override @@ -51,11 +51,11 @@ class _QuizzConfigState extends State { if (newIndex > oldIndex) { newIndex -= 1; } - final QuestionDTO item = quizzDTO.questions.removeAt(oldIndex); - quizzDTO.questions.insert(newIndex, item); + final QuestionDTO item = quizzDTO.questions!.removeAt(oldIndex); + quizzDTO.questions!.insert(newIndex, item); var i = 0; - quizzDTO.questions.forEach((question) { + quizzDTO.questions!.forEach((question) { question.order = i; i++; }); @@ -182,7 +182,7 @@ class _QuizzConfigState extends State { Padding( padding: const EdgeInsets.only(top: 40, left: 10, right: 10, bottom: 10), child: Container( - height: quizzDTO.questions.length == 0 ? 75 : null, + height: quizzDTO.questions!.length == 0 ? 75 : null, child: ReorderableListView.builder( shrinkWrap: true, padding: const EdgeInsets.only(right: 125), @@ -192,10 +192,10 @@ class _QuizzConfigState extends State { decoration: boxDecoration(), padding: const EdgeInsets.all(2), margin: EdgeInsets.symmetric(vertical: 3, horizontal: 3), - child: getElement(index, quizzDTO.questions[index], size, appContext), + child: getElement(index, quizzDTO.questions![index], size, appContext), ); }, - itemCount: quizzDTO.questions.length, + itemCount: quizzDTO.questions!.length, onReorder: _onReorder ), ) @@ -213,12 +213,12 @@ class _QuizzConfigState extends State { right: 10, child: InkWell( onTap: () async { - QuestionDTO result = await showNewOrUpdateQuestionQuizz(null, appContext, context, "Question"); + QuestionDTO? result = await showNewOrUpdateQuestionQuizz(null, appContext, context, "Question"); if (result != null) { setState(() { - result.order = quizzDTO.questions.length; - quizzDTO.questions.add(result); + result.order = quizzDTO.questions!.length; + quizzDTO.questions!.add(result); widget.onChanged(jsonEncode(quizzDTO).toString()); }); } @@ -273,7 +273,7 @@ class _QuizzConfigState extends State { child: Padding( padding: const EdgeInsets.all(2.0), child: AutoSizeText( - question.label == null ? "" : question.label[0].value, + question.label == null ? "" : question.label![0].value!, style: new TextStyle(fontSize: 15), maxLines: 2, textAlign: TextAlign.center, @@ -301,7 +301,7 @@ class _QuizzConfigState extends State { if (result != null) { setState(() { - quizzDTO.questions[question.order] = result; + quizzDTO.questions![question.order!] = result; widget.onChanged(jsonEncode(quizzDTO).toString()); }); } @@ -321,7 +321,7 @@ class _QuizzConfigState extends State { child: InkWell( onTap: () { setState(() { - quizzDTO.questions.removeAt(question.order); + quizzDTO.questions!.removeAt(question.order!); widget.onChanged(jsonEncode(quizzDTO).toString()); }); }, @@ -369,7 +369,7 @@ imageBoxDecoration(QuestionDTO questionDTO, appContext) { image: questionDTO.source_ != null ? new DecorationImage( fit: BoxFit.cover, image: new NetworkImage( - questionDTO.source_, + questionDTO.source_!, ), ) : null, ); diff --git a/lib/Screens/Configurations/Section/SubSection/Slider/listView_card_image.dart b/lib/Screens/Configurations/Section/SubSection/Slider/listView_card_image.dart index ad0aa14..15987ff 100644 --- a/lib/Screens/Configurations/Section/SubSection/Slider/listView_card_image.dart +++ b/lib/Screens/Configurations/Section/SubSection/Slider/listView_card_image.dart @@ -47,7 +47,7 @@ class _ListViewCard extends State { child: Column( children: [ AutoSizeText( - widget.listItems[widget.index].title == null ? "" : widget.listItems[widget.index].title[0].value, + widget.listItems[widget.index].title == null ? "" : widget.listItems[widget.index].title![0].value!, style: new TextStyle(fontSize: 15), maxLines: 1, ), @@ -134,7 +134,7 @@ boxDecoration(ImageDTO imageDTO, appContext) { image: imageDTO.title != null && imageDTO.source_ != null ? new DecorationImage( fit: BoxFit.scaleDown, image: new NetworkImage( - imageDTO.source_, + imageDTO.source_!, ), ) : null, boxShadow: [ diff --git a/lib/Screens/Configurations/Section/SubSection/Slider/new_update_image_slider.dart b/lib/Screens/Configurations/Section/SubSection/Slider/new_update_image_slider.dart index 49bef14..f61cfae 100644 --- a/lib/Screens/Configurations/Section/SubSection/Slider/new_update_image_slider.dart +++ b/lib/Screens/Configurations/Section/SubSection/Slider/new_update_image_slider.dart @@ -8,7 +8,7 @@ import 'package:manager_app/app_context.dart'; import 'package:manager_app/constants.dart'; import 'package:manager_api_new/api.dart'; -Future showNewOrUpdateImageSlider(ImageDTO inputImageDTO, AppContext appContext, BuildContext context, bool showTitle, bool showDescription) async { +Future showNewOrUpdateImageSlider(ImageDTO? inputImageDTO, AppContext appContext, BuildContext context, bool showTitle, bool showDescription) async { ImageDTO imageDTO = new ImageDTO(); if (inputImageDTO != null) { @@ -18,7 +18,7 @@ Future showNewOrUpdateImageSlider(ImageDTO inputImageDTO, AppContext a imageDTO.description = []; ManagerAppContext managerAppContext = appContext.getContext(); - managerAppContext.selectedConfiguration.languages.forEach((element) { + managerAppContext.selectedConfiguration!.languages!.forEach((element) { var translationTitleDTO = new TranslationDTO(); translationTitleDTO.language = element; translationTitleDTO.value = ""; @@ -27,8 +27,8 @@ Future showNewOrUpdateImageSlider(ImageDTO inputImageDTO, AppContext a translationDescriptionDTO.language = element; translationDescriptionDTO.value = ""; - imageDTO.title.add(translationTitleDTO); - imageDTO.description.add(translationDescriptionDTO); + imageDTO.title!.add(translationTitleDTO); + imageDTO.description!.add(translationDescriptionDTO); }); } @@ -59,7 +59,7 @@ Future showNewOrUpdateImageSlider(ImageDTO inputImageDTO, AppContext a imageDTO.source_ = null; } else { imageDTO.resourceId = resource.id; - imageDTO.source_ = resource.type == ResourceType.ImageUrl ? resource.data : appContext.getContext().clientAPI.resourceApi.apiClient.basePath+"/api/Resource/"+ resource.id; + imageDTO.source_ = resource.type == ResourceType.ImageUrl ? resource.data : (appContext.getContext() as ManagerAppContext).clientAPI!.resourceApi!.apiClient.basePath+"/api/Resource/"+ resource.id!; } }, isSmall: true @@ -131,22 +131,22 @@ Future showNewOrUpdateImageSlider(ImageDTO inputImageDTO, AppContext a getTranslations(BuildContext context, AppContext appContext, ImageDTO imageDTO, bool showTitle, bool showDescription) { List translations = []; ManagerAppContext managerAppContext = appContext.getContext(); - for(var language in managerAppContext.selectedConfiguration.languages) { + for(var language in managerAppContext.selectedConfiguration!.languages!) { - if(imageDTO.title.where((element) => element.language == language).length == 0) { + if(imageDTO.title!.where((element) => element.language == language).length == 0) { imageDTO.title = []; var translationTitleDTO = new TranslationDTO(); translationTitleDTO.language = language; translationTitleDTO.value = ""; - imageDTO.title.add(translationTitleDTO); + imageDTO.title!.add(translationTitleDTO); } - if(imageDTO.description.where((element) => element.language == language).length == 0) { + if(imageDTO.description!.where((element) => element.language == language).length == 0) { imageDTO.description = []; var translationDescriptionDTO = new TranslationDTO(); translationDescriptionDTO.language = language; translationDescriptionDTO.value = ""; - imageDTO.description.add(translationDescriptionDTO); + imageDTO.description!.add(translationDescriptionDTO); } translations.add( @@ -178,9 +178,9 @@ getTranslations(BuildContext context, AppContext appContext, ImageDTO imageDTO, label: "Titre:", color: kWhite, isTitle: true, - initialValue: imageDTO.title.where((element) => element.language == language).first.value, + initialValue: imageDTO.title!.where((element) => element.language == language).first.value!, onChanged: (value) { - imageDTO.title.where((element) => element.language == language).first.value = value; + imageDTO.title!.where((element) => element.language == language).first.value = value; }, ), if(showDescription) @@ -188,9 +188,9 @@ getTranslations(BuildContext context, AppContext appContext, ImageDTO imageDTO, label: "Description:", color: kWhite, isTitle: false, - initialValue: imageDTO.description.where((element) => element.language == language).first.value, + initialValue: imageDTO.description!.where((element) => element.language == language).first.value!, onChanged: (value) { - imageDTO.description.where((element) => element.language == language).first.value = value; + imageDTO.description!.where((element) => element.language == language).first.value = value; }, ), ], diff --git a/lib/Screens/Configurations/Section/SubSection/Slider/slider_config.dart b/lib/Screens/Configurations/Section/SubSection/Slider/slider_config.dart index 72280b7..68f5baf 100644 --- a/lib/Screens/Configurations/Section/SubSection/Slider/slider_config.dart +++ b/lib/Screens/Configurations/Section/SubSection/Slider/slider_config.dart @@ -9,16 +9,16 @@ import 'dart:convert'; import 'package:provider/provider.dart'; class SliderConfig extends StatefulWidget { - final String color; - final String label; + final String? color; + final String? label; final String initialValue; final ValueChanged onChanged; const SliderConfig({ - Key key, + Key? key, this.color, this.label, - this.initialValue, - this.onChanged, + required this.initialValue, + required this.onChanged, }) : super(key: key); @override @@ -26,16 +26,16 @@ class SliderConfig extends StatefulWidget { } class _SliderConfigState extends State { - SliderDTO sliderDTO; + late SliderDTO sliderDTO; @override void initState() { super.initState(); - sliderDTO = SliderDTO.fromJson(json.decode(widget.initialValue)); - List test = new List.from(sliderDTO.images); + sliderDTO = SliderDTO.fromJson(json.decode(widget.initialValue))!; + List test = new List.from(sliderDTO.images!); sliderDTO.images = test; - sliderDTO.images.sort((a, b) => a.order.compareTo(b.order)); + sliderDTO.images!.sort((a, b) => a.order!.compareTo(b.order!)); } @override @@ -49,11 +49,11 @@ class _SliderConfigState extends State { if (newIndex > oldIndex) { newIndex -= 1; } - final ImageDTO item = sliderDTO.images.removeAt(oldIndex); - sliderDTO.images.insert(newIndex, item); + final ImageDTO item = sliderDTO.images!.removeAt(oldIndex); + sliderDTO.images!.insert(newIndex, item); var i = 0; - sliderDTO.images.forEach((image) { + sliderDTO.images!.forEach((image) { image.order = i; i++; }); @@ -72,10 +72,10 @@ class _SliderConfigState extends State { scrollDirection: Axis.horizontal, padding: const EdgeInsets.symmetric(vertical: 20.0), children: List.generate( - sliderDTO.images.length, + sliderDTO.images!.length, (index) { return ListViewCardImage( - sliderDTO.images, + sliderDTO.images!, index, Key('$index'), appContext, @@ -106,8 +106,8 @@ class _SliderConfigState extends State { if (result != null) { setState(() { - result.order = sliderDTO.images.length; - sliderDTO.images.add(result); + result.order = sliderDTO.images!.length; + sliderDTO.images!.add(result); widget.onChanged(jsonEncode(sliderDTO).toString()); }); } diff --git a/lib/Screens/Configurations/Section/SubSection/WebOrVideo/web_video_config.dart b/lib/Screens/Configurations/Section/SubSection/WebOrVideo/web_video_config.dart index 4f49895..dd52f11 100644 --- a/lib/Screens/Configurations/Section/SubSection/WebOrVideo/web_video_config.dart +++ b/lib/Screens/Configurations/Section/SubSection/WebOrVideo/web_video_config.dart @@ -5,16 +5,16 @@ import 'package:manager_api_new/api.dart'; import 'dart:convert'; class WebOrVideoConfig extends StatefulWidget { - final String color; - final String label; + final String? color; + final String? label; final String initialValue; final ValueChanged onChanged; // To return video or web url const WebOrVideoConfig({ - Key key, + Key? key, this.color, this.label, - this.initialValue, - this.onChanged, + required this.initialValue, + required this.onChanged, }) : super(key: key); @override @@ -22,10 +22,11 @@ class WebOrVideoConfig extends StatefulWidget { } class _WebOrVideoConfigState extends State { - WebDTO resourceSource; // WebDTO == VideoDTO + late WebDTO resourceSource; // WebDTO == VideoDTO + @override void initState() { - WebDTO test = WebDTO.fromJson(json.decode(widget.initialValue)); + WebDTO test = WebDTO.fromJson(json.decode(widget.initialValue))!; resourceSource = test; super.initState(); } @@ -33,7 +34,7 @@ class _WebOrVideoConfigState extends State { @override Widget build(BuildContext context) { return StringInputContainer( - label: widget.label, + label: widget.label!, initialValue: resourceSource.source_ == null ? '': resourceSource.source_, onChanged: (String url) { resourceSource.source_ = url; diff --git a/lib/Screens/Configurations/Section/section_detail_screen.dart b/lib/Screens/Configurations/Section/section_detail_screen.dart index 98c37bc..2afd832 100644 --- a/lib/Screens/Configurations/Section/section_detail_screen.dart +++ b/lib/Screens/Configurations/Section/section_detail_screen.dart @@ -28,7 +28,7 @@ import 'package:qr_flutter/qr_flutter.dart'; class SectionDetailScreen extends StatefulWidget { final String id; - SectionDetailScreen({Key key, @required this.id}) : super(key: key); + SectionDetailScreen({Key? key, required this.id}) : super(key: key); @override _SectionDetailScreenState createState() => _SectionDetailScreenState(); @@ -42,7 +42,7 @@ class _SectionDetailScreenState extends State { Size size = MediaQuery.of(context).size; return FutureBuilder( - future: getSection(widget.id, appContext.getContext().clientAPI), + future: getSection(widget.id, (appContext.getContext() as ManagerAppContext).clientAPI!), builder: (context, AsyncSnapshot snapshot) { if (snapshot.connectionState == ConnectionState.done) { return Stack( @@ -71,7 +71,7 @@ class _SectionDetailScreenState extends State { ); } - Widget bodySection(SectionDTO sectionDTO, Size size, AppContext appContext, BuildContext context) { + Widget bodySection(SectionDTO? sectionDTO, Size size, AppContext appContext, BuildContext context) { return SingleChildScrollView( child: Column( //mainAxisAlignment: MainAxisAlignment.spaceAround, @@ -100,14 +100,14 @@ class _SectionDetailScreenState extends State { size: 25, ), ), - Text(sectionDTO != null ? sectionDTO.label : "", style: TextStyle(fontSize: 30, fontWeight: FontWeight.w400)), - if((appContext.getContext() as ManagerAppContext).selectedConfiguration.isMobile) - DownloadPDF(sections: [sectionDTO]), + Text(sectionDTO != null ? sectionDTO.label! : "", style: TextStyle(fontSize: 30, fontWeight: FontWeight.w400)), + if((appContext.getContext() as ManagerAppContext).selectedConfiguration!.isMobile!) + DownloadPDF(sections: [sectionDTO!]), ], ), Padding( padding: const EdgeInsets.all(5.0), - child: Text(sectionDTO != null ? DateFormat('dd/MM/yyyy').format(sectionDTO.dateCreation) : "", style: TextStyle(fontSize: 15, fontWeight: FontWeight.w200)), + child: Text(sectionDTO != null ? DateFormat('dd/MM/yyyy').format(sectionDTO.dateCreation!) : "", style: TextStyle(fontSize: 15, fontWeight: FontWeight.w200)), ), ], ), @@ -149,7 +149,7 @@ class _SectionDetailScreenState extends State { child: Row( mainAxisAlignment: MainAxisAlignment.spaceAround, children: [ - if((appContext.getContext() as ManagerAppContext).selectedConfiguration.isMobile) + if((appContext.getContext() as ManagerAppContext).selectedConfiguration!.isMobile!) Column( mainAxisAlignment: MainAxisAlignment.spaceAround, crossAxisAlignment: CrossAxisAlignment.start, @@ -162,17 +162,17 @@ class _SectionDetailScreenState extends State { height: 125, child: QrImage( padding: EdgeInsets.only(left: 0.0, top: 5.0, bottom: 5.0), - data: sectionDTO.id, + data: sectionDTO!.id!, version: QrVersions.auto, size: 50.0, ), ), - SelectableText(sectionDTO.id, style: new TextStyle(fontSize: 15)) + SelectableText(sectionDTO.id!, style: new TextStyle(fontSize: 15)) ], ), CheckInputContainer( label: "Beacon :", - isChecked: sectionDTO.isBeacon, + isChecked: sectionDTO.isBeacon!, fontSize: 25, onChanged: (value) { setState(() { @@ -181,10 +181,10 @@ class _SectionDetailScreenState extends State { }); }, ), - if(sectionDTO.isBeacon) + if(sectionDTO.isBeacon!) NumberInputContainer( label: "Identifiant Beacon :", - initialValue: sectionDTO != null ? sectionDTO.beaconId : "", + initialValue: sectionDTO != null ? sectionDTO.beaconId! : 0, isSmall: true, onChanged: (value) { try { @@ -204,17 +204,17 @@ class _SectionDetailScreenState extends State { StringInputContainer( label: "Identifiant :", initialValue: sectionDTO != null ? sectionDTO.label : "", - onChanged: (value) { - sectionDTO.label = value; + onChanged: (String value) { + sectionDTO!.label = value; }, ), MultiStringContainer( label: "Titre affiché:", modalLabel: "Titre", color: kPrimaryColor, - initialValue: sectionDTO != null ? sectionDTO.title : [], + initialValue: sectionDTO != null ? sectionDTO.title! : [], onGetResult: (value) { - if (sectionDTO.title != value) { + if (sectionDTO!.title! != value) { sectionDTO.title = value; save(true, sectionDTO, appContext); } @@ -222,15 +222,15 @@ class _SectionDetailScreenState extends State { maxLines: 1, isTitle: true, ), - if(!(appContext.getContext() as ManagerAppContext).selectedConfiguration.isMobile) + if(!(appContext.getContext() as ManagerAppContext).selectedConfiguration!.isMobile!) MultiStringContainer( label: "Description affichée:", modalLabel: "Description", color: kPrimaryColor, - initialValue: sectionDTO != null ? sectionDTO.description : [], + initialValue: sectionDTO != null ? sectionDTO.description! : [], onGetResult: (value) { - if (sectionDTO.description != value) { - sectionDTO.description = value; + if (sectionDTO!.description != value) { + sectionDTO.description = value!; save(true, sectionDTO, appContext); } }, @@ -245,15 +245,15 @@ class _SectionDetailScreenState extends State { children: [ ImageInputContainer( label: "Image :", - initialValue: sectionDTO != null ? sectionDTO.imageId : "", + initialValue: sectionDTO != null ? sectionDTO.imageId : null, color: kPrimaryColor, onChanged: (ResourceDTO resource) { if(resource.id == null) { - sectionDTO.imageId = null; + sectionDTO!.imageId = null; sectionDTO.imageSource = null; } else { - sectionDTO.imageId = resource.id; - sectionDTO.imageSource = resource.type == ResourceType.ImageUrl ? resource.data : appContext.getContext().clientAPI.resourceApi.apiClient.basePath+"/api/Resource/"+ resource.id; + sectionDTO!.imageId = resource.id; + sectionDTO.imageSource = resource.type == ResourceType.ImageUrl ? resource.data : (appContext.getContext() as ManagerAppContext).clientAPI!.resourceApi!.apiClient.basePath+"/api/Resource/"+ resource.id!; } }, ), @@ -337,7 +337,7 @@ class _SectionDetailScreenState extends State { Future cancel(SectionDTO sectionDTO, AppContext appContext) async { ManagerAppContext managerAppContext = appContext.getContext(); - SectionDTO section = await appContext.getContext().clientAPI.sectionApi.sectionGetDetail(sectionDTO.id); + SectionDTO? section = await (appContext.getContext() as ManagerAppContext).clientAPI!.sectionApi!.sectionGetDetail(sectionDTO.id!); managerAppContext.selectedSection = section; appContext.setContext(managerAppContext); } @@ -348,7 +348,7 @@ class _SectionDetailScreenState extends State { () {}, () async { ManagerAppContext managerAppContext = appContext.getContext(); - await appContext.getContext().clientAPI.sectionApi.sectionDelete(sectionDTO.id); + await managerAppContext.clientAPI!.sectionApi!.sectionDelete(sectionDTO.id!); managerAppContext.selectedSection = null; appContext.setContext(managerAppContext); }, @@ -358,7 +358,7 @@ class _SectionDetailScreenState extends State { Future save(bool isTraduction, SectionDTO sectionDTO, AppContext appContext) async { if (sectionDTO != null) { - SectionDTO section = await appContext.getContext().clientAPI.sectionApi.sectionUpdate(sectionDTO); + SectionDTO? section = await (appContext.getContext() as ManagerAppContext).clientAPI!.sectionApi!.sectionUpdate(sectionDTO); ManagerAppContext managerAppContext = appContext.getContext(); managerAppContext.selectedSection = section; appContext.setContext(managerAppContext); @@ -375,7 +375,7 @@ class _SectionDetailScreenState extends State { switch(sectionDTO.type) { case SectionType.Map: return MapConfig( - initialValue: sectionDTO.data, + initialValue: sectionDTO.data!, onChanged: (String data) { sectionDTO.data = data; //save(false, sectionDTO, appContext); @@ -383,7 +383,7 @@ class _SectionDetailScreenState extends State { ); case SectionType.Slider: return SliderConfig( - initialValue: sectionDTO.data, + initialValue: sectionDTO.data!, onChanged: (String data) { sectionDTO.data = data; save(false, sectionDTO, appContext); @@ -393,14 +393,14 @@ class _SectionDetailScreenState extends State { case SectionType.Web: return WebOrVideoConfig( label: sectionDTO.type == SectionType.Video ? "Url de la vidéo:": "Url du site web:", - initialValue: sectionDTO.data, + initialValue: sectionDTO.data!, onChanged: (String data) { sectionDTO.data = data; }, ); case SectionType.Menu: return MenuConfig( - initialValue: sectionDTO.data, + initialValue: sectionDTO.data!, onChanged: (String data) { //print("Received info in parent"); //print(data); @@ -409,7 +409,7 @@ class _SectionDetailScreenState extends State { ); case SectionType.Quizz: return QuizzConfig( - initialValue: sectionDTO.data, + initialValue: sectionDTO.data!, onChanged: (String data) { //print("Received info in parent - quizz"); //print(data); @@ -418,7 +418,7 @@ class _SectionDetailScreenState extends State { ); case SectionType.Article: return ArticleConfig( - initialValue: sectionDTO.data, + initialValue: sectionDTO.data!, onChanged: (String data) { //print("Received info in parent - article"); //print(data); @@ -430,8 +430,8 @@ class _SectionDetailScreenState extends State { } } -Future getSection(String sectionId, Client client) async { - SectionDTO section = await client.sectionApi.sectionGetDetail(sectionId); +Future getSection(String sectionId, Client client) async { + SectionDTO? section = await client.sectionApi!.sectionGetDetail(sectionId); //print(section); return section; } diff --git a/lib/Screens/Configurations/configuration_detail_screen.dart b/lib/Screens/Configurations/configuration_detail_screen.dart index f55c450..200ffb8 100644 --- a/lib/Screens/Configurations/configuration_detail_screen.dart +++ b/lib/Screens/Configurations/configuration_detail_screen.dart @@ -28,23 +28,23 @@ import 'dart:html' as html; class ConfigurationDetailScreen extends StatefulWidget { final String id; - ConfigurationDetailScreen({Key key, @required this.id}) : super(key: key); + ConfigurationDetailScreen({Key? key, required this.id}) : super(key: key); @override _ConfigurationDetailScreenState createState() => _ConfigurationDetailScreenState(); } class _ConfigurationDetailScreenState extends State { - ConfigurationDTO configurationDTO; - SectionDTO selectedSection; - List sections; + ConfigurationDTO? configurationDTO; + SectionDTO? selectedSection; + List? sections; @override Widget build(BuildContext context) { final appContext = Provider.of(context); Size size = MediaQuery.of(context).size; return FutureBuilder( - future: getConfiguration(this.widget, appContext.getContext().clientAPI), + future: getConfiguration(this.widget, (appContext.getContext() as ManagerAppContext).clientAPI!), builder: (context, AsyncSnapshot snapshot) { if (snapshot.connectionState == ConnectionState.done) { return bodyConfiguration(snapshot.data, size, appContext, context); @@ -82,17 +82,17 @@ class _ConfigurationDetailScreenState extends State { children: [ Row( children: [ - Text(configurationDTO.label, style: TextStyle(fontSize: 30, fontWeight: FontWeight.w400)), + Text(configurationDTO.label!, style: TextStyle(fontSize: 30, fontWeight: FontWeight.w400)), InkWell( onTap: () async { try { // Export config - Client clientAPI = appContext.getContext().clientAPI; - ExportConfigurationDTO export = await clientAPI.configurationApi.configurationExport(configurationDTO.id); + Client clientAPI = (appContext.getContext() as ManagerAppContext).clientAPI!; + ExportConfigurationDTO export = await clientAPI.configurationApi!.configurationExport(configurationDTO.id!); if (kIsWeb) { html.AnchorElement anchorElement = new html.AnchorElement(); - var uri = (Uri.parse(appContext.getContext().clientAPI.resourceApi.apiClient.basePath+'/api/Configuration/${configurationDTO.id}/export')); + var uri = (Uri.parse((appContext.getContext() as ManagerAppContext).clientAPI!.resourceApi!.apiClient.basePath+'/api/Configuration/${configurationDTO.id}/export')); anchorElement.href = uri.toString(); anchorElement.download = '${configurationDTO.label}.json'; anchorElement.click(); @@ -101,7 +101,7 @@ class _ConfigurationDetailScreenState extends State { showNotification(Colors.green, kWhite, "L'export de la visite a réussi, le document se trouve là : " + test.path, context, 3000); } } catch(e) { - log(e); + log(e.toString()); showNotification(kPrimaryColor, kWhite, "L'export de la visite a échoué", context, null); } }, @@ -114,7 +114,7 @@ class _ConfigurationDetailScreenState extends State { ), Padding( padding: const EdgeInsets.all(5.0), - child: Text(DateFormat('dd/MM/yyyy').format(configurationDTO.dateCreation), style: TextStyle(fontSize: 15, fontWeight: FontWeight.w200)), + child: Text(DateFormat('dd/MM/yyyy').format(configurationDTO.dateCreation!), style: TextStyle(fontSize: 15, fontWeight: FontWeight.w200)), ), ], ), @@ -173,7 +173,7 @@ class _ConfigurationDetailScreenState extends State { ), MultiSelectDropdownContainer( label: "Langues :", - initialValue: configurationDTO.languages != null ? configurationDTO.languages: [], + initialValue: configurationDTO.languages != null ? configurationDTO.languages!: [], values: languages, isMultiple: true, fontSize: 20, @@ -236,7 +236,7 @@ class _ConfigurationDetailScreenState extends State { configurationDTO.isMobile = value; }, ), - if(configurationDTO.isMobile) + if(configurationDTO.isMobile!) RoundedButton( text: "Télécharger les QRCodes", icon: Icons.qr_code, @@ -244,7 +244,7 @@ class _ConfigurationDetailScreenState extends State { textColor: Colors.white, fontSize: 15, press: () { - PDFHelper.downloadPDF(sections); + PDFHelper.downloadPDF(sections!); }, ) ], @@ -253,7 +253,7 @@ class _ConfigurationDetailScreenState extends State { mainAxisAlignment: MainAxisAlignment.spaceAround, crossAxisAlignment: CrossAxisAlignment.start, children: [ - if(!configurationDTO.isMobile) + if(!configurationDTO.isMobile!) ColorPickerInputContainer( label: "Couleur fond d'écran :", fontSize: 20, @@ -262,7 +262,7 @@ class _ConfigurationDetailScreenState extends State { configurationDTO.secondaryColor = value; }, ), - if(configurationDTO.isMobile) + if(configurationDTO.isMobile!) Padding( padding: const EdgeInsets.only(bottom: 15), child: MultiStringContainer( @@ -270,7 +270,7 @@ class _ConfigurationDetailScreenState extends State { modalLabel: "Titre", fontSize: 20, color: kPrimaryColor, - initialValue: configurationDTO != null ? configurationDTO.title : [], + initialValue: configurationDTO != null ? configurationDTO.title! : [], onGetResult: (value) { if (configurationDTO.title != value) { configurationDTO.title = value; @@ -283,7 +283,7 @@ class _ConfigurationDetailScreenState extends State { ImageInputContainer( label: "Image :", fontSize: 20, - initialValue: configurationDTO != null ? configurationDTO.imageId : "", + initialValue: configurationDTO.imageId, color: kPrimaryColor, onChanged: (ResourceDTO resource) { if(resource.id == null) { @@ -291,7 +291,7 @@ class _ConfigurationDetailScreenState extends State { configurationDTO.imageSource = null; } else { configurationDTO.imageId = resource.id; - configurationDTO.imageSource = resource.type == ResourceType.ImageUrl ? resource.data : appContext.getContext().clientAPI.resourceApi.apiClient.basePath+"/api/Resource/"+ resource.id; + configurationDTO.imageSource = resource.type == ResourceType.ImageUrl ? resource.data : (appContext.getContext() as ManagerAppContext).clientAPI!.resourceApi!.apiClient.basePath+"/api/Resource/"+ resource.id!; } }, ), @@ -308,15 +308,15 @@ class _ConfigurationDetailScreenState extends State { border: Border.all(width: 0.5, color: kSecond) ), child: FutureBuilder( - future: getSections(configurationDTO, appContext.getContext().clientAPI), + future: getSections(configurationDTO, (appContext.getContext() as ManagerAppContext).clientAPI!), builder: (context, AsyncSnapshot snapshot) { if (snapshot.connectionState == ConnectionState.done) { - if(configurationDTO.isMobile) { + if(configurationDTO.isMobile!) { // Only see Article and Quizz type - sections = new List.from(snapshot.data).where((section) => !section.isSubSection && (section.type == SectionType.Article || section.type == SectionType.Quizz)).toList(); + sections = new List.from(snapshot.data).where((section) => !section.isSubSection! && (section.type == SectionType.Article || section.type == SectionType.Quizz)).toList(); } else { - sections = new List.from(snapshot.data).where((section) => !section.isSubSection).toList(); + sections = new List.from(snapshot.data).where((section) => !section.isSubSection!).toList(); } return bodyGrid(configurationDTO, size, appContext); } @@ -408,14 +408,14 @@ class _ConfigurationDetailScreenState extends State { child: Padding( padding: const EdgeInsets.all(8.0), child: SectionReorderList( - sectionsIn: sections, - configurationId: configurationDTO.id, + sectionsIn: sections!, + configurationId: configurationDTO.id!, onChangedOrder: (List sectionsOut) async { sections = sectionsOut; // Update section order ManagerAppContext managerAppContext = appContext.getContext(); - await managerAppContext.clientAPI.sectionApi.sectionUpdateOrder(sections); + await managerAppContext.clientAPI!.sectionApi!.sectionUpdateOrder(sections!); }, ), ), @@ -425,7 +425,7 @@ class _ConfigurationDetailScreenState extends State { Future cancel(ConfigurationDTO configurationDTO, AppContext appContext) async { ManagerAppContext managerAppContext = appContext.getContext(); - ConfigurationDTO configuration = await appContext.getContext().clientAPI.configurationApi.configurationGetDetail(configurationDTO.id); + ConfigurationDTO? configuration = await managerAppContext.clientAPI!.configurationApi!.configurationGetDetail(configurationDTO.id!); managerAppContext.selectedConfiguration = configuration; appContext.setContext(managerAppContext); } @@ -436,7 +436,7 @@ class _ConfigurationDetailScreenState extends State { () {}, () async { ManagerAppContext managerAppContext = appContext.getContext(); - await appContext.getContext().clientAPI.configurationApi.configurationDelete(configurationDTO.id); + await managerAppContext.clientAPI!.configurationApi!.configurationDelete(configurationDTO.id!); managerAppContext.selectedConfiguration = null; appContext.setContext(managerAppContext); }, @@ -445,22 +445,24 @@ class _ConfigurationDetailScreenState extends State { } Future save(ConfigurationDTO configurationDTO, AppContext appContext) async { - ConfigurationDTO configuration = await appContext.getContext().clientAPI.configurationApi.configurationUpdate(configurationDTO); ManagerAppContext managerAppContext = appContext.getContext(); + ConfigurationDTO? configuration = await managerAppContext.clientAPI!.configurationApi!.configurationUpdate(configurationDTO); managerAppContext.selectedConfiguration = configuration; appContext.setContext(managerAppContext); showNotification(Colors.green, kWhite, 'La visite a été sauvegardée avec succès', context, null); } - Future getConfiguration(ConfigurationDetailScreen widget, Client client) async { - ConfigurationDTO configuration = await client.configurationApi.configurationGetDetail(widget.id); + Future getConfiguration(ConfigurationDetailScreen widget, Client client) async { + ConfigurationDTO? configuration = await client.configurationApi!.configurationGetDetail(widget.id); return configuration; } - Future> getSections(ConfigurationDTO configurationDTO, Client client) async { - List sections = await client.sectionApi.sectionGetFromConfiguration(configurationDTO.id); - sections.sort((a, b) => a.order.compareTo(b.order)); + Future?> getSections(ConfigurationDTO configurationDTO, Client client) async { + List? sections = await client.sectionApi!.sectionGetFromConfiguration(configurationDTO.id!); + if(sections != null) { + sections.sort((a, b) => a.order!.compareTo(b.order!)); + } return sections; } } diff --git a/lib/Screens/Configurations/configurations_screen.dart b/lib/Screens/Configurations/configurations_screen.dart index bf03adc..a70ae36 100644 --- a/lib/Screens/Configurations/configurations_screen.dart +++ b/lib/Screens/Configurations/configurations_screen.dart @@ -13,14 +13,14 @@ import 'package:intl/intl.dart'; import 'Section/section_detail_screen.dart'; class ConfigurationsScreen extends StatefulWidget { - ConfigurationsScreen({Key key}) : super(key: key); + ConfigurationsScreen({Key? key}) : super(key: key); @override _ConfigurationsScreenState createState() => _ConfigurationsScreenState(); } class _ConfigurationsScreenState extends State { - ConfigurationDTO selectedConfiguration; + ConfigurationDTO? selectedConfiguration; @override Widget build(BuildContext context) { @@ -30,10 +30,10 @@ class _ConfigurationsScreenState extends State { ManagerAppContext managerAppContext = appContext.getContext(); if (managerAppContext.selectedSection != null) { - return SectionDetailScreen(id: managerAppContext.selectedSection.id); + return SectionDetailScreen(id: managerAppContext.selectedSection!.id!); } if (managerAppContext.selectedConfiguration != null) { - return ConfigurationDetailScreen(id: managerAppContext.selectedConfiguration.id); + return ConfigurationDetailScreen(id: managerAppContext.selectedConfiguration!.id!); } else { return Align( alignment: AlignmentDirectional.topCenter, @@ -108,7 +108,7 @@ class _ConfigurationsScreenState extends State { Align( alignment: Alignment.centerLeft, child: AutoSizeText( - configuration.label, + configuration.label!, style: new TextStyle(fontSize: 25), maxLines: 1, ), @@ -116,7 +116,7 @@ class _ConfigurationsScreenState extends State { Align( alignment: Alignment.bottomRight, child: AutoSizeText( - DateFormat('dd/MM/yyyy').format(configuration.dateCreation), + DateFormat('dd/MM/yyyy').format(configuration.dateCreation!), style: new TextStyle(fontSize: 18, fontFamily: ""), maxLines: 1, ), @@ -133,12 +133,15 @@ class _ConfigurationsScreenState extends State { } } -Future> getConfigurations(ManagerAppContext managerAppContext) async { - List configurations = await managerAppContext.clientAPI.configurationApi.configurationGet(instanceId: managerAppContext.instanceId); +Future?> getConfigurations(ManagerAppContext managerAppContext) async { + List? configurations = await managerAppContext.clientAPI!.configurationApi!.configurationGet(instanceId: managerAppContext.instanceId); //print("number of configurations " + configurations.length.toString()); - configurations.forEach((element) { - //print(element); - }); + if(configurations != null) { + configurations.forEach((element) { + //print(element); + }); + } + return configurations; } @@ -151,7 +154,7 @@ boxDecoration(ConfigurationDTO configurationDTO) { fit: BoxFit.cover, colorFilter: new ColorFilter.mode(Colors.black.withOpacity(0.18), BlendMode.dstATop), image: new NetworkImage( - configurationDTO.imageSource, + configurationDTO.imageSource!, ), ) : null, boxShadow: [ diff --git a/lib/Screens/Configurations/listView_card_section.dart b/lib/Screens/Configurations/listView_card_section.dart index 50a3e8a..17cb2f4 100644 --- a/lib/Screens/Configurations/listView_card_section.dart +++ b/lib/Screens/Configurations/listView_card_section.dart @@ -69,7 +69,7 @@ class _ListViewCardSectionsState extends State { ), ), child: Text( - "${sectionDTO.order+1}", + "${sectionDTO.order!+1}", style: const TextStyle(color: Colors.white) ), ), @@ -94,7 +94,7 @@ class _ListViewCardSectionsState extends State { Align( alignment: Alignment.center, child: AutoSizeText( - element.label, + element.label!, style: new TextStyle(fontSize: 15), maxLines: 2, textAlign: TextAlign.center, @@ -123,7 +123,7 @@ boxDecoration(SectionDTO sectionDTO, appContext) { fit: BoxFit.cover, colorFilter: new ColorFilter.mode(Colors.black.withOpacity(0.18), BlendMode.dstATop), image: new NetworkImage( - sectionDTO.imageSource, + sectionDTO.imageSource!, ), ) : null, boxShadow: [ diff --git a/lib/Screens/Configurations/new_configuration_popup.dart b/lib/Screens/Configurations/new_configuration_popup.dart index 1cba4e4..70fcc4a 100644 --- a/lib/Screens/Configurations/new_configuration_popup.dart +++ b/lib/Screens/Configurations/new_configuration_popup.dart @@ -13,6 +13,7 @@ import 'package:manager_api_new/api.dart'; void showNewConfiguration(AppContext appContext, ValueChanged isImport, BuildContext context, BuildContext mainContext) { ConfigurationDTO configurationDTO = new ConfigurationDTO(); Size size = MediaQuery.of(mainContext).size; + configurationDTO.label = ""; showDialog( builder: (BuildContext context) => AlertDialog( @@ -46,12 +47,12 @@ void showNewConfiguration(AppContext appContext, ValueChanged isImport, Bu ), InkWell( onTap: () async { - FilePickerResult result = await FilePicker.platform.pickFiles(); + FilePickerResult? result = await FilePicker.platform.pickFiles(); //String result = filePicker(); if (result != null) { - await FileHelper().importConfiguration(result, null, appContext.getContext().clientAPI, mainContext); + await FileHelper().importConfiguration(result, null, (appContext.getContext() as ManagerAppContext).clientAPI!, mainContext); isImport(true); Navigator.of(context).pop(); } @@ -102,7 +103,11 @@ void showNewConfiguration(AppContext appContext, ValueChanged isImport, Bu color: kPrimaryColor, textColor: kWhite, press: () { - create(configurationDTO, appContext, context); + if(configurationDTO.label != null && configurationDTO.label!.length > 2) { + create(configurationDTO, appContext, context); + } else { + showNotification(Colors.orange, kWhite, 'Veuillez spécifier un nom pour la nouvelle visite', context, null); + } }, fontSize: 20, ), @@ -134,7 +139,7 @@ String filePicker() { void create(ConfigurationDTO configurationDTO, AppContext appContext, context) async { if (configurationDTO.label != null) { configurationDTO.instanceId = (appContext.getContext() as ManagerAppContext).instanceId; - await appContext.getContext().clientAPI.configurationApi.configurationCreate(configurationDTO); + await (appContext.getContext() as ManagerAppContext).clientAPI!.configurationApi!.configurationCreate(configurationDTO); ManagerAppContext managerAppContext = appContext.getContext(); managerAppContext.selectedConfiguration = null; appContext.setContext(managerAppContext); diff --git a/lib/Screens/Configurations/new_section_popup.dart b/lib/Screens/Configurations/new_section_popup.dart index 9f4396e..d6f17c7 100644 --- a/lib/Screens/Configurations/new_section_popup.dart +++ b/lib/Screens/Configurations/new_section_popup.dart @@ -8,11 +8,12 @@ import 'package:manager_app/app_context.dart'; import 'package:manager_app/constants.dart'; import 'package:manager_api_new/api.dart'; -void showNewSection(String configurationId, AppContext appContext, BuildContext contextBuild, bool isSubSection, Function sendSubSection, bool isMobile) { +void showNewSection(String configurationId, AppContext appContext, BuildContext contextBuild, bool isSubSection, Function? sendSubSection, bool isMobile) { SectionDTO sectionDTO = new SectionDTO(); + sectionDTO.label = ""; sectionDTO.configurationId = configurationId; sectionDTO.isSubSection = isSubSection; - sectionDTO.parentId = isSubSection ? appContext.getContext().selectedSection.id : null; + sectionDTO.parentId = isSubSection ? (appContext.getContext() as ManagerAppContext).selectedSection!.id : null; Size size = MediaQuery.of(contextBuild).size; sectionDTO.type = isMobile ? SectionType.Article : SectionType.Map; @@ -84,8 +85,12 @@ void showNewSection(String configurationId, AppContext appContext, BuildContext color: kPrimaryColor, textColor: kWhite, press: () { - //onYes(); - create(sectionDTO, appContext, context, isSubSection, sendSubSection); + if(sectionDTO.label != null && sectionDTO.label!.length > 2) { + //onYes(); + create(sectionDTO, appContext, context, isSubSection, sendSubSection); + } else { + showNotification(Colors.orange, kWhite, 'Veuillez spécifier un nom pour la nouvelle section', context, null); + } }, fontSize: 20, ), @@ -98,13 +103,13 @@ void showNewSection(String configurationId, AppContext appContext, BuildContext ); } -void create(SectionDTO sectionDTO, AppContext appContext, BuildContext context, bool isSubSection, Function sendSubSection) async { +void create(SectionDTO sectionDTO, AppContext appContext, BuildContext context, bool isSubSection, Function? sendSubSection) async { if (sectionDTO.label != null) { - sectionDTO.instanceId = (appContext.getContext() as ManagerAppContext).instanceId; - SectionDTO newSection = await appContext.getContext().clientAPI.sectionApi.sectionCreate(sectionDTO); + ManagerAppContext managerAppContext = appContext.getContext(); + sectionDTO.instanceId = managerAppContext.instanceId; + SectionDTO? newSection = await managerAppContext.clientAPI!.sectionApi!.sectionCreate(sectionDTO); if (!isSubSection) { - ManagerAppContext managerAppContext = appContext.getContext(); /*if (managerAppContext.selectedConfiguration.sectionIds == null) { managerAppContext.selectedConfiguration.sectionIds = []; } @@ -112,7 +117,7 @@ void create(SectionDTO sectionDTO, AppContext appContext, BuildContext context, appContext.setContext(managerAppContext); showNotification(Colors.green, kWhite, 'La section a été créée avec succès !', context, null); } else { - sendSubSection(newSection); + sendSubSection!(newSection); } Navigator.of(context).pop(); } diff --git a/lib/Screens/Configurations/section_reorderList.dart b/lib/Screens/Configurations/section_reorderList.dart index e74901d..2b63fbe 100644 --- a/lib/Screens/Configurations/section_reorderList.dart +++ b/lib/Screens/Configurations/section_reorderList.dart @@ -14,10 +14,10 @@ class SectionReorderList extends StatefulWidget { final List sectionsIn; final ValueChanged> onChangedOrder; const SectionReorderList({ - Key key, - this.configurationId, - this.sectionsIn, - this.onChangedOrder, + Key? key, + required this.configurationId, + required this.sectionsIn, + required this.onChangedOrder, }) : super(key: key); @override @@ -25,7 +25,7 @@ class SectionReorderList extends StatefulWidget { } class _SectionReorderListState extends State { - List sections; + late List sections; String filterSearch = ''; @override @@ -60,7 +60,7 @@ class _SectionReorderListState extends State { Size size = MediaQuery.of(context).size; ManagerAppContext managerAppContext = appContext.getContext(); - ConfigurationDTO currentConfiguration = managerAppContext.selectedConfiguration; + ConfigurationDTO currentConfiguration = managerAppContext.selectedConfiguration!; return Stack( children: [ @@ -79,7 +79,7 @@ class _SectionReorderListState extends State { sections, index, Key('$index'), - currentConfiguration.isMobile, + currentConfiguration.isMobile!, appContext, (section) { setState(() { @@ -143,7 +143,7 @@ class _SectionReorderListState extends State { right: 10, child: InkWell( onTap: () { - showNewSection(widget.configurationId, appContext, context, false, null, currentConfiguration.isMobile); + showNewSection(widget.configurationId, appContext, context, false, null, currentConfiguration.isMobile!); }, child: Container( height: MediaQuery.of(context).size.width * 0.04, @@ -174,6 +174,6 @@ class _SectionReorderListState extends State { } void filterResource() { - sections = filterSearch.isEmpty ? widget.sectionsIn: widget.sectionsIn.where((SectionDTO section) => removeDiacritics(section.label.toUpperCase()).contains(removeDiacritics(filterSearch.toUpperCase()))).toList(); + sections = filterSearch.isEmpty ? widget.sectionsIn: widget.sectionsIn.where((SectionDTO section) => removeDiacritics(section.label!.toUpperCase()).contains(removeDiacritics(filterSearch.toUpperCase()))).toList(); } } diff --git a/lib/Screens/Devices/change_device_info_modal.dart b/lib/Screens/Devices/change_device_info_modal.dart index ab4ae7a..213782e 100644 --- a/lib/Screens/Devices/change_device_info_modal.dart +++ b/lib/Screens/Devices/change_device_info_modal.dart @@ -55,7 +55,7 @@ showChangeInfo (String text, DeviceDTO inputDevice, Function onGetResult, int ma padding: const EdgeInsets.all(8.0), child: DropDownConfig( configurations: snapshot.data, - selectedConfigurationId: inputDevice.configurationId, + selectedConfigurationId: inputDevice.configurationId!, onChange: (ConfigurationDTO configurationOut) { inputDevice.configuration = configurationOut.label; inputDevice.configurationId = configurationOut.id; @@ -136,7 +136,7 @@ getConfigurationsElement(DeviceDTO inputDevice, data, Function onGetResult) { color: inputDevice.configurationId == configuration.id ? kPrimaryColor : null, child: ListTile( leading: Icon(Icons.account_tree_rounded), - title: Text(configuration.label), + title: Text(configuration.label!), ), ), ); @@ -145,12 +145,16 @@ getConfigurationsElement(DeviceDTO inputDevice, data, Function onGetResult) { return widgets; } -Future> getConfigurations(AppContext appContext) async { - List configurations = await (appContext.getContext() as ManagerAppContext).clientAPI.configurationApi.configurationGet(instanceId: (appContext.getContext() as ManagerAppContext).instanceId); +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()); - configurations.forEach((element) { - //print(element); - }); + + if(configurations != null) { + configurations.forEach((element) { + //print(element); + }); + } + return configurations; } diff --git a/lib/Screens/Devices/device_element.dart b/lib/Screens/Devices/device_element.dart index 3d927a2..edfcbaf 100644 --- a/lib/Screens/Devices/device_element.dart +++ b/lib/Screens/Devices/device_element.dart @@ -10,8 +10,8 @@ import 'package:provider/provider.dart'; class DeviceElement extends StatefulWidget { final DeviceDTO deviceDTO; const DeviceElement({ - Key key, - this.deviceDTO, + Key? key, + required this.deviceDTO, }) : super(key: key); @override @@ -19,7 +19,7 @@ class DeviceElement extends StatefulWidget { } class _DeviceElementState extends State { - DeviceDTO deviceDTO; + late DeviceDTO deviceDTO; @override void initState() { @@ -40,7 +40,7 @@ class _DeviceElementState extends State { width: 15, height: 15, decoration: BoxDecoration( - color: deviceDTO.connected ? Colors.green : Colors.red, + color: deviceDTO.connected! ? Colors.green : Colors.red, shape: BoxShape.rectangle, borderRadius: BorderRadius.circular(25.0), boxShadow: [ @@ -60,7 +60,7 @@ class _DeviceElementState extends State { child: Row( children: [ AutoSizeText( - deviceDTO.name, + deviceDTO.name!, style: new TextStyle(fontSize: 25, fontWeight: FontWeight.w300), maxLines: 1, ), @@ -78,7 +78,7 @@ class _DeviceElementState extends State { mainAxisAlignment: MainAxisAlignment.center, children: [ AutoSizeText( - deviceDTO.configuration != null ? deviceDTO.configuration : "Aucune configuration", + deviceDTO.configuration != null ? deviceDTO.configuration! : "Aucune configuration", style: new TextStyle(fontSize: 20), maxLines: 1, ), @@ -118,10 +118,10 @@ class _DeviceElementState extends State { ); } - Future updateMainInfos(DeviceDTO deviceToUpdate, dynamic appContext) async { + Future updateMainInfos(DeviceDTO deviceToUpdate, dynamic appContext) async { ManagerAppContext managerAppContext = appContext.getContext(); //print(deviceToUpdate); - DeviceDTO device = await managerAppContext.clientAPI.deviceApi.deviceUpdateMainInfos(deviceToUpdate); + DeviceDTO? device = await managerAppContext.clientAPI!.deviceApi!.deviceUpdateMainInfos(deviceToUpdate); //print(device); return device; } diff --git a/lib/Screens/Devices/devices_screen.dart b/lib/Screens/Devices/devices_screen.dart index dd06b5f..e1454f8 100644 --- a/lib/Screens/Devices/devices_screen.dart +++ b/lib/Screens/Devices/devices_screen.dart @@ -8,7 +8,7 @@ import 'package:manager_api_new/api.dart'; import 'package:provider/provider.dart'; class DevicesScreen extends StatefulWidget { - DevicesScreen({Key key}) : super(key: key); + DevicesScreen({Key? key}) : super(key: key); @override _DevicesScreenState createState() => _DevicesScreenState(); @@ -203,7 +203,7 @@ class _DevicesScreenState extends State { Future updateMainInfos(DeviceDTO deviceToUpdate, dynamic appContext) async { ManagerAppContext managerAppContext = appContext.getContext(); - await managerAppContext.clientAPI.deviceApi.deviceUpdateMainInfos(deviceToUpdate); + await managerAppContext.clientAPI!.deviceApi!.deviceUpdateMainInfos(deviceToUpdate); } boxDecoration() { @@ -222,11 +222,15 @@ boxDecoration() { ); } -Future> getDevices(AppContext appContext) async { - List devices = await (appContext.getContext() as ManagerAppContext).clientAPI.deviceApi.deviceGet(instanceId: (appContext.getContext() as ManagerAppContext).instanceId); +Future?> getDevices(AppContext appContext) async { + List? devices = await (appContext.getContext() as ManagerAppContext).clientAPI!.deviceApi!.deviceGet(instanceId: (appContext.getContext() as ManagerAppContext).instanceId); //print("number of devices " + devices.length.toString()); - devices.forEach((element) { - //print(element); - }); + + if(devices != null) { + devices.forEach((element) { + //print(element); + }); + } + return devices; } diff --git a/lib/Screens/Devices/dropDown_configuration.dart b/lib/Screens/Devices/dropDown_configuration.dart index 7227a72..ba9d355 100644 --- a/lib/Screens/Devices/dropDown_configuration.dart +++ b/lib/Screens/Devices/dropDown_configuration.dart @@ -7,10 +7,10 @@ class DropDownConfig extends StatefulWidget { final String selectedConfigurationId; final ValueChanged onChange; const DropDownConfig({ - Key key, - this.configurations, - this.selectedConfigurationId, - this.onChange, + Key? key, + required this.configurations, + required this.selectedConfigurationId, + required this.onChange, }) : super(key: key); @override @@ -18,7 +18,7 @@ class DropDownConfig extends StatefulWidget { } class _DropDownConfigState extends State { - ConfigurationDTO configurationDTO; + late ConfigurationDTO configurationDTO; @override void initState() { @@ -41,16 +41,18 @@ class _DropDownConfigState extends State { height: 2, color: kPrimaryColor, ), - onChanged: (ConfigurationDTO newValue) { - setState(() { - configurationDTO = newValue; - widget.onChange(configurationDTO); - }); + onChanged: (ConfigurationDTO? newValue) { + if(newValue != null) { + setState(() { + configurationDTO = newValue; + widget.onChange(configurationDTO); + }); + } }, items: widget.configurations.map>((ConfigurationDTO value) { return DropdownMenuItem( value: value, - child: Text(value.label, style: TextStyle(fontSize: 20, fontWeight: FontWeight.w400)), + child: Text(value.label!, style: TextStyle(fontSize: 20, fontWeight: FontWeight.w400)), ); }).toList(), ); diff --git a/lib/Screens/Main/components/background.dart b/lib/Screens/Main/components/background.dart index 8141daa..034aad3 100644 --- a/lib/Screens/Main/components/background.dart +++ b/lib/Screens/Main/components/background.dart @@ -4,8 +4,8 @@ import 'package:manager_app/constants.dart'; class Background extends StatelessWidget { final Widget child; const Background({ - Key key, - @required this.child, + Key? key, + required this.child, }) : super(key: key); @override diff --git a/lib/Screens/Main/components/body.dart b/lib/Screens/Main/components/body.dart index 484f5b6..3c2da3b 100644 --- a/lib/Screens/Main/components/body.dart +++ b/lib/Screens/Main/components/body.dart @@ -18,7 +18,7 @@ import 'package:provider/provider.dart'; class Body extends StatefulWidget { - Body({Key key}) : super(key: key); + Body({Key? key}) : super(key: key); @override _BodyState createState() => _BodyState(); @@ -42,8 +42,8 @@ class _BodyState extends State { menu.sections = []; //menu.sections.add(devices); - menu.sections.add(configurations); - menu.sections.add(resources); + menu.sections!.add(configurations); + menu.sections!.add(resources); selectedElement = initElementToShow(currentPosition, menu); @@ -85,7 +85,7 @@ class _BodyState extends State { mainAxisAlignment: MainAxisAlignment.spaceEvenly, crossAxisAlignment: CrossAxisAlignment.center, children: [ - for (var section in menu.sections) + for (var section in menu.sections!) InkWell( onTap: () => { setState(() { @@ -125,7 +125,7 @@ class _BodyState extends State { child: Column( children: [ AutoSizeText( - appContext.getContext().email, + (appContext.getContext() as ManagerAppContext).email!, style: new TextStyle(color: kBodyTextColor, fontSize: 20, fontWeight: FontWeight.w300, fontFamily: "Helvetica"), maxLines: 1, ), @@ -177,7 +177,7 @@ class _BodyState extends State { } initElementToShow(int currentPosition, Menu menu) { - MenuSection elementToShow = menu.sections.where((s) => s.order == currentPosition).first; + MenuSection elementToShow = menu.sections!.where((s) => s.order == currentPosition).first; switch (elementToShow.type) { case 'devices' : diff --git a/lib/Screens/Main/main_screen.dart b/lib/Screens/Main/main_screen.dart index a9bed73..d13400d 100644 --- a/lib/Screens/Main/main_screen.dart +++ b/lib/Screens/Main/main_screen.dart @@ -2,7 +2,7 @@ import 'package:flutter/material.dart'; import 'package:manager_app/Screens/Main/components/body.dart'; class MainScreen extends StatefulWidget { - MainScreen({Key key}) : super(key: key); + MainScreen({Key? key}) : super(key: key); @override _MainScreenState createState() => _MainScreenState(); diff --git a/lib/Screens/Policy/policy_screen.dart b/lib/Screens/Policy/policy_screen.dart index 7293a4b..315259c 100644 --- a/lib/Screens/Policy/policy_screen.dart +++ b/lib/Screens/Policy/policy_screen.dart @@ -11,7 +11,7 @@ import 'package:manager_app/app_context.dart'; import 'package:provider/provider.dart'; class PolicyScreen extends StatefulWidget { - PolicyScreen({Key key}) : super(key: key); + PolicyScreen({Key? key}) : super(key: key); @override _PolicyScreenState createState() => _PolicyScreenState(); diff --git a/lib/Screens/Policy/web_view.dart b/lib/Screens/Policy/web_view.dart index 5ef08c7..f7e8c15 100644 --- a/lib/Screens/Policy/web_view.dart +++ b/lib/Screens/Policy/web_view.dart @@ -5,7 +5,7 @@ import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; class WebView extends StatefulWidget { - WebView({this.htmlText}); + WebView({required this.htmlText}); final String htmlText; @@ -27,7 +27,7 @@ class _WebViewWidget extends State { _iframeElement.innerHtml = widget.htmlText; - document.body.innerHtml = widget.htmlText; + document.body!.innerHtml = widget.htmlText; //document.title = "Privacy Policy"; //document.body. = widget.htmlText; diff --git a/lib/Screens/Resources/get_element_for_resource.dart b/lib/Screens/Resources/get_element_for_resource.dart index 655ee3c..5246deb 100644 --- a/lib/Screens/Resources/get_element_for_resource.dart +++ b/lib/Screens/Resources/get_element_for_resource.dart @@ -14,10 +14,10 @@ getElementForResource(dynamic resourceDTO, AppContext appContext) { switch(resourceDTO.type) { case ResourceType.Image: return Image.network( - appContext.getContext().clientAPI.resourceApi.apiClient.basePath+"/api/Resource/"+ resourceDTO.id, + (appContext.getContext() as ManagerAppContext).clientAPI!.resourceApi!.apiClient.basePath+"/api/Resource/"+ resourceDTO.id, fit:BoxFit.fill, loadingBuilder: (BuildContext context, Widget child, - ImageChunkEvent loadingProgress) { + ImageChunkEvent? loadingProgress) { if (loadingProgress == null) { return child; } @@ -26,7 +26,7 @@ getElementForResource(dynamic resourceDTO, AppContext appContext) { color: kPrimaryColor, value: loadingProgress.expectedTotalBytes != null ? loadingProgress.cumulativeBytesLoaded / - loadingProgress.expectedTotalBytes + loadingProgress.expectedTotalBytes! : null, ), ); @@ -38,7 +38,7 @@ getElementForResource(dynamic resourceDTO, AppContext appContext) { resourceDTO.data, fit:BoxFit.fill, loadingBuilder: (BuildContext context, Widget child, - ImageChunkEvent loadingProgress) { + ImageChunkEvent? loadingProgress) { if (loadingProgress == null) { return child; } @@ -47,7 +47,7 @@ getElementForResource(dynamic resourceDTO, AppContext appContext) { color: kPrimaryColor, value: loadingProgress.expectedTotalBytes != null ? loadingProgress.cumulativeBytesLoaded / - loadingProgress.expectedTotalBytes + loadingProgress.expectedTotalBytes! : null, ), ); @@ -92,10 +92,10 @@ getElementForResource(dynamic resourceDTO, AppContext appContext) { } } -Future getAudio(String resourceId, AppContext appContext) async { +Future getAudio(String resourceId, AppContext appContext) async { try { ManagerAppContext managerAppContext = appContext.getContext() as ManagerAppContext; - var url = managerAppContext.host + "/api/Resource/" + resourceId; // TO TEST TODO UPDATE ROUTE + var url = managerAppContext.host! + "/api/Resource/" + resourceId; // TO TEST TODO UPDATE ROUTE var test2 = await http.readBytes(Uri.parse(url)); final base64Str = base64.encode(test2); Uint8List base64String = base64Decode(base64Str); // LOAD DATA diff --git a/lib/Screens/Resources/new_resource_popup.dart b/lib/Screens/Resources/new_resource_popup.dart index a746518..3a56c2b 100644 --- a/lib/Screens/Resources/new_resource_popup.dart +++ b/lib/Screens/Resources/new_resource_popup.dart @@ -15,8 +15,8 @@ dynamic showNewResource(AppContext appContext, BuildContext context) async { ResourceDTO resourceDetailDTO = new ResourceDTO(); Size size = MediaQuery.of(context).size; var fileName; - List filesToSend; - List filesToSendWeb; + List? filesToSend; + List? filesToSendWeb; var result = await showDialog( builder: (BuildContext context) => AlertDialog( @@ -89,7 +89,7 @@ dynamic showNewResource(AppContext appContext, BuildContext context) async { color: kPrimaryColor, textColor: kWhite, press: () { - if (resourceDetailDTO.label != null && resourceDetailDTO.label.trim() != '') { + if (resourceDetailDTO.label != null && resourceDetailDTO.label!.trim() != '') { if(kIsWeb) { if(resourceDetailDTO.data != null || filesToSendWeb != null) { Navigator.pop(context, [resourceDetailDTO, filesToSend, filesToSendWeb]); @@ -97,7 +97,7 @@ dynamic showNewResource(AppContext appContext, BuildContext context) async { showNotification(Colors.orange, kWhite, 'Aucun fichier n\'a été chargé', context, null); } } else { - if (resourceDetailDTO.data != null || filesToSendWeb.length > 0 || filesToSend.length > 0) { + if (resourceDetailDTO.data != null || filesToSendWeb!.length > 0 || filesToSend!.length > 0) { Navigator.pop(context, [resourceDetailDTO, filesToSend, filesToSendWeb]); } else { showNotification(Colors.orange, kWhite, 'Aucun fichier n\'a été chargé', context, null); diff --git a/lib/Screens/Resources/resource_body_grid.dart b/lib/Screens/Resources/resource_body_grid.dart index 96c79ba..20735fd 100644 --- a/lib/Screens/Resources/resource_body_grid.dart +++ b/lib/Screens/Resources/resource_body_grid.dart @@ -3,6 +3,7 @@ import 'package:flutter/material.dart'; import 'package:manager_app/Components/fetch_resource_icon.dart'; import 'package:manager_app/Components/multi_select_container.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'; @@ -15,11 +16,11 @@ class ResourceBodyGrid extends StatefulWidget { final bool isAddButton; final List resourceTypesIn; const ResourceBodyGrid({ - Key key, - this.resources, - this.onSelect, - this.isAddButton, - this.resourceTypesIn, + Key? key, + required this.resources, + required this.onSelect, + required this.isAddButton, + required this.resourceTypesIn, }) : super(key: key); @override @@ -27,11 +28,11 @@ class ResourceBodyGrid extends StatefulWidget { } class _ResourceBodyGridState extends State { - List filterTypes; - List currentFilterTypes; + late List filterTypes; + late List currentFilterTypes; String filterSearch = ''; - List selectedTypes; - List resourcesToShow; + late List selectedTypes; + late List resourcesToShow; @override void initState() { @@ -77,7 +78,7 @@ class _ResourceBodyGridState extends State { isMultiple: true, onChanged: (result) { setState(() { - selectedTypes = result; + selectedTypes = result as List; // TO TEST filterResource(); }); }, @@ -158,7 +159,7 @@ class _ResourceBodyGridState extends State { Align( alignment: Alignment.center, child: AutoSizeText( - resource.label == null ? "" : resource.label, + resource.label == null ? "" : resource.label!, style: new TextStyle(fontSize: 20), maxLines: 1, ), @@ -183,7 +184,7 @@ class _ResourceBodyGridState extends State { } void filterResource() { - resourcesToShow = filterSearch.isEmpty ? widget.resources: widget.resources.where((ResourceDTO resource) => resource.id == null || removeDiacritics(resource.label.toUpperCase()).contains(removeDiacritics(filterSearch.toUpperCase()))).toList(); + resourcesToShow = filterSearch.isEmpty ? widget.resources: widget.resources.where((ResourceDTO resource) => resource.id == null || removeDiacritics(resource.label!.toUpperCase()).contains(removeDiacritics(filterSearch.toUpperCase()))).toList(); var getTypesInSelected = resource_types.where((ft) => selectedTypes.contains(ft.label)).map((rt) => rt.type).toList(); resourcesToShow = resourcesToShow.where((resource) => resource.id == null || getTypesInSelected.contains(resource.type)).toList(); } @@ -198,7 +199,7 @@ boxDecoration(dynamic resourceDetailDTO, appContext) { fit: BoxFit.cover, colorFilter: new ColorFilter.mode(Colors.black.withOpacity(0.3), BlendMode.dstATop), image: new NetworkImage( - resourceDetailDTO.type == ResourceType.Image ? appContext.getContext().clientAPI.resourceApi.apiClient.basePath+"/api/Resource/"+ resourceDetailDTO.id : resourceDetailDTO.data, + resourceDetailDTO.type == ResourceType.Image ? (appContext.getContext() as ManagerAppContext).clientAPI!.resourceApi!.apiClient.basePath+"/api/Resource/"+ resourceDetailDTO.id : resourceDetailDTO.data, ), ) : null, boxShadow: [ diff --git a/lib/Screens/Resources/resources_screen.dart b/lib/Screens/Resources/resources_screen.dart index 997128d..06fec61 100644 --- a/lib/Screens/Resources/resources_screen.dart +++ b/lib/Screens/Resources/resources_screen.dart @@ -15,17 +15,17 @@ import 'package:http/http.dart' as http; import 'package:flutter/foundation.dart' show kIsWeb; class ResourcesScreen extends StatefulWidget { - final Function onGetResult; //return ResourceDTO + final Function? onGetResult; //return ResourceDTO final bool isImage; final bool isAddButton; final bool isFilter; final List resourceTypes; const ResourcesScreen({ - Key key, + Key? key, this.isImage = false, this.onGetResult, this.isAddButton = true, - this.resourceTypes, + required this.resourceTypes, this.isFilter = true }) : super(key: key); @@ -34,8 +34,8 @@ class ResourcesScreen extends StatefulWidget { } class _ResourcesScreenState extends State { - String filter; - bool isLoading; + String? filter; + bool? isLoading; @override Widget build(BuildContext context) { @@ -63,7 +63,7 @@ class _ResourcesScreenState extends State { if (widget.onGetResult == null) { // Main screen if (value.id == null) { - var result = await showNewResource(appContext, context); + List? result = await showNewResource(appContext, context); if (result != null) { await create(result[0], result[1], result[2], appContext, context); @@ -75,7 +75,7 @@ class _ResourcesScreenState extends State { // Update resource ManagerAppContext managerAppContext = appContext.getContext() as ManagerAppContext; try{ - var resourceUpdated = managerAppContext.clientAPI.resourceApi.resourceUpdate(result); + var resourceUpdated = managerAppContext.clientAPI!.resourceApi!.resourceUpdate(result); setState(() { // refresh ui showNotification(kSuccess, kWhite, 'La ressource a été mise à jour avec succès', context, null); @@ -87,7 +87,7 @@ class _ResourcesScreenState extends State { } } else { // Result for select modal - widget.onGetResult(value); + widget.onGetResult!(value); } });//bodyGrid(tempOutput, size, appContext); } else { @@ -108,35 +108,35 @@ class _ResourcesScreenState extends State { } } -Future getResources(Function onGetResult, bool isImage, AppContext appContext, List types) async { +Future?> getResources(Function? onGetResult, bool isImage, AppContext appContext, List types) async { types = types != null ? types : []; - List resources = await (appContext.getContext() as ManagerAppContext).clientAPI.resourceApi.resourceGet(instanceId: (appContext.getContext() as ManagerAppContext).instanceId, types: types); - if (onGetResult != null && isImage) { + List? resources = await (appContext.getContext() as ManagerAppContext).clientAPI!.resourceApi!.resourceGet(instanceId: (appContext.getContext() as ManagerAppContext).instanceId, types: types); + if (onGetResult != null && isImage && resources != null) { resources = resources.where((element) => element.type == ResourceType.Image || element.type == ResourceType.ImageUrl || element.type == ResourceType.Audio).toList(); } return resources; } -Future create(ResourceDTO resourceDTO, List files, List filesWeb, AppContext appContext, context) async { +Future create(ResourceDTO resourceDTO, List? files, List? filesWeb, AppContext appContext, context) async { switch(resourceDTO.type) { case ResourceType.Audio: case ResourceType.Image: case ResourceType.Video: - var request = http.MultipartRequest('POST', Uri.parse(appContext.getContext().clientAPI.resourceApi.apiClient.basePath+"/api/Resource/upload")); + var request = http.MultipartRequest('POST', Uri.parse((appContext.getContext() as ManagerAppContext).clientAPI!.resourceApi!.apiClient.basePath+"/api/Resource/upload")); if (kIsWeb) { - for (PlatformFile file in filesWeb) { + for (PlatformFile file in filesWeb!) { request.files.add( await http.MultipartFile.fromBytes( 'picture', - file.bytes, + file.bytes!, filename: file.name ) ); } } else { - for (File file in files) { + for (File file in files!) { request.files.add( await http.MultipartFile( 'picture', @@ -150,9 +150,9 @@ Future create(ResourceDTO resourceDTO, List files, List create(ResourceDTO resourceDTO, List files, List r height: size.height * 0.75, child: ResourcesScreen( isAddButton: false, - onGetResult: (ResourceDTO resource) { + onGetResult: (ResourceDTO? resource) { if (resource != null) { var result = resource; Navigator.pop(context, result); @@ -65,7 +65,7 @@ showValues(List newValues) { valuesToShow.add( new StringInputContainer( color: Colors.lightBlue, - label: newValue.language, + label: newValue.language!, initialValue: newValue.value, onChanged: (String value) { newValue.value = value; diff --git a/lib/Screens/Resources/show_resource_popup.dart b/lib/Screens/Resources/show_resource_popup.dart index db3ae6e..29d3548 100644 --- a/lib/Screens/Resources/show_resource_popup.dart +++ b/lib/Screens/Resources/show_resource_popup.dart @@ -10,7 +10,7 @@ import 'package:manager_api_new/api.dart'; import 'get_element_for_resource.dart'; -Future showResource(ResourceDTO resourceDTO, AppContext appContext, BuildContext context, Size size) async { +Future showResource(ResourceDTO resourceDTO, AppContext appContext, BuildContext context, Size size) async { var result = await showDialog( builder: (BuildContext context) => AlertDialog( shape: RoundedRectangleBorder( @@ -112,7 +112,7 @@ Future showResource(ResourceDTO resourceDTO, AppContext appContext, icon: Icons.check, color: kPrimaryColor, press: () { - if (resourceDTO.label != null && resourceDTO.label.length > 2) { + if (resourceDTO.label != null && resourceDTO.label!.length > 2) { Navigator.pop(context, resourceDTO); } }, @@ -134,7 +134,7 @@ Future delete(ResourceDTO resourceDTO, AppContext appContext, context) asy "Êtes-vous sûr de vouloir supprimer cette ressource ?", () {}, () async { - await appContext.getContext().clientAPI.resourceApi.resourceDelete(resourceDTO.id); + await (appContext.getContext() as ManagerAppContext).clientAPI!.resourceApi!.resourceDelete(resourceDTO.id!); // just to refresh ManagerAppContext managerAppContext = appContext.getContext(); appContext.setContext(managerAppContext); diff --git a/lib/Screens/login_screen.dart b/lib/Screens/login_screen.dart index d9d74b3..b6c3d30 100644 --- a/lib/Screens/login_screen.dart +++ b/lib/Screens/login_screen.dart @@ -20,33 +20,35 @@ import 'package:provider/provider.dart'; import 'package:flutter/foundation.dart' show kIsWeb; class LoginScreen extends StatefulWidget { - final Session session; - LoginScreen({Key key, this.session}) : super(key: key); + final Session? session; + LoginScreen({Key? key, this.session}) : super(key: key); @override _LoginScreenState createState() => _LoginScreenState(); } class _LoginScreenState extends State { - String email; // DEV "test@email.be" - String password; // DEV = "kljqsdkljqsd" - String host; // DEV = "http://192.168.31.96" - Client clientAPI; + String email = ""; // DEV "test@email.be" + String password = ""; // DEV = "kljqsdkljqsd" + String? host; // DEV = "http://192.168.31.96" + Client? clientAPI; bool isLoading = false; bool isRememberMe = false; String pageTitle = "MyMuseum"; - String token; - String instanceId; + String? token; + String? instanceId; Storage localStorage = window.localStorage; - void authenticateTRY(dynamic appContext, bool fromClick) async { + void authenticateTRY(AppContext appContext, bool fromClick) async { //print("try auth.. "); /*this.host = "http://localhost:5000"; this.email = "test@email.be"; this.password = "kljqsdkljqsd";*/ - clientAPI = Client(this.host); + if(this.host != null) { + clientAPI = Client(this.host!); + } if (this.email != null && this.password != null || this.token != null) { @@ -64,73 +66,76 @@ class _LoginScreenState extends State { var instanceId = this.instanceId; if(accessToken == null) { LoginDTO loginDTO = new LoginDTO(email: email, password: password); - TokenDTO token = await clientAPI.authenticationApi.authenticationAuthenticateWithJson(loginDTO); - accessToken = token.accessToken; - instanceId = token.instanceId; + TokenDTO? token = await clientAPI!.authenticationApi!.authenticationAuthenticateWithJson(loginDTO); - showNotification(kSuccess, kWhite, 'Connexion réussie', context, null); + if(token != null) { + accessToken = token.accessToken!; + instanceId = token.instanceId!; - if(isRememberMe) { - if(!localStorage.containsKey("remember")) { - localStorage.addEntries({"remember": "true"}.entries); + showNotification(kSuccess, kWhite, 'Connexion réussie', context, null); + + if(isRememberMe) { + if(!localStorage.containsKey("remember")) { + localStorage.addEntries({"remember": "true"}.entries); + } + + if(!localStorage.containsKey("email") && !localStorage.containsKey("token")) { + localStorage.addEntries({"email": email!}.entries); + localStorage.addEntries({"token": token.accessToken!}.entries); + localStorage.addEntries({"instanceId": token.instanceId!}.entries); + } + } else { + localStorage.clear(); } - - if(!localStorage.containsKey("email") && !localStorage.containsKey("token")) { - localStorage.addEntries({"email": email}.entries); - localStorage.addEntries({"token": token.accessToken}.entries); - localStorage.addEntries({"instanceId": token.instanceId}.entries); - } - } else { - localStorage.clear(); - } - } - // Desktop - /*if (isRememberMe) { + // Desktop + /*if (isRememberMe) { Session updatedSession = new Session(rememberMe: isRememberMe, host: host, email: email, password: password); // update JSON FILE FileHelper().writeSession(updatedSession); }*/ - ManagerAppContext managerAppContext = appContext.getContext(); - // Set the appContext - if (managerAppContext == null) { - managerAppContext = new ManagerAppContext(); - } + ManagerAppContext? managerAppContext = appContext.getContext(); + // Set the appContext + if (managerAppContext == null) { + managerAppContext = new ManagerAppContext(); + } - // store user info locally - managerAppContext.email = email; - managerAppContext.host = host; - managerAppContext.instanceId = instanceId; - managerAppContext.accessToken = accessToken; - managerAppContext.clientAPI = clientAPI; - setAccessToken(accessToken); - //print(managerAppContext); + // store user info locally + managerAppContext.email = email; + managerAppContext.host = host; + managerAppContext.instanceId = instanceId; + managerAppContext.accessToken = accessToken; + managerAppContext.clientAPI = clientAPI; + setAccessToken(accessToken); + //print(managerAppContext); - appContext.setContext(managerAppContext); + appContext.setContext(managerAppContext); - if(fromClick) { - setState(() { - isLoading = false; - }); - } + if(fromClick) { + setState(() { + isLoading = false; + }); + } - //Navigator.pushNamed(context, '/main'); + //Navigator.pushNamed(context, '/main'); - /*Navigator.pushNamedAndRemoveUntil( + /*Navigator.pushNamedAndRemoveUntil( context, '/main', (Route route) => false // For pushAndRemoveUntil );*/ - Navigator.pushAndRemoveUntil( - context, - MaterialPageRoute( - builder: (context) { - return MainScreen(); - }, - ), - (Route route) => false // For pushAndRemoveUntil - ); + Navigator.pushAndRemoveUntil( + context, + MaterialPageRoute( + builder: (context) { + return MainScreen(); + }, + ), + (Route route) => false // For pushAndRemoveUntil + ); + } + } } catch (e) { print("error auth"); @@ -147,7 +152,7 @@ class _LoginScreenState extends State { void setAccessToken(String accessToken) { //clientAPI.resourceApi.apiClient.addDefaultHeader('authorization', 'Bearer '+accessToken); - clientAPI.apiApi.addDefaultHeader('authorization', 'Bearer '+accessToken); + clientAPI!.apiApi!.addDefaultHeader('authorization', 'Bearer '+accessToken); //clientAPI.resourceApi.addDefaultHeader('Bearer', accessToken); //clientAPI.apiApi.authentication.applyToParams([], Map.from({'Bearer': accessToken})); @@ -309,10 +314,12 @@ class _LoginScreenState extends State { checkColor: kTextLightColor, activeColor: kPrimaryColor, value: this.isRememberMe, - onChanged: (bool value) { - setState(() { - this.isRememberMe = value; - }); + onChanged: (bool? value) { + if(value != null) { + setState(() { + this.isRememberMe = value; + }); + } }, ), ), diff --git a/lib/app_context.dart b/lib/app_context.dart index 59927f7..6f5b303 100644 --- a/lib/app_context.dart +++ b/lib/app_context.dart @@ -3,7 +3,7 @@ import 'package:flutter/material.dart'; import 'Models/managerContext.dart'; class AppContext with ChangeNotifier { - ManagerAppContext _managerContext; + ManagerAppContext? _managerContext; AppContext(this._managerContext); diff --git a/lib/client.dart b/lib/client.dart index 36a4f0d..9d16ba4 100644 --- a/lib/client.dart +++ b/lib/client.dart @@ -2,33 +2,33 @@ import 'package:manager_api_new/api.dart'; //import 'package:openapi_dart_common/openapi.dart'; class Client { - ApiClient _apiClient; - ApiClient get apiApi => _apiClient; + ApiClient? _apiClient; + ApiClient? get apiApi => _apiClient; - AuthenticationApi _authenticationApi; - AuthenticationApi get authenticationApi => _authenticationApi; + AuthenticationApi? _authenticationApi; + AuthenticationApi? get authenticationApi => _authenticationApi; - UserApi _userApi; - UserApi get userApi => _userApi; + UserApi? _userApi; + UserApi? get userApi => _userApi; - ConfigurationApi _configurationApi; - ConfigurationApi get configurationApi => _configurationApi; + ConfigurationApi? _configurationApi; + ConfigurationApi? get configurationApi => _configurationApi; - SectionApi _sectionApi; - SectionApi get sectionApi => _sectionApi; + SectionApi? _sectionApi; + SectionApi? get sectionApi => _sectionApi; - ResourceApi _resourceApi; - ResourceApi get resourceApi => _resourceApi; + ResourceApi? _resourceApi; + ResourceApi? get resourceApi => _resourceApi; - DeviceApi _deviceApi; - DeviceApi get deviceApi => _deviceApi; + DeviceApi? _deviceApi; + DeviceApi? get deviceApi => _deviceApi; Client(String path) { _apiClient = ApiClient( basePath: path); //basePath: "https://192.168.31.140"); //basePath: "https://localhost:44339"); - _apiClient.addDefaultHeader("Access-Control_Allow_Origin", "*"); + _apiClient!.addDefaultHeader("Access-Control_Allow_Origin", "*"); _authenticationApi = AuthenticationApi(_apiClient); _userApi = UserApi(_apiClient); _configurationApi = ConfigurationApi(_apiClient); diff --git a/lib/main.dart b/lib/main.dart index 40106cf..4bbb17b 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -21,9 +21,12 @@ Future main() async { var session = await loadJsonSessionFile(); + ManagerAppContext managerAppContext = new ManagerAppContext(); + final MyApp myApp = MyApp( initialRoute: initialRoute, - session: session + session: session, + managerAppContext: managerAppContext //context: localContext, ); @@ -34,7 +37,7 @@ class MyApp extends StatefulWidget { final String initialRoute; final Session session; final ManagerAppContext managerAppContext; - MyApp({this.initialRoute, this.session, this.managerAppContext}); + MyApp({required this.initialRoute, required this.session, required this.managerAppContext}); // This widget is the root of your application. @override diff --git a/pubspec.lock b/pubspec.lock index abd2a22..50da93d 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -49,14 +49,14 @@ packages: url: "https://pub.dev" source: hosted version: "2.10.0" - audioplayers: - dependency: "direct main" + audio_session: + dependency: transitive description: - name: audioplayers - sha256: d50acc9659568fe0c14a5fd81ec51cdd5948b5362186572a58d76bc745302202 + name: audio_session + sha256: e4acc4e9eaa32436dfc5d7aed7f0a370f2d7bb27ee27de30d6c4f220c2a05c73 url: "https://pub.dev" source: hosted - version: "0.18.3" + version: "0.1.13" auto_size_text: dependency: "direct main" description: @@ -408,6 +408,30 @@ packages: url: "https://pub.dev" source: hosted version: "4.8.0" + just_audio: + dependency: "direct main" + description: + name: just_audio + sha256: "7e6d31508dacd01a066e3889caf6282e5f1eb60707c230203b21a83af5c55586" + url: "https://pub.dev" + source: hosted + version: "0.9.32" + just_audio_platform_interface: + dependency: transitive + description: + name: just_audio_platform_interface + sha256: eff112d5138bea3ba544b6338b1e0537a32b5e1425e4d0dc38f732771cda7c84 + url: "https://pub.dev" + source: hosted + version: "4.2.0" + just_audio_web: + dependency: transitive + description: + name: just_audio_web + sha256: "89d8db6f19f3821bb6bf908c4bfb846079afb2ab575b783d781a6bf119e3abaf" + url: "https://pub.dev" + source: hosted + version: "0.4.7" logging: dependency: transitive description: @@ -861,5 +885,5 @@ packages: source: hosted version: "3.1.1" sdks: - dart: ">=2.18.0 <3.0.1" + dart: ">=2.18.0 <3.0.0" flutter: ">=3.0.0" diff --git a/pubspec.yaml b/pubspec.yaml index 36fa3c1..f62fb28 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -18,7 +18,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev version: 1.0.0+1 environment: - sdk: ">=2.7.0 <3.0.1" + sdk: ">=2.16.2 <3.0.1" dependencies: flutter: