How do I remove the empty space at the beginning of a card in Flutter? - flutter

So I have this card:
and I want to make it so the blue box looks like this:
how would I do this?
my code is this:
child: Card(
elevation: 5.0,
child: ListTile(
onTap: () {},
title: Text(tasks[index].title),
subtitle: Text(tasks[index].description, overflow: TextOverflow.ellipsis, maxLines: 1,),
leading: ClipRRect(
borderRadius: BorderRadius.circular(2.0),
child: SizedBox(
height: 60.0,
width: 10.0,
child: DecoratedBox(
decoration: BoxDecoration(
color: Colors.blue,
),
),
),
)
),
),

Check the DevTools here https://flutter.dev/docs/development/tools/devtools/overview
They are super useful especially for when there is something wrong with the layout of your widgets, you can see exactly what is wrong woth that widget.
Im guessing its the SizedBox width:10.

Related

How to add shadow just to an image in Card in Circle Avatar in flutter?

I am new to flutter and I want to add shadow to an image in Card (shadow just to an image not the text), how can I do that? Below is the snippet of my code, please let me know how can I do that, thank you.
child: Container(
height: 70,
child: Card(
child: ListTile(
onTap: () {},
title: Text(eventList[index].event_name),
leading: CircleAvatar(
backgroundImage: NetworkImage(eventList[index].imageURL),
),
),
),
),
you can wrap the CircleAvatar with another Container and specify the boxShadow property in its decoration, or for more accuracy, just use a DecoratedBox like this:
Container(
height: 70,
child: Card(
child: ListTile(
onTap: () {},
title: Text("eventList[index].event_name"),
leading: DecoratedBox(
decoration: BoxDecoration(
boxShadow: <BoxShadow>[
BoxShadow(
color: Colors.black.withOpacity(.2),
blurRadius: 5,
offset: const Offset(0, 10),
)
]),
child: CircleAvatar(
backgroundImage: NetworkImage("eventList[index].imageURL"),
),
),
),
),
);
You can simply use a Widget called PhysicalModel where it can easily show shadows. You can play with the properties such as color and elevation for your desired shadow effect.
https://api.flutter.dev/flutter/widgets/PhysicalModel-class.html
leading: PhysicalModel(
color: Colors.grey.withOpacity(0.8),
shape: BoxShape.circle,
elevation: 10.0,
child: const CircleAvatar(
backgroundImage: NetworkImage(
'https://i1.sndcdn.com/artworks-000486414654-mt7qdt-t500x500.jpg'),
),
),

Flutter: How to make chat page bottom text bar

I am trying to make a chat page on flutter that looks like this: top bar + bottom textField and send button. I have been able to make both the top appbar and the textfield with the send button, but I have not been able to position the textfield at the bottom of the page successfully. I have tried things like Align and Expand, footer, BottomNavigationBar.
The current version of the code I have pasted only shows the top Appbar. If I take out the child Row and the send button, I have a textfield at the bottom of the page. For some reason, as soon as I add the child Row in order to be able to add the send button, the entire textfield does not show up on the screen. I would appreciate any help.
Note: Since I am trying to make a chat screen, I want the middle section to be scrollable (while the top and bottom remain), where I can later add the chat bubbles.
Screenshot of code because of the bad editing of code snippet
Continuation of code snippet
"""
#override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: ColorConstant.whiteA700,
// Top bar
appBar: AppBar(
backgroundColor: ColorConstant.deepOrange300,
title: Text("Match's Name",style: AppStyle.textstyleinterregular15.copyWith(
fontSize: getFontSize(15))),
),
body: Column(
children: [
Expanded(child: SingleChildScrollView(
child: Column(
children: [
// Bubbles
],
),
),
),
Container(
height: 45,
width: double.infinity,
color: ColorConstant.whiteA700,
child: Row(children: <Widget>[
TextField(
decoration: InputDecoration(
hintText: "Message...",
hintStyle: TextStyle(color: ColorConstant.bluegray100),
border: OutlineInputBorder(
borderSide: BorderSide(color: ColorConstant.bluegray100)
),
)
),
SizedBox(width: 15,),
// Send Button
FloatingActionButton(
onPressed: (){},
child: Icon(Icons.send,color: ColorConstant.whiteA700,size: 18,),
backgroundColor: ColorConstant.lightBlueA100,
elevation: 0,
),
]),
);
],
),
);
"""
Try this one...
bottomNavigationBar: Padding(
padding:
EdgeInsets.only(bottom: MediaQuery.of(context).viewInsets.bottom),
child: Container(
height: 45,
width: MediaQuery.of(context).size.width,
color: Colors.white,
child: Row(
children: [
Expanded(
child: const TextField(
decoration: InputDecoration(
hintText: "Message...",
hintStyle: TextStyle(color: Colors.blue),
border: OutlineInputBorder(
borderSide: BorderSide(color: Colors.blue)),
),
),
),
SizedBox(
width: 15,
),
// Send Button
MaterialButton(
color: Colors.red,
onPressed: () {},
child: Icon(
Icons.send,
color: Colors.white,
size: 18,
),
// backgroundColor: ColorConstant.lightBlueA100,
elevation: 0,
),
],
),
),
),
Wrap TextField with Expanded widget it'll work for you.

