diff --git a/lib/Components/number_input_container.dart b/lib/Components/number_input_container.dart new file mode 100644 index 0000000..3b9caac --- /dev/null +++ b/lib/Components/number_input_container.dart @@ -0,0 +1,63 @@ +import 'package:auto_size_text/auto_size_text.dart'; +import 'package:flutter/material.dart'; +import 'package:manager_app/Components/rounded_input_field.dart'; +import 'package:manager_app/constants.dart'; + +class NumberInputContainer extends StatelessWidget { + final Color color; + final String label; + final int initialValue; + final ValueChanged onChanged; + final bool isUrl; + final bool isSmall; + final int maxLength; + final double fontSize; + final double fontSizeText; + const NumberInputContainer({ + Key key, + this.color = kSecond, + this.label, + this.initialValue, + this.onChanged, + this.isUrl = false, + this.isSmall = false, + this.maxLength = 50, + this.fontSize = 25, + this.fontSizeText = 20, + }) : super(key: key); + + @override + Widget build(BuildContext context) { + Size size = MediaQuery.of(context).size; + return Container( + child: Row( + children: [ + Align( + alignment: AlignmentDirectional.centerStart, + child: AutoSizeText( + label, + style: TextStyle(fontSize: fontSize, fontWeight: FontWeight.w300), + maxLines: 2, + maxFontSize: fontSize, + textAlign: TextAlign.center, + ), + ), + Padding( + padding: const EdgeInsets.all(10.0), + child: Container( + width: isUrl ? size.width *0.6 : isSmall ? size.width *0.1 : size.width *0.2, + child: RoundedInputField( + color: color, + textColor: kBlack, + fontSize: fontSizeText, + initialValue: initialValue.toString(), + onChanged: onChanged, + maxLength: maxLength, + ), + ), + ), + ], + ), + ); + } +} \ No newline at end of file diff --git a/lib/Components/rounded_input_field.dart b/lib/Components/rounded_input_field.dart index ac803d1..7b4a656 100644 --- a/lib/Components/rounded_input_field.dart +++ b/lib/Components/rounded_input_field.dart @@ -1,4 +1,5 @@ import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; import 'package:manager_app/Components/text_field_container.dart'; import 'package:manager_app/constants.dart'; @@ -12,6 +13,7 @@ class RoundedInputField extends StatelessWidget { final bool isEmail; final double fontSize; final String autofill; + final bool isInt; const RoundedInputField({ Key key, this.hintText, @@ -25,6 +27,7 @@ class RoundedInputField extends StatelessWidget { this.isEmail = false, this.fontSize = 20, this.autofill, + this.isInt = false }) : super(key: key); @override @@ -37,7 +40,10 @@ class RoundedInputField extends StatelessWidget { cursorColor: textColor, maxLength: maxLength, autofillHints: [autofill], - keyboardType: isEmail ? TextInputType.emailAddress : TextInputType.text, + keyboardType: isEmail ? TextInputType.emailAddress : isInt ? TextInputType.number : TextInputType.text, + inputFormatters: !isInt ? [] : [ + FilteringTextInputFormatter.digitsOnly + ], style: TextStyle(fontSize: fontSize, color: textColor), decoration: InputDecoration( icon: icon != null ? Icon( diff --git a/lib/Screens/Configurations/Section/section_detail_screen.dart b/lib/Screens/Configurations/Section/section_detail_screen.dart index 398d015..5bbd59b 100644 --- a/lib/Screens/Configurations/Section/section_detail_screen.dart +++ b/lib/Screens/Configurations/Section/section_detail_screen.dart @@ -6,6 +6,7 @@ import 'package:manager_app/Components/image_input_container.dart'; import 'package:manager_app/Components/loading_common.dart'; import 'package:manager_app/Components/message_notification.dart'; import 'package:manager_app/Components/multi_string_input_container.dart'; +import 'package:manager_app/Components/number_input_container.dart'; import 'package:manager_app/Components/rounded_button.dart'; import 'package:manager_app/Components/string_input_container.dart'; import 'package:manager_app/Models/managerContext.dart'; @@ -181,11 +182,17 @@ class _SectionDetailScreenState extends State { }, ), if(sectionDTO.isBeacon) - StringInputContainer( + NumberInputContainer( label: "Identifiant Beacon :", initialValue: sectionDTO != null ? sectionDTO.beaconId : "", + isSmall: true, onChanged: (value) { - sectionDTO.beaconId = value; + try { + sectionDTO.beaconId = int.parse(value); + } catch (e) { + print('BeaconId not a number'); + showNotification(Colors.orange, kWhite, 'Cela doit ĂȘtre un chiffre', context, null); + } }, ), ],