showModernFormInputText function
Future<TextEditingController?>
showModernFormInputText(
- dynamic context,
- {String text = "",
- TextStyle? textStyle,
- String? label = "",
- TextStyle? labelStyle,
- String hint = "",
- TextStyle? hintStyle,
- String? cancel = "",
- TextStyle? cancelStyle,
- String? done = "",
- TextStyle? doneStyle,
- Widget? labelChild,
- TextEditingController? controller,
- TextInputType? keyboardType,
- TextCapitalization? textCapitalization,
- String? validator( )?}
Implementation
Future<TextEditingController?> showModernFormInputText(
context, {
String text = "",
TextStyle? textStyle,
String? label = "",
TextStyle? labelStyle,
String hint = "",
TextStyle? hintStyle,
String? cancel = "",
TextStyle? cancelStyle,
String? done = "",
TextStyle? doneStyle,
Widget? labelChild,
TextEditingController? controller,
TextInputType? keyboardType,
TextCapitalization? textCapitalization,
String? Function(TextEditingController)? validator,
}) async {
Color colorBlack = Color(0xff2A2A2A);
Color colorMute = Color(0xff9EA4B9);
Color colorGrey = Color(0xff707070);
TextEditingController inputController =
controller ?? TextEditingController(text: text);
if (MediaQuery.of(context).size.width > ModernFormUtils.webBreakdown) {
return await menu.showMenu(
context: context,
position: menu.modernFormPopupMenuPosition(
context, menu.ModernFormPopupMenuLocation.BottomLeft),
items: [
menu.PopupMenuItem(
onTapEnabled: false,
child: ModernFormTextField(
label: label,
enabled: true,
controller: inputController,
autofocus: true,
onFieldSubmitted: () {
Navigator.pop(context, inputController);
},
),
),
menu.PopupMenuItem(
onTapEnabled: false,
child: Padding(
padding: const EdgeInsets.only(top: 7),
child: Row(
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
ElevatedButton(
onPressed: () {
Navigator.pop(context, inputController);
},
child: Text("Salvar"),
),
],
),
),
),
]);
}
return await showModalBottomSheet(
isScrollControlled: true,
context: context,
builder: (context) {
return AnimatedPadding(
padding: MediaQuery.of(context).viewInsets,
duration: const Duration(milliseconds: 100),
curve: Curves.decelerate,
child: Container(
child: Wrap(
children: [
Container(
padding: EdgeInsets.all(0),
height: ScreenUtil().setSp(60),
width: double.maxFinite,
decoration: BoxDecoration(
color: Colors.white,
border: Border(
bottom: BorderSide(
color: Color(0xffD8D8D8), width: ScreenUtil().setSp(1)),
),
),
child: Row(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
RawMaterialButton(
onPressed: () {
Navigator.pop(context, null);
},
padding: EdgeInsets.symmetric(
horizontal: ScreenUtil().setSp(10)),
child: Row(
children: <Widget>[
Icon(
Icons.close,
size: ScreenUtil().setSp(24),
color: colorBlack,
),
SizedBox(width: ScreenUtil().setSp(5)),
Text(
cancel ?? "",
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: ScreenUtil().setSp(16),
color: colorBlack,
),
)
],
),
),
Expanded(
child: SizedBox.shrink(),
),
RawMaterialButton(
onPressed: () {
Navigator.pop(context, inputController);
},
padding: EdgeInsets.symmetric(
horizontal: ScreenUtil().setSp(10)),
child: Row(
children: <Widget>[
Text(
done ?? "",
style: doneStyle ??
TextStyle(
fontWeight: FontWeight.bold,
fontSize: ScreenUtil().setSp(16),
color: colorBlack,
),
),
SizedBox(width: 5),
Icon(
Icons.check,
size: ScreenUtil().setSp(24),
color: colorBlack,
),
],
),
),
],
),
),
Padding(
padding: EdgeInsets.symmetric(vertical: 25),
child: Padding(
padding: EdgeInsets.only(bottom: ScreenUtil().setSp(5)),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
labelChild ??
Text(
label ?? "",
textAlign: TextAlign.center,
style: labelStyle ??
TextStyle(
fontSize: ScreenUtil().setSp(16),
color: colorGrey,
fontWeight: FontWeight.bold,
),
),
],
),
),
),
TextFormField(
controller: inputController,
autofocus: true,
textAlign: TextAlign.center,
textCapitalization:
textCapitalization ?? TextCapitalization.sentences,
keyboardType: keyboardType ?? TextInputType.text,
textInputAction: TextInputAction.done,
onEditingComplete: () {
Navigator.pop(context, inputController);
},
style: textStyle ??
TextStyle(
fontSize: ScreenUtil().setSp(19),
fontWeight: FontWeight.bold,
color: colorBlack,
),
decoration: InputDecoration(
border: InputBorder.none,
hintText: hint,
hintStyle: hintStyle ??
TextStyle(
fontSize: ScreenUtil().setSp(26),
fontWeight: FontWeight.w400,
color: colorMute,
),
errorText:
validator != null ? validator(inputController) : null),
)
],
)));
},
);
}