Flutter: Full bottom button with safe area

I faced with this problem: I found the only way to do so that the background of the button was in full height when using safearea on iPhone 11. But now the button is pressed partially podskajet. Please how to make the entire blue area pressed as a button. Thank you all for your answers.
I add a screenshot and a piece of code as it is implemented now.
Container(
color: Colors.blue,
child: SafeArea(
left: false,
right: false,
child: Expanded(
flex: 1,
child: SizedBox(
width: double.infinity,
child: RaisedButton(
elevation: 0,
onPressed: () {},
child: Text("Add", style: TextStyle(color: Colors.white)),
color: Colors.blue,
),
),
),
),
),
You can check by changing the color of this Container.
Container(
color: Colors.red,
Or you can use Debug Paint using the inspector. And then you will realize that some area is not in the button. This is the reason why onTap is not working.
After that time you can use InkWell easily with wrapping all your Container.
InkWell(
onTap: () {
// Here is your onTap function
},
Container(
color: Colors.red,
child: SafeArea(
left: false,
right: false,
child: Expanded(
flex: 1,
child: SizedBox(
width: double.infinity,
// In fact, you don't need a button anymore.
child: RaisedButton(
elevation: 0,
onPressed: () {},
child: Text("Add", style: TextStyle(color: Colors.white)),
color: Colors.blue,
),
),
),
),
),
),

How to handle the flutter widget size compatible to all device?

Here I'm taking two widgets one is textfield widget and another one is Icon widget both are placed in seperate container. I'm very new to flutter, I dont know how to place two widgets parallely each other with different size. But somehow designed for my mobile but when i run my app on different mobile its widgets are overflowing.Can anybody help me out from this issue. Thanks in advance!!! For More reference see the image given.
Here is my code
Padding(
padding: const EdgeInsets.only(
top: 10.0, bottom: 4.0, right: 20.0, left: 20.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
Container(
child: Material(
color: Colors.white,
elevation: 3.0,
// CONTAINER BACKSIDE SHADOW DEPTH
borderRadius: BorderRadius.circular(5.0),
shadowColor: Color(0xFF90A4AE),
//CONTAINER BACKSIDE SHADOW COLOR
child: Expanded(
child: TextField(
decoration: InputDecoration(
border: InputBorder.none,
prefixIcon: IconButton(
icon: Icon(
Icons.search,
color: Colors.pink,
),
onPressed: () {},
),
hintText: "Search for restaurant",
hintStyle: TextStyle(fontSize: 15),
),
onChanged: (input) {
print(input);
},
),
),
),
height: 55.0,
width: MediaQuery
.of(context)
.size
.width - 120,
decoration: BoxDecoration(
border: Border.all(
color: Colors.white,
width: 1.0,
style: BorderStyle.solid),
borderRadius: BorderRadius.circular(5.0),
),
),
Container(
child: Material(
color: Colors.white,
elevation: 3.0,
// CONTAINER BACKSIDE SHADOW DEPTH
borderRadius: BorderRadius.circular(5.0),
shadowColor: Color(
0xFF90A4AE),
child: IconButton(
icon: Icon(Icons.tune),
color: Colors.pink,
onPressed: () {
[enter image description here][1]
},
), //CONTAINER BACKSIDE SHADOW COLOR
),
height: 55.0,
width: MediaQuery
.of(context)
.size
.width - 300,
decoration: BoxDecoration(
border: Border.all(
color: Colors.white,
width: 1.0,
style: BorderStyle.solid),
borderRadius: BorderRadius.circular(5.0)),
)
],
),
),
From the screenshot and the code, I see there are two widgets in a row and the screen is overflown as it couldn't accommodate and show both of them.
There are two solutions:
To show the row children in the next line automatically if overflown.
To make the row children scrollable row-wise.
NOTE: SMLink is my custom widget. Just used here for demonstration purposes.
SOLUTION-1
The simple workaround would be to use the Wrap widget instead of the Row widget.
The Wrap widget simply takes the children who are prone to screen overflow and places them on the next line. You can set the direction, spacing etc, in addition to the options that Row widget can offer. Try it & let me know.
// By default, it behaves as Row, you can set the direction attribute to Axi.vertical to mimic the Column widget.
Wrap(
spacing: 8.0,
runAlignment: WrapAlignment.center,
crossAxisAlignment: WrapCrossAlignment.center,
alignment: WrapAlignment.center,
children:
[
SMLink(logo: 'Medium', link: Constants.LINK_MEDIUM),
SMLink(logo: 'linkedin', link: Constants.LINK_LINKEDIN),
SMLink(logo: 'facebook', link: Constants.LINK_FAEBOOK),
SMLink(logo: 'Qwiklabs', link: Constants.LINK_QWIKLABS),
],
)
SOLUTION-2
From the screenshot, the other way to fix would be by making the row scrollable. This makes UI look consistent in your case. We can use ListView widget for this.
ListView(
scrollDirection: Axis.horizontal,
children:
[
SMLink(logo: 'Medium', link: Constants.LINK_MEDIUM),
SMLink(logo: 'linkedin', link: Constants.LINK_LINKEDIN),
SMLink(logo: 'facebook', link: Constants.LINK_FAEBOOK),
SMLink(logo: 'Qwiklabs', link: Constants.LINK_QWIKLABS),
],
)

