In a Flutter app textBox, user is entering text and numbers. What method can be used to suppress the keyboard suggestion bar?
use EditableText class and set property autocorrect to false.
Do tell if it works, haven't tried it yet.
You can use this for disable sugestions and autocorrect:
TextField(
enableSuggestions: false,
autocorrect: false
),
just add parameter autocorrect:false,Then it will hide the suggestions.
new TextField(
autocorrect: false,
controller: _tbName,
decoration: new InputDecoration(
icon: const Icon(Icons.person),
hintText: 'Enter your Name',
labelText: 'Name',
helperText: 'Required',
errorText: nameErrorText,
),
onChanged: (value) {
//save here
},
);
To disable the suggestion bar, you need to use the smartDashesType parameter.
This solution works fine for me:
TextFormField(
smartDashesType: SmartDashesType.disabled,
autocorrect: false
)
Related
I'm new here and with Flutter, at this moment i'm developing an app to list data from my node api. I have found the way to filter that data and then show it in a flutter Datatable. Now, i want to give format to my "Cantidad" column. I though creating like a dropdown button and put it in the title of my Cantidad column. Then I will select the format between "Bandejas" or "Plantas" , these will change the value of all the cells in this columns. Do you have any idea to achieve this?
My app screnshoot
I drawed it to make more sense to you, if you take a look in my cantidad title there is a red arrow, i want to design a dropdown there. It's only a simbolyc draw.
Since label in DataColumn can be any widget, you can just use a DropdownButton there, here's a code sample i just did.
return DataTable(
border: TableBorder.all(width: 1),
columns: [
const DataColumn(
label: Text('Fecha'),
),
const DataColumn(
label: Text('Especie'),
),
DataColumn(
label: DropdownButton(
hint: const Text(
'Cantidad',
style: TextStyle(color: Colors.black),
),
underline: Container(),
items: const [
DropdownMenuItem(
value: 'Bandejas',
child: Text('Bandejas'),
),
DropdownMenuItem(
value: 'Plantas',
child: Text('Plantas'),
),
],
onChanged: (value) {
//Here update your column values
},
),
),
],
rows: const [],
);
Here's how it looks:
I am trying to override the default behaviour of a new line when pressing enter. I am able to catch the key event, but it still defaults to adding a new line. The idea is to execute a function on enter key.
Here's my code for catching the enter key
RawKeyboardListener(
child: EditableText(
style: const TextStyle(
fontSize: 16,
),
backgroundCursorColor: Colors.black,
controller: widget.controller,
cursorColor: Colors.black,
focusNode: widget.focusNode,
maxLines: null,
),
focusNode: FocusNode(),
onKey: (RawKeyEvent event) {
if (event.isKeyPressed(LogicalKeyboardKey.enter)) //Enter Key ID from keyboard
{
print("Enter is pressed");
}
},
),
Without knowing what you are trying to accomplish, there is a way to have a multiline TextField that does not create a new line on pressing enter. You could then listen in onEditingComplete or onSubmitted:
TextField(
keyboardType: TextInputType.text,
maxLines: null,
onEditingComplete: () => print('Enter was probably pressed'),
)
I have created a custom widget that contains an Inkwell widget. I would like to popup a selection menu allowing a user to pick an option when the Inkwell is press. Can anyone give me a suggestion on how to accomplish this? Thanks in advance.
You can use AlertDialog-class to do that:
onPress() {
showDialog<Null>(
builder: (BuildContext context) {
return new AlertDialog(
title: new Text('Rewind and remember'),
content: Text("...")
);
},
);
}
NB! This code does not work. The operation ends with application crash.
You can use directly the PopupMenuButton it is a widget
PopupMenuButton<int>(
child: Icon(Icons.more_vert),
itemBuilder: (c) => [
PopupMenuItem(
value: 1,
child: Text('edit'),
),
PopupMenuItem(
value: 2,
child: Text('delete'),
),
],
),
I just have a simple Card like new Card(child: new Text('My cool card')) and I want to be able to click anywhere on it to run some function, except there's no onPressed method for a Card. I could add a button to the bottom, but that's not ideal for this situation.
Anyone know how to make the whole card clickable?
Flutter use composition over properties.
Wrap the desired widget into a clickable one to achieve what you need.
Some clickable widgets : GestureDetector, InkWell, InkResponse.
GestureDetector(
onTap: () => ......,
child: Card(...),
);
Flutter provides the InkWell Widget. by registering a callback you can decide what happens when user clicks on the card (called tap in flutter). InkWell also implements Material Design ripple effect
Card(
child: new InkWell(
onTap: () {
print("tapped");
},
child: Container(
width: 100.0,
height: 100.0,
),
),
),
I think you can also use InkWell apart from GestureDetector just wrap the card inside InkWell() Widget
InkWell(
onTap: (){ print("Card Clicked"); }
child: new Card(),
);
You can use Inkwell and insert splashColor which, at the click of the user, creates the rebound effect with the chosen color, on the card ..
This is mainly used in material design.
return Card(
color: item.completed ? Colors.white70 : Colors.white,
elevation: 8,
child: InkWell(
splashColor: "Insert color when user tap on card",
onTap: () async {
},
),
);
Wrap a card in GestureDetector Widget like a below:
GestureDetector(
onTap: () {
// To do
},
child: Card(
),
),
Another way is as follows:
InkWell(
onTap: () {
// To do
},
child: Card(),
),
In Flutter, InkWell is a material widget that responds to touch action.
InkWell(
child: Card(......),
onTap: () {
print("Click event on Container");
},
);
GestureDetector is a widget that detects the gestures.
GestureDetector(
onTap: () {
print("Click event on Container");
},
child: Card(.......),
)
Difference
InkWell is a material widget and it can show you a Ripple Effect whenever a touch was received.
GestureDetector is more general-purpose, not only for touch but also for other gestures.
The most preferred way is to add ListTile as Card child. Not only does ListTile contain the method onTap it also helps you in making Card interesting.
Card(
child: ListTile(
title: Text('Title')
leading: CircleAvatar(
backgroundImage: AssetImage('assets/images/test.jpg'),
),
onTap: () {
print('Card Clicked');
},
),
),
You also can insert a card into a TextButton:
TextButton clickableCard = TextButton(child: card, onPressed: onCardClick, style: [...]);
This brings the advantage, that you get some features for free. For example in Flutter Web, you get a mousover effect and the cursor changes to the hand so that ths user knows, he can click there. Other additional features can be customised using the style.
Do something on tap/click of 'child' in Flutter:-
Code:-your code looks like:
child: Card(------
------------
--------),
Step1:- Put your mouse cursor on Card then, press- Alt+Enter(in windows) select wrap with widget.
Step2:- Change your default widget into GestureDetector.
final code:-
child: GestureDetector(
onTap: YourOnClickCode(),
child: Card(------
------------
--------),
),
Most of the answers are brilliant but I just want to share mine for the one who wants to make/show a ripple effect on Tap of card or list tile.
Card(
child: TextButton(
onPressed: ()=> ...,
child: ListTile(
title: Text('title'),
),
),
);
There is probably something obvious I'm missing. Is there one property that can change the color of all the text in a Flutter app?
The way I am doing it now is, in my MaterialApp:
theme: ThemeData(
textTheme: Theme.of(context).textTheme.copyWith(
body1:
Theme.of(context).textTheme.body1.apply(color: Colors.pink),
body2:
Theme.of(context).textTheme.body2.apply(color: Colors.pink),
display1:
Theme.of(context).textTheme.display1.apply(color: Colors.pink),
display2:
Theme.of(context).textTheme.display2.apply(color: Colors.pink),
... // and so on
),
),
),
I also tried
textTheme: Theme.of(context).textTheme.apply(bodyColor: Colors.pink),
but this applies to Dropdown text, not regular text. Likewise, displayColor applies to the appBar text and a InputDecoration text, but not regular text. I don't seem to have any decorationText in my code so I'm not sure what that one is for.
I note there is a textSelectionColor property but that only applies for TextField widgets.
I think TextTheme.apply is what you want. bodyColor will be applied to headline, title, subhead, button, body1, and body2. displayColor will be applied to display1 through display4, and caption. If you specify both bodyColor and displayColor and use the same color value, that will effectively change text colors on all text styles.
Example:
final newTextTheme = Theme.of(context).textTheme.apply(
bodyColor: Colors.pink,
displayColor: Colors.pink,
);
For the entire app, you can set textTheme property in the Material app widget.
MaterialApp(
theme: ThemeData(
textTheme: TextTheme(
bodyText1: TextStyle(),
bodyText2: TextStyle(),
).apply(
bodyColor: Colors.orange,
displayColor: Colors.blue,
),
),
)
To provide an alternative that seems to work without setting all the Text styles directly is to change the style of the DefaultTextStyle at the place in the Widget tree to take effect
return DefaultTextStyle(
style: TextStyle(color: Colors.pink),
child: _YOUR_WIDGETS_
)
Maybe a bit late... but you can use this:
ThemeData(
primaryTextTheme: Typography(platform: TargetPlatform.iOS).white,
textTheme: Typography(platform: TargetPlatform.iOS).white,
)
mine is working with this:
return MaterialApp(
theme: ThemeData(
textTheme: TextTheme(
bodyText2: TextStyle(
color: Colors.white,
),
),
),
);
I found using copyWith() on the TextTheme works well, as you can just change specific properties like fontsize - leaving everthing else unchanged.
textTheme: TextTheme().copyWith(
bodyText2: TextStyle(
fontSize: 30,
fontWeight: FontWeight.bold
)
),