I'm developing a mobile app in Flutter, and until now I only designed a light mode UI and everything is working fine, but if I try to add a CupertinoTextField, since my phone is in dark mode it will appear black. Is there an easy way to force it to be light? I wasn't even able to find how to just change its color.
Here's my code:
final TextEditingController _textController = TextEditingController();
CupertinoTextField(
controller: _textController,
keyboardType: TextInputType.multiline,
minLines: 1,
maxLines: 5,
placeholder: 'Type a message'
)
You can change the color by adding a BoxDecoration in the CupertinoTextField
CupertinoTextField(
controller: _textController,
keyboardType: TextInputType.multiline,
minLines: 1,
maxLines: 5,
placeholder: 'Type a message',
decoration: BoxDecoration(
color: Colors.white,
),
)
Related
In Flutter TextFeild While using keyboardType:TextInputType.number along with controller of type TextEditingController, unable to enter digits using number keyboard directly. First I have to press any special symbol such as '.','-' , and then type the numbers.
final expenseAmount = TextEditingController();
TextField(
decoration: InputDecoration(
labelText: "Amount",
),
controller: expenseAmount,
keyboardType: TextInputType.number,
),
Screen Shots 1st unable to type number 2nd after . able to type
I had a similar problem when I used TextInputType.phone. After executing these lines of code controller.text = '', the numeric keypad became unavailable. controller.clean this helped me solve the problem.
You should try this
final TextEditingController price = new TextEditingController();
TextFormField(
controller: price,
keyboardType: TextInputType.number,
decoration: InputDecoration(
border: OutlineInputBorder(),
labelText: 'Amount',
hintText: 'MRP',
),
textInputAction: TextInputAction.done,
),
Other Solution:
you add the package: import 'package:flutter/services.dart';
TextFormField(
keyboardType: TextInputType.number,
inputFormatters: [
FilteringTextInputFormatter.allow(
RegExp(r'[0-9]'),
),
],
decoration: InputDecoration(
border: OutlineInputBorder(),
labelText: 'Price',
hintText: '0.00',
),
),
Refer FilteringTextInputFormatter here
change this line
final expenseAmount = TextEditingController();
to
TextEditingController expenseAmount = TextEditingController();
i think this will fix your problem.
I want to catch OTP sms code but it doesn't work on IOS.
I need show the code upper of keyboard.
my code block is;
TextField(
controller: controller,
autofillHints: const <String>[AutofillHints.oneTimeCode],
keyboardType: TextInputType.number,
onChanged: onChanged,
),
From Flutter docs at https://master-api.flutter.dev/flutter/material/TextField/autofillHints.html "Some autofill hints only work with specific keyboardTypes". Try changing the keyboardType. For example:
TextField(
controller: controller,
autofillHints: const <String>[AutofillHints.oneTimeCode],
keyboardType: TextInputType.text,
onChanged: onChanged,
),
I have a code for making Text Fields as shown below
...Column(
children: <Widget>[
textField(text: 'User Name'),
SizedBox(height: 20),
textField(text: 'Password'), ])...
textField is a class that I made that has the following code to make a textfield. I did this to avoid code duplication,since I use textfields a lot in my applicatin.
...TextField(
textInputAction: TextInputAction.next,
obscureText: text == 'Password' ? true : false,
textCapitalization: TextCapitalization.words,
cursorColor: primaryColor,
textAlign: TextAlign.center,
decoration: InputDecoration(
labelText: text,
labelStyle: TextStyle(color: primaryColor, fontFamily: 'Bellotta'),
filled: true,
fillColor: Colors.white,
border: OutlineInputBorder(...
Since I use this function to create the text field I cant use focusNode to change focus.
How can I solve this issue??
u can specify two more parameter one for focusNode of current textfield & another one for focus u want to change e.g.
textField(
text: 'User Name',
focusNode: // your focus node,
nextFocusNode: // your next field focus node
),
now u can use :
FocusScope.of(context).requestFocus(nextFocus);
tip: if u want to decrease code duplication then instead of creating textfield method u should store ur InputDecoration in var/ method.
I want show cursor always in textfield but i couldn't see a solution.
What I want to do is always show the cursor like whatsapp.
I want the cursor to appear even if the keyboard is closed
TextField(
textCapitalization:TextCapitalization.sentences,
minLines: 1,
maxLines: 6,
controller: _textEditingController,
focusNode: _focusNode,
)
TextField(
textCapitalization:TextCapitalization.sentences,
minLines: 1,
maxLines: 6,
autofocus: true, // line Added
controller: _textEditingController,
focusNode: _focusNode,
)
I want to disable predictive text which comes in the keyboard of a textfield. It is not so difficult in native android and IOS but I have not found a solution in a Flutter.
I have tried using autocorrect: false and changing keyboardtypes but it is not working.
TextField(
autocorrect: false,
keyboardType: TextInputType.emailAddress,
decoration: new InputDecoration(hintText: "Enter text"),
autofocus: true,
),
If neither enableSuggestions nor autocorrect can solve the problem, try setting keyboardType to TextInputType.visiblePassword.
You can try to add enableSuggestions = false to your textfield widget. This should disable the predictive text from your keyboard as supposed to https://github.com/flutter/flutter/pull/42550.
TextField(
autocorrect: false,
enableSuggestions: false,
keyboardType: TextInputType.emailAddress,
decoration: new InputDecoration(hintText: "Enter text"),
autofocus: true,
),
At the time of writing this answer, this is not yet available in Android. But using autocorrect: false on iOS should work fine.
Check: https://github.com/flutter/flutter/issues/22828
This worked for me on both iOS and android
TextField(
autocorrect: false,
obscureText: true,
controller: answerText,
textAlign: TextAlign.center,
keyboardType: TextInputType.text,
textInputAction: TextInputAction.done,
autofocus: true,
onChanged: (value) {
setState(() {
result = value;
});
},),
The only downside is that it obscure from the screen what is written. A workaround is to add somewhere in the screen Text(result)