Flutter: how can I make a rounded PopupMenuButton's InkWell?

I have a PopupMenuButton inside a FloatingActionButton. But it's InkWell is not rounded, it is standard square shape. How can I achieve that?
Use customBorder property of InkWell:
InkWell(
customBorder: CircleBorder(),
onTap: () {}
child: ...
)
You can use borderRadius property of InkWell to get a rounded Ink Splash.
Material(
color: Colors.lightBlue,
borderRadius: BorderRadius.circular(25.0),
child: InkWell(
splashColor: Colors.blue,
borderRadius: BorderRadius.circular(25.0),
child: Text('Button'),
),
),
To change the InkWell's shape to rounded from standard square shape, Material's borderRadius property is used. Example code is given below -
floatingActionButton: FloatingActionButton(
backgroundColor: Colors.green,
child: Material(
color: Colors.yellow,
borderRadius: BorderRadius.all(Radius.circular(5.0)),
child: InkWell(
child: PopupMenuButton(
//shape is used to change the shape of popup card
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(15.0)),
child: Icon(Icons.mode_edit, size: 22.0, color: Colors.red,),
itemBuilder: (context) => [
PopupMenuItem(
child: Text("Child 1"),
),
PopupMenuItem(
child: Text("Child 2"),
),
],
),
),
),
),
I faced a similar issue where the child of the PopupMenuButton would have a square InkWell around it.
In order to make it behave like an IconButton, which naturally uses the rounded InkWell, I simply had to use the icon paramater instead of the child.
icon: Icon(Icons.more_vert),
This is indicated in the documentation for that paramater:
/// If provided, the [icon] is used for this button
/// and the button will behave like an [IconButton].
final Widget icon;
Wrap the Inkwell with Material. Add Border Radius
Material(
borderRadius: BorderRadius.all( // add
Radius.circular(20)
),
child: InkWell(
child: Ink(
padding: EdgeInsets.symmetric(vertical: 5, horizontal: 10),
child: Text(
"Kayıt Ol",
style: TextStyle(
color: cKutuRengi,
),
),
),
),
)
Here's how to make the tap effect look right
Material(
borderRadius: BorderRadius.all(
Radius.circular(20)
),
child: InkWell(
customBorder:RoundedRectangleBorder( // add
borderRadius: BorderRadius.all(
Radius.circular(20)
)
),
onTap: () {
debugPrint("on tap");
},
child: Ink(
padding: EdgeInsets.symmetric(vertical: 5, horizontal: 10),
child: Text(
"Kayıt Ol",
style: TextStyle(
color: cKutuRengi,
),
),
),
),
)
Most of the answers here are not using PopupMenuButton like the question specified. If you're simply using an icon child then you can use the icon property rather than child as already explained above, but if you want rounded corners on some other child, you wrap it with a Material, and wrap that with a ClipRRect See this Stackoverflow