Is there anything like PostfixIcon for TextField in flutter - flutter

I've already tried PrefixIcon for TextField in flutter but this time I'm looking for something like Postfix Clickable Icon in flutter. I'm attaching the image and I want to achieve something like that.
Where the Icon is clickable and on clicking the Icon it will display the other TextField.
Here's the Image:

Use a suffixIcon. If that doesn't behave how you'd expect, you can always use a Stack.

You can use a Stack Widget to do that. it works similar to a Row or a Column but its Stacks its children on top of each other.
https://api.flutter.dev/flutter/widgets/Stack-class.html
what you are trying to do this something like this,
Stack(
alignment: Alignment.centerRight,
children: <Widget>[
TextField(),
IconButton(icon: Icon(Icons.add), onPressed: (){
//Code
})
],
),

You can use a Stack Widget #Srilal Sachintha
Stack(
alignment: Alignment.centerRight,
children: <Widget>[
TextFormField(),
IconButton(icon: Icon(Icons.add), onPressed: (){
//Code
})
],
),
or Use a suffixIcon. If that doesn't behave how you'd expect, you can always use a Stack. #

Related

How to add button in Flutter

I am new in flutter.
I am following some YouTube videos to learn flutter. After adding a picture in card(home screen) now I want to add two buttons below that picture. how can i do it.
the picture Adding code
body: Center(
child: Card(
child: Column(
children: [Image.asset("assets/image-name")],
),
),
),
Here you have a great page, where you can find implementations of basic material widgets in Flutter.
For your example, it would look like this:
body: Center(
child: Card(
child: Column(
children: [
Image.asset("assets/image-name"),
ElevatedButton(
onPressed: () {
// Respond to button press
},
child: Text('CONTAINED BUTTON'),
)
],
),
),
),
For a second button, you can just add another one in the children array.
You can also wrap both buttons in Row widget, that will allow you to place them horizontally, next to each other.

What widget to use to get a sign up button with google logo at the left

I saved the google logo a as .png because I want to keep its colors. I am aware there are some packages for predefined sign-in buttons like google or with the google Icon(but I can't keep the colors obviously in this case), but I would like to know if I can somehow make so the .png image acts like an Icon.
You can use whatever button widget you like or you can create your custom button...
According to your image you can use outline button or flat button... then in your child parameter add Row with image and text
OutlineButton(child: Row(children: Image.asset(your_image_location), Text('Sign in with Google')))
body: Stack(
children: <Widget>[
Center(
child: IconButton(
icon: Image.asset('path/the_image.png'),
iconSize: 50,
onPressed: () {},
)
Positioned(
child: Container(
child: Center(child: Text('Sign in With Google')),
)),
],
)

Flutter error - The specific widget that could not find a Material ancestor was:

I am using the Align widget to place an Icon button at the bottom center of the screen.
However, I get the following error and I'm unable to resolve it:
The specific widget that could not find a Material ancestor was:
IconButton
My code:
return Stack(
children: <Widget>[
Container(
child: GoogleMap(
initialCameraPosition:
CameraPosition(target: LatLng(1,1), zoom: 15),
onMapCreated: (map) {
mapReady;
},),
),
Align(
alignment:Alignment.bottomCenter,
child: IconButton(
icon: Icon(Icons.next_week), onPressed: (){}),
)
],
If I replace the IconButton widget with for example a Text widget it works well.
Could you please explain why it doesn't work, why the IconButton needs a Material ancestor?
Because as per documentation of IconButton (https://api.flutter.dev/flutter/material/IconButton-class.html)
An icon button is a picture printed on a Material widget that reacts
to touches by filling with color (ink).
[..]
Requires one of its ancestors to be a Material widget.
IconButton uses most likely ThemeData as well as other things which MaterialApp normally provides.
Is there a reason you dont use MaterialApp as ancestor?
If you wrap you stack (or the parent in general) with Scaffold you will n get this error.
In this case, if you wrap your IconButton with Material Widget,i believe it will fix the problem:
Align(
alignment: Alignment.bottomCenter,
child: Material(
child: IconButton(icon: Icon(Icons.next_week), onPressed: () {})),
)

Making a scrollable flat button in Flutter application

I'm trying to embed a flat button with a variable amount of text within a scroll view, so that the user can scroll the text but also tap it in order to perform an action. I tried doing this with a flat button embedded in a ConstrainedBox, which itself is embedded in a SingleChildScrollView.
I've tried embedding the FlatButton in a SingleChildScrollView as below. Earlier, I tried wrapping the text in an expanded widget with a SingleChildScrollView ancestor but that caused runtime errors because the requirements of the scroll view and the expanded view conflict (as far as I understand).
Widget contentScreen() {
return SingleChildScrollView(
child: ConstrainedBox(
constraints: BoxConstraints(),
child: FlatButton(
onPressed: () {
_toggleContent();
},
child:
Column(children: <Widget>[
Container(
child: Text(
"Lorem Ipsum....",
style: TextStyle(color: Colors.white, fontSize: 20))),
]
)
)
)
);
}
The text just doesn't scroll. Instead it overflows and shows the diagonal yellow bars. I don't have a list of exactly what I've tried, but where I'm at right now is that I'm using the above code but there is no scrolling behavior as expected. :\
I tried this: How to make the Scrollable text in flutter?
This: Make scrollable Text inside container in Flutter
And this: how to make text or richtext scrollable in flutter?
Is there something about the FlatButton's behavior that just precludes scrolling? If so, how can I work around that to still get the two behaviors (ability to both scroll and tap to perform action) that I want?
Have you tried this? Why do you need Expanded widget?
Container(
height: 20.0,
child: FlatButton(
onPressed: () {},
child: SingleChildScrollView(
child: Text('Lorem ipsum'),
),
),
),
Gesture Detector should also work well.
Container(
height: 20.0,
child: FlatButton(
onPressed: () {},
child: SingleChildScrollView(
child: Text('Lorem ipsum'),
),
),
),

How can I achieve BottomNavigationBar with 1 NavigationBarItem

I want a BottomNavigationBar with 1 NavigationBarItem. The purpose is to display a record count for a list.
Can someone please advise me if there is a way to achieve that?
I can see no logical reason why the "items:" must exceed 1 item, but I'd be pleased to learn why.
Into bottomNavigationBar need to minimun 2 NavigationBarItem require. but you want a BottomNavigationBar with 1 NavigationBarItem, So you can use the Custom layout for the BottomNavigationBarItem for display 1 item into bottomNavigationBar
Custom Layout like as bellow :
bottomNavigationBar: Container(
height: 65,
color: Colors.grey,
child: Center(
child: Column(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
IconButton(
icon: Icon(Icons.list),
onPressed: (){},
),
Text("items"),
],
),
),
),
Another way to handle this and the way that I ended up using is to add an invisible BottomNavigationBarItem to the BottomNavigationBar. The way to do that is to just use icon: Icon(null) and an zero-length text. The reason that at least two items are needed in the BottomNavigationBar is possibly because of the docking capability of the FAB button which is a very useful feature.