mobileapplicationPassvault/lib/custom_widgets/new_reuse_textfield.dart

86 lines
2.7 KiB
Dart

// ignore_for_file: use_key_in_widget_constructors, non_constant_identifier_names
import 'package:flutter/material.dart';
import 'package:flutter_passvault/constant/constantfile.dart';
class NewReusableTextField extends StatefulWidget {
final TextEditingController? controller;
final String? hintText;
final Icon? icon;
final bool hasBorder;
final String? labelText;
final bool showLabel;
final bool secure;
final bool emailkeyboard;
final Key? key1;
// ignore: prefer_const_constructors_in_immutables
NewReusableTextField({
this.controller,
this.hintText,
this.icon,
this.hasBorder = true,
this.labelText,
this.showLabel = true,
this.secure = false,
this.emailkeyboard = false,
this.key1,
});
@override
State<NewReusableTextField> createState() => _NewReusableTextFieldState();
}
class _NewReusableTextFieldState extends State<NewReusableTextField> {
bool _showPwd = false;
final color1 = ApiConstants.backgroundcolor;
@override
Widget build(BuildContext context) {
return TextField(
key: widget.key1,
keyboardType: widget.emailkeyboard
? TextInputType.emailAddress
: TextInputType.text,
obscureText: widget.secure ? !_showPwd : false,
controller: widget.controller,
decoration: InputDecoration(
labelText: widget.showLabel ? widget.labelText : null,
labelStyle: widget.showLabel
? const TextStyle(
fontFamily: 'source-sans-pro.regular.ttf',
color: Colors.black,
fontWeight: FontWeight.normal, // Adjust the font weight
letterSpacing:
0.9, // Adjust the letter spacing // Set the rendering mode
)
: null,
contentPadding: const EdgeInsets.symmetric(
horizontal: 10.0, vertical: 4.0), // Reduce the vertical padding
border:
widget.hasBorder ? const OutlineInputBorder() : InputBorder.none,
hintText: widget.hintText,
prefixIcon: widget.icon,
suffixIcon: widget.secure
? IconButton(
icon: Icon(
// Based on passwordVisible state choose the icon
_showPwd ? Icons.visibility : Icons.visibility_off,
color: _showPwd ? color1 : Colors.grey,
),
onPressed: () {
// Update the state i.e. toogle the state of passwordVisible variable
setState(() {
_showPwd = !_showPwd;
});
},
)
: null),
);
}
}