How to pass a data from first screen to second screen but should receive on textfield widget in second screen. I have tried but there is no option in textfield widget, how to do this?
TextField(
keyboardType: TextInputType.text,
decoration: InputDecoration(
fillColor: Colors.white,
hintText: "",
filled: true,
labelText: "First name",
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(
color: Colors.white),
borderRadius: BorderRadius.circular(6),
),
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(
color: Colors.white),
borderRadius: BorderRadius.circular(6),
)),
),
To set default text in your TextField you need to use TextEditingController, you can use it by initializing in initState or directly to the TextField, here are the examples
To initialize with initState
late TextEditingController _controller;
#override
void initState() {
_controller.text = widget.text;
super.initState();
}
To pass value directly
TextField(
controller: TextEditingController(text: widget.text),
keyboardType: TextInputType.text,
decoration: InputDecoration(
fillColor: Colors.white,
hintText: "",
filled: true,
labelText: "First name",
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(color: Colors.white),
borderRadius: BorderRadius.circular(6),
),
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(color: Colors.white),
borderRadius: BorderRadius.circular(6),
)),
)
Related
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);
},
),
How to hide the bottom edge on TextField?
TextField(
decoration: InputDecoration(
hintText: '(201) 555-0123',
),
You can use the *border parameters of TextField:
TextField(
decoration: InputDecoration(
hintText: '(201) 555-0123',
// Hides the border when the TextField is enabled
enabledBorder: OutlineInputBorder(
borderSide: const BorderSide(color: Colors.transparent),
),
// Hides the border when you click the TextField
focusedBorder: OutlineInputBorder(
borderSide: const BorderSide(color: Colors.transparent),
),
// Hides the border when the TextField is disabled
disabledBorder: OutlineInputBorder(
borderSide: const BorderSide(color: Colors.transparent),
),
),
)
How are you?
You can set the border of InputDecoration to InputBorder.none.
child: TextField(
decoration: InputDecoration(
border: InputBorder.none,
hintText: S.of(context).textHere,
hintStyle: TextStyle(fontSize: 12),
),
minLines: 5,
maxLines: null,
controller: _content,
keyboardType: TextInputType.multiline,
textCapitalization: TextCapitalization.sentences,
),
https://i.stack.imgur.com/trK69.png
class _UpdateViewState extends State<UpdateView> {
var dropDownValue = "Vaccine";
#override
Widget build(BuildContext context) {
void getDropDownItem(){
print(val); //Need help here
;}
return Scaffold(
body: new Column(
children: <Widget>[
SizedBox(height: 100),
new ListTile(
leading: const Icon(Icons.person),
title: TextField(
decoration: InputDecoration(
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.all(Radius.circular(12.0)),
borderSide: BorderSide(color: Colors.blue, width: 2),
),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.all(Radius.circular(10.0)),
borderSide: BorderSide(color: Colors.blue),
),
border: OutlineInputBorder(),
labelText: 'Enter Provider Name Here',
hintText: 'Provider Name',
),
),
),
}
In this ListTile, I am trying to collect the text value and print. I'm not even sure how to collect the value from the TextField. In the tutorials, this part was skipped. Please help
You can set the controller in TextField
take controller variable
TextEditingController controller = new TextEditingController();
in TextField set controller
TextField(
controller: controller,
decoration: InputDecoration(
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.all(Radius.circular(12.0)),
borderSide: BorderSide(color: Colors.blue, width: 2),
),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.all(Radius.circular(10.0)),
borderSide: BorderSide(color: Colors.blue),
),
border: OutlineInputBorder(),
labelText: 'Enter Provider Name Here',
hintText: 'Provider Name',
)
and you can get text using controller like
controller.text
You need to use a TextEditingController , as for example:
TextEditingController _myController = TextEditingController();
final textfield = TextField(
decoration: InputDecoration(
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.all(Radius.circular(12.0)),
borderSide: BorderSide(color: Colors.blue, width: 2),
),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.all(Radius.circular(10.0)),
borderSide: BorderSide(color: Colors.blue),
),
border: OutlineInputBorder(),
labelText: 'Enter Provider Name Here',
hintText: 'Provider Name',
),
Then you can access this value using _myController.text property
There are multiple ways of doing it:
declaring a variable and assigning value to it-
String textvalue;
TextField(
onChanged: (value) {
email = value;
},
)
by assigning TextEditingController()-
TextEditingController textController;
TextField(
controller: textController,
),
now use it as
var value = textColtroller.text;
I want to align inputDecoration errorText to the bottom-right of TextField.
The default mode is bottom-left.
I want to set it like
here is my textField code:
TextField authTextFiled(
String hint, ValidationBloc bloc, AsyncSnapshot<String> snapshot) {
return TextField(
textAlign: TextAlign.right,
onChanged: (String text) => bloc.updateText(text),
decoration: InputDecoration(
hintStyle: AppStyle.textFieldHintTextStyle,
errorStyle: AppStyle.textFieldErrorTextStyle,
errorText: snapshot.hasError ? snapshot.error : null,
border: OutlineInputBorder(borderRadius: AppStyle.borderRadius),
disabledBorder: OutlineInputBorder(
borderRadius: AppStyle.borderRadius,
borderSide: BorderSide(width: 1, color: AppColors.pinkDarkDisableColor)
),
focusedBorder: OutlineInputBorder(
borderRadius: AppStyle.borderRadius,
borderSide: BorderSide(width: 1, color: AppColors.bluePrimaryColor),
),
errorBorder: OutlineInputBorder(
borderRadius: AppStyle.borderRadius,
borderSide: BorderSide(width: 1, color: AppColors.pinkDarkHotColor)
),
focusedErrorBorder: OutlineInputBorder(
borderRadius: AppStyle.borderRadius,
borderSide: BorderSide(width: 1, color: AppColors.pinkDarkHotColor)),
hintText: hint,
),
keyboardType: TextInputType.number,
textDirection: TextDirection.rtl,
);
}
any help would be appreciated.
Wrap your TextFormField inside Directionality and give RTL direction,
Directionality(
textDirection: TextDirection.rtl,
child: TextFormField(
...
What is Directionality CLass?
A widget that determines the ambient directionality of text and text-direction-sensitive render objects.
Output
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),
),