Update beaconId as an integer

This commit is contained in:
Fransolet Thomas 2023-02-17 17:46:54 +01:00
parent 397e4fb6f2
commit 89502ce5d1
3 changed files with 79 additions and 3 deletions

View File

@ -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<String> 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,
),
),
),
],
),
);
}
}

View File

@ -1,4 +1,5 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:manager_app/Components/text_field_container.dart'; import 'package:manager_app/Components/text_field_container.dart';
import 'package:manager_app/constants.dart'; import 'package:manager_app/constants.dart';
@ -12,6 +13,7 @@ class RoundedInputField extends StatelessWidget {
final bool isEmail; final bool isEmail;
final double fontSize; final double fontSize;
final String autofill; final String autofill;
final bool isInt;
const RoundedInputField({ const RoundedInputField({
Key key, Key key,
this.hintText, this.hintText,
@ -25,6 +27,7 @@ class RoundedInputField extends StatelessWidget {
this.isEmail = false, this.isEmail = false,
this.fontSize = 20, this.fontSize = 20,
this.autofill, this.autofill,
this.isInt = false
}) : super(key: key); }) : super(key: key);
@override @override
@ -37,7 +40,10 @@ class RoundedInputField extends StatelessWidget {
cursorColor: textColor, cursorColor: textColor,
maxLength: maxLength, maxLength: maxLength,
autofillHints: [autofill], autofillHints: [autofill],
keyboardType: isEmail ? TextInputType.emailAddress : TextInputType.text, keyboardType: isEmail ? TextInputType.emailAddress : isInt ? TextInputType.number : TextInputType.text,
inputFormatters: !isInt ? [] : <TextInputFormatter>[
FilteringTextInputFormatter.digitsOnly
],
style: TextStyle(fontSize: fontSize, color: textColor), style: TextStyle(fontSize: fontSize, color: textColor),
decoration: InputDecoration( decoration: InputDecoration(
icon: icon != null ? Icon( icon: icon != null ? Icon(

View File

@ -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/loading_common.dart';
import 'package:manager_app/Components/message_notification.dart'; import 'package:manager_app/Components/message_notification.dart';
import 'package:manager_app/Components/multi_string_input_container.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/rounded_button.dart';
import 'package:manager_app/Components/string_input_container.dart'; import 'package:manager_app/Components/string_input_container.dart';
import 'package:manager_app/Models/managerContext.dart'; import 'package:manager_app/Models/managerContext.dart';
@ -181,11 +182,17 @@ class _SectionDetailScreenState extends State<SectionDetailScreen> {
}, },
), ),
if(sectionDTO.isBeacon) if(sectionDTO.isBeacon)
StringInputContainer( NumberInputContainer(
label: "Identifiant Beacon :", label: "Identifiant Beacon :",
initialValue: sectionDTO != null ? sectionDTO.beaconId : "", initialValue: sectionDTO != null ? sectionDTO.beaconId : "",
isSmall: true,
onChanged: (value) { 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);
}
}, },
), ),
], ],