You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
141 lines
4.9 KiB
Dart
141 lines
4.9 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:test_sa/extensions/context_extension.dart';
|
|
import 'package:test_sa/extensions/int_extensions.dart';
|
|
import 'package:test_sa/extensions/text_extensions.dart';
|
|
import 'package:test_sa/extensions/widget_extensions.dart';
|
|
import 'package:test_sa/new_views/app_style/app_color.dart';
|
|
|
|
class InputWidget extends StatefulWidget {
|
|
final String labelText;
|
|
final String hintText;
|
|
final TextEditingController controller;
|
|
final VoidCallback suffixTap;
|
|
final bool isEnable;
|
|
final bool hasSelection;
|
|
final int lines;
|
|
final bool isInputTypeNum;
|
|
final bool isTextIsPassword;
|
|
final bool isBackgroundEnable;
|
|
final bool isEnableBorder;
|
|
final double verticalPadding;
|
|
final double horizontalPadding;
|
|
final Function(String) onChange;
|
|
final Function(String) validator;
|
|
|
|
InputWidget(
|
|
this.labelText,
|
|
this.hintText,
|
|
this.controller, {
|
|
Key key,
|
|
this.isTextIsPassword = false,
|
|
this.suffixTap,
|
|
this.validator,
|
|
this.isEnable = true,
|
|
this.hasSelection = false,
|
|
this.isEnableBorder = false,
|
|
this.lines = 1,
|
|
this.onChange,
|
|
this.isInputTypeNum = false,
|
|
this.isBackgroundEnable = false,
|
|
this.verticalPadding = 10,
|
|
this.horizontalPadding = 16,
|
|
}) : super(key: key);
|
|
|
|
@override
|
|
_InputWidgetState createState() {
|
|
return _InputWidgetState();
|
|
}
|
|
}
|
|
|
|
class _InputWidgetState extends State<InputWidget> {
|
|
bool isObscureText;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
isObscureText = widget.isTextIsPassword;
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
super.dispose();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Container(
|
|
height: 56,
|
|
padding: EdgeInsets.only(left: widget.horizontalPadding, right: widget.horizontalPadding, bottom: widget.verticalPadding, top: widget.verticalPadding),
|
|
alignment: Alignment.center,
|
|
decoration: BoxDecoration(
|
|
borderRadius: BorderRadius.circular(10),
|
|
color: widget.isBackgroundEnable ? Color(0xffF7F7F7) : Colors.white,
|
|
border: Border.all(
|
|
color: widget.isEnableBorder ? Color(0xffefefef) : Colors.transparent,
|
|
width: 1,
|
|
),
|
|
boxShadow: const [
|
|
BoxShadow(
|
|
color: Color.fromRGBO(0, 0, 0, 0.05),
|
|
blurRadius: 10.0,
|
|
spreadRadius: 0.0,
|
|
offset: Offset(0, 0),
|
|
),
|
|
],
|
|
),
|
|
child: InkWell(
|
|
onTap: widget.hasSelection ? () {} : null,
|
|
child: Row(
|
|
children: [
|
|
Expanded(
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(
|
|
widget.labelText,
|
|
style: AppTextStyles.tinyFont.copyWith(color: context.isDark ? AppColor.neutral10 : AppColor.neutral20),
|
|
),
|
|
TextFormField(
|
|
enabled: widget.isEnable,
|
|
scrollPadding: EdgeInsets.zero,
|
|
keyboardType: widget.isInputTypeNum ? TextInputType.number : TextInputType.text,
|
|
controller: widget.controller,
|
|
maxLines: widget.lines,
|
|
validator: widget.validator,
|
|
obscuringCharacter: "*",
|
|
obscureText: isObscureText,
|
|
onChanged: widget.onChange,
|
|
style: AppTextStyles.bodyText.copyWith(color: context.isDark ? AppColor.primary50 : AppColor.neutral50),
|
|
decoration: InputDecoration(
|
|
isDense: true,
|
|
hintText: widget.hintText,
|
|
// hintStyle: AppTextStyles.bodyText.copyWith(color: context.isDark ? AppColor.primary50 : AppColor.neutral50),
|
|
hintStyle: AppTextStyles.bodyText.copyWith(color: context.isDark ? AppColor.neutral10 : AppColor.neutral20.withOpacity(.4)),
|
|
//suffixIconConstraints: const BoxConstraints(minWidth: 50),
|
|
// suffixIcon: widget.suffixTap == null ? null : IconButton(icon: const Icon(Icons.mic, color: MyColors.darkTextColor), onPressed: widget.suffixTap),
|
|
contentPadding: EdgeInsets.zero,
|
|
border: InputBorder.none,
|
|
focusedBorder: InputBorder.none,
|
|
enabledBorder: InputBorder.none,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
if (widget.isTextIsPassword) ...[
|
|
16.width,
|
|
Icon(isObscureText ? Icons.visibility_rounded : Icons.visibility_off_rounded).onPress(() {
|
|
setState(() {
|
|
isObscureText = !isObscureText;
|
|
});
|
|
})
|
|
],
|
|
if (widget.hasSelection) Icon(Icons.keyboard_arrow_down_outlined),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|