As the image is shown below, the first image displays my text field before I click on it. the second image displays how it displays when after start typing and clicking on it. I want to remove that label text display while typing. how can I do that?
TextFormField(
controller: usernameEditingController,
decoration: InputDecoration(
fillColor: textWhite,
filled: true,
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(20.0),
borderSide: const BorderSide(
color: textdarkBlue,
),
),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(20.0),
borderSide: const BorderSide(
color: textdarkBlue,
),
),
errorBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(20.0),
borderSide: const BorderSide(color: Colors.red),
),
focusedErrorBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(20.0),
borderSide: const BorderSide(color: Colors.red),
),
isDense: true,
contentPadding: EdgeInsets.fromLTRB(10, 30, 10, 0),
labelText: "User Name",
labelStyle: TextStyle(
fontSize: 15,
color: textdarkBlue,
),
hintText: "ex: James",
hintStyle: TextStyle(
color: textdarkBlue,
fontFamily: "Paralucent",
fontSize: 14)),
style: TextStyle(
color: textdarkBlue,
),
validator: (text) {
if (text!.isEmpty) {
return "Username can't be empty";
} else {
return null;
}
},
onChanged: (String? text) {
userName = text!;
//print(userName);
},
),
It is displaying as OutlineInputBorder's behavior.
There are few different ways, One is using FocusNode, goal is to provide labelText:null on focus change.
String userName = "";
late FocusNode focusNode = FocusNode()
..addListener(() {
setState(() {});
});
.....
TextFormField(
// controller: usernameEditingController,
focusNode: focusNode,
decoration: InputDecoration(
labelText: focusNode.hasFocus ? null : "User Name",
That is the behaviour of labelText property if you don't want it , simply remove it and use hintText instead
TextFormField(
controller: usernameEditingController,
decoration: InputDecoration(
fillColor: textWhite,
filled: true,
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(20.0),
borderSide: const BorderSide(
color: textdarkBlue,
),
),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(20.0),
borderSide: const BorderSide(
color: textdarkBlue,
),
),
errorBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(20.0),
borderSide: const BorderSide(color: Colors.red),
),
focusedErrorBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(20.0),
borderSide: const BorderSide(color: Colors.red),
),
isDense: true,
contentPadding: EdgeInsets.fromLTRB(10, 30, 10, 0),
hintText: "ex: James",
hintStyle: TextStyle(
color: textdarkBlue,
fontFamily: "Paralucent",
fontSize: 14)),
style: TextStyle(
color: textdarkBlue,
),
validator: (text) {
if (text!.isEmpty) {
return "Username can't be empty";
} else {
return null;
}
},
onChanged: (String? text) {
userName = text!;
//print(userName);
},
),
Related
how do i reduce the top and bottom padding of flutter textfield within the border? there is too much space for top and bottom.
TextField(
textInputAction: TextInputAction.search,
controller: controller,
focusNode: focusNode,
autofocus: true,
cursorColor: Theme.of(context).primaryColor,
onChanged: (text) {
text.length >= 4
? provider.fetchSearchName(text)
: buildNoData();
},
decoration: InputDecoration(
suffixIcon: IconButton(
onPressed: clearText,
color: Theme.of(context).primaryColor,
icon: Icon(Icons.cancel_outlined)
),
labelText: 'Search',
labelStyle: TextStyle(color: Colors.white),
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(width: 2, color: Theme.of(context).primaryColor),
// borderRadius: BorderRadius.circular(10),
),
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(width: 2, color: Theme.of(context).primaryColor),
// borderRadius: BorderRadius.circular(10),
)
),
),
You may use contentPadding: within InputDecoration widget.
Here's the Code
TextField(
textInputAction: TextInputAction.search,
controller: controller,
focusNode: focusNode,
autofocus: true,
cursorColor: Theme.of(context).primaryColor,
onChanged: (text) {
text.length >= 4
? provider.fetchSearchName(text)
: buildNoData();
},
decoration: InputDecoration(
contentPadding: EdgeInsets.symmetric(vertical: 5, horizontal: 12),
suffixIcon: IconButton(
onPressed: clearText,
color: Theme.of(context).primaryColor,
icon: Icon(Icons.cancel_outlined)
),
labelText: 'Search',
labelStyle: TextStyle(color: Colors.white),
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(width: 2, color: Theme.of(context).primaryColor),
// borderRadius: BorderRadius.circular(10),
),
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(width: 2, color: Theme.of(context).primaryColor),
// borderRadius: BorderRadius.circular(10),
)
),
),
how to make text field in flutter like this. I want to develop a text field in flutter
You can make this TextField like this:
TextField(
decoration: InputDecoration(
filled: true,
fillColor: Colors.white,
focusColor: Colors.white,
focusedBorder: OutlineInputBorder(
borderSide: const BorderSide(color: Colors.white, width: 2.0),
borderRadius: BorderRadius.circular(30),
),
border: OutlineInputBorder(
borderSide: const BorderSide(color: Colors.white, width: 2.0),
borderRadius: BorderRadius.circular(30),
),
enabledBorder: OutlineInputBorder(
borderSide: const BorderSide(color: Colors.white, width: 2.0),
borderRadius: BorderRadius.circular(30),
),
hintText: 'Email address',
hintStyle: const TextStyle(color: Colors.grey),
),
),
Hope it works for you:
TextField(
decoration: InputDecoration(
filled: true,
fillColor: Colors.white.withOpacity(0.6),
hintText: "Email address",
hintStyle: TextStyle(
color: Colors.grey[400],
fontWeight: FontWeight.bold
),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(20),
borderSide: BorderSide.none,
),
),
);
Column(
children:[
const TextField(
decoration: InputDecoration(
fillColor: Colors.white,
filled: true,
isDense: true,
contentPadding: EdgeInsets.symmetric(vertical: 12.0, horizontal: 16.0),
// counter: Container(),
counterText: '',
hintStyle: TextStyle(
color: Colors.grey,
fontWeight: FontWeight.w700,
fontSize: 18),
hintText: 'Email Address',
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(color: Colors.white),
borderRadius: BorderRadius.all(
Radius.circular(12.0),
),
),
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(color: Colors.white),
borderRadius: BorderRadius.all(
Radius.circular(12.0),
),
),
),
keyboardType: TextInputType.emailAddress,
textInputAction: TextInputAction.next,
),
SizedBox(height: 20),
const TextField(
decoration: InputDecoration(
fillColor: Colors.white,
filled: true,
isDense: true,
contentPadding: EdgeInsets.symmetric(vertical: 12.0, horizontal: 16.0),
// counter: Container(),
counterText: '',
hintStyle: TextStyle(
color: Colors.grey,
fontWeight: FontWeight.w700,
fontSize: 18),
hintText: 'Password',
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(color: Colors.white),
borderRadius: BorderRadius.all(
Radius.circular(8.0),
),
),
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(color: Colors.white),
borderRadius: BorderRadius.all(
Radius.circular(8.0),
),
),
),
keyboardType: TextInputType.visiblePassword,
obscureText: true,
textInputAction: TextInputAction.done,
),
]
)
Please use this text field code. Import and use it everywhere
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:personal_diary/app/data/SelectedTheme.dart';
import 'package:personal_diary/app/data/ThemeData.dart';
class EditText extends StatelessWidget {
// final Color textColor;
final String hint;
final int maxLine;
final int? maxLength;
final bool isObscure;
final Color? textFieldColor, hintFieldColor;
final TextInputType? keyboardType;
final ThemeDetails themeDetails = SelectedTheme.instance.getTheme();
final double marginTop, marginBottom, marginLeft, marginRight;
final TextEditingController? controller;
final bool isReadOnly;
final double? fontSize;
final double? height;
final String? Function(String? val)? validator;
EditText(
{required this.hint,
this.maxLine = 1,
this.maxLength,
this.fontSize,
this.isReadOnly = false,
this.isObscure = false,
this.keyboardType,
this.marginTop = 0.0,
this.marginBottom = 0.0,
this.height,
this.marginLeft = 0.0,
this.textFieldColor,
this.hintFieldColor,
this.validator,
this.marginRight = 0.0,
this.controller});
#override
Widget build(BuildContext context) {
return Container(
decoration: BoxDecoration(
color: Colors.white.withOpacity(0.85),
borderRadius: BorderRadius.all(Radius.circular(12.sp))),
padding: EdgeInsets.only(left: 10.w),
margin: EdgeInsets.only(
top: marginTop,
bottom: marginBottom,
right: marginRight,
left: marginLeft),
child: TextFormField(
style: TextStyle(
color: Colors.black,
fontSize: fontSize ?? 14.sp,
height: height,
),
controller: controller,
maxLines: maxLine,
readOnly: isReadOnly,
maxLength: maxLength,
validator: validator,
keyboardType: keyboardType,
obscureText: isObscure,
decoration: InputDecoration(
hintText: hint, border: InputBorder.none,
counterText: '',
hintStyle: TextStyle(
color: Colors.grey, fontSize: 14.sp
),
),
),
);
}
}
This is how you can use this code :
Column(
children : [
EditText(
hint: "Enter email",
isObscure:true,
keyboardType: TextInputType.number,
hintFieldColor: Colors.grey,
marginTop: 20.h,
maxLength: 1,
controller: confirmPasswordController,
),
]
)
i would like to animtate "Hint text" in "InputDecoration". I found "Animated_text_kit" which alove to animate text, but i don't know how to implement this in inputDecoration - Hint text
Here is my InputDecoration Code:
decoration: InputDecoration(
enabledBorder: inputBorderDecoration,
alignLabelWithHint: true,
focusedBorder: focusedBorder,
suffixIcon: isWriting
? null
: IconButton(
icon: Image.asset('assets/images/microphone.png'),
color: Colors.black,
onPressed: () {
print('microphone taped');
}),
hintText: "Message...",
hintStyle: TextStyle(color: AppColor.darkGrey, fontSize: 18),
border: OutlineInputBorder(
borderSide: BorderSide(
color: Colors.red.withOpacity(0.2),
),
borderRadius: BorderRadius.circular(15),
),
contentPadding:
EdgeInsets.symmetric(horizontal: 10, vertical: 0),
filled: true,
fillColor: Colors.white.withOpacity(0.3),
),
I want to change TextFiled underline color when it is disabled
child: TextField(
***enabled: false,***
controller: resultController,
style: TextStyle(
color: Colors.orange, fontSize: 18, fontWeight: FontWeight.bold),
keyboardType: TextInputType.number,
decoration: InputDecoration(
enabledBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Colors.white)),
labelText: resultLableText,
labelStyle: TextStyle(color: Colors.white)),
),
Look at the below code, it will easily solve your problem:
TextField(
decoration: InputDecoration(
hintText: "Your hint here",
//defalult border
border: OutlineInputBorder(
borderSide: BorderSide(width: 1, color: Colors.green)),
//disabled border
disabledBorder: OutlineInputBorder(
borderSide: BorderSide(width: 1, color: Colors.grey)),
//enabled border
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(width: 1, color: Colors.blue)),
//error boreder
errorBorder: OutlineInputBorder(
borderSide: BorderSide(width: 1, color: Colors.red)),
//focused border
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(width: 1, color: Colors.purple)),
//error while focused border
focusedErrorBorder: OutlineInputBorder(
borderSide: BorderSide(width: 1, color: Colors.amber)),
),
),
I am unsure that there is a method you can use to check if a TextField is disabled, but a way you can do it is you can create a bool that keeps track if the TextField is disabled.
Create the bool
bool isDisabled = false;
Make a function that changes the value
Function<void> changeDisabled() {
setState() {
isDisabled ? isDisabled = false : isDisabled = true
}
}
Check the status of isDisabled in your code.
child: TextField(
enabled: false,
controller: resultController,
style: TextStyle(
color: Colors.orange, fontSize: 18, fontWeight: FontWeight.bold),
keyboardType: TextInputType.number,
decoration: InputDecoration(
enabledBorder: UnderlineInputBorder(
borderSide: BorderSide(color: isDisabled ? Colors.white : Colors.black)),
labelText: resultLableText,
labelStyle: TextStyle(color: Colors.white)),
),
You can specify the underline color of the TextField if its disabled in the same way you did for when its enabled by using the disabledBorder property of the InputDecoration like :
InputDecoration(
enabledBorder:
UnderlineInputBorder(borderSide: BorderSide(color: Colors.white)),
labelText: resultLableText,
labelStyle: TextStyle(color: Colors.white),
disabledBorder:
UnderlineInputBorder(borderSide: BorderSide(color: Colors.green)),
),
or specifying it in the ThemeData like :
MaterialApp(
theme: ThemeData.light().copyWith(
inputDecorationTheme: InputDecorationTheme(
disabledBorder:
UnderlineInputBorder(borderSide: BorderSide(color: Colors.green)),
)),
debugShowCheckedModeBanner: false,
home: Scaffold(
body: Center(
child: MyWidget(),
),
),
);
}
Unable to change the default border color when TextFormField is not active. When TextFormField is not active this shows DarkGrey-Border color. So, how to change that.
Theme(
data: new ThemeData(
primaryColor: Colors.red,
primaryColorDark: Colors.black,
),
child: TextFormField(
decoration: new InputDecoration(
labelText: "Enter Email",
fillColor: Colors.white,
border: new OutlineInputBorder(
borderRadius: new BorderRadius.circular(25.0),
borderSide: new BorderSide(),
),
//fillColor: Colors.green
),
validator: (val) {
if (val.length == 0) {
return "Email cannot be empty";
} else {
return null;
}
},
keyboardType: TextInputType.emailAddress,
style: new TextStyle(
fontFamily: "Poppins",
),
),
),
Use enabledBorder of the InputDecoration, don't forget you can also use the focusedBorder, like this :
InputDecoration(
labelText: "Enter Email",
fillColor: Colors.white,
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(25.0),
borderSide: BorderSide(
color: Colors.blue,
),
),
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(25.0),
borderSide: BorderSide(
color: Colors.red,
width: 2.0,
),
),
)
Here you have more info: https://api.flutter.dev/flutter/material/InputDecoration/enabledBorder.html
OutlineInputBorder(
borderSide: BorderSide(
color: AppColor.secondaryBackground)),
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(color:
AppColor.secondaryBackground)),
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(color:
AppColor.secondaryBackground),
),