Apply Gradient colours to Bottom Nav bar with floating action button - flutter

I need to make a nav bar with a floating action button just like this image:
what I have been able to make is in this picture :
The problem is that I wrapped my raw in a container, added box decoration to apply gradient property to my bottom nav bar which ended up deleting the white curve of the floating action button inside the nabber. I want to be able to preserve the white curve just like in the first image and be able to apply gradient colours only to my nav bar is it possible to do so without using a box decoration ?
Here's my code currently :
Widget build(BuildContext context) {
return SafeArea(child:
Scaffold(
floatingActionButton:FloatingActionButton( //Floating action button on Scaffold
onPressed: (){
//code to execute on button press
},
child: Icon(Icons.add), //icon inside button
backgroundColor: kPrimaryColor,
),
floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
//floating action button position to center
bottomNavigationBar: Container(
decoration: const BoxDecoration(
borderRadius: BorderRadius.only(
topRight: Radius.circular(30), topLeft: Radius.circular(30)),
color: Colors.white,
),
child: ClipRRect(
borderRadius: const BorderRadius.only(
topLeft: Radius.circular(30.0),
topRight: Radius.circular(30.0),
),
child: BottomAppBar( //bottom navigation bar on scaffold
color:Colors.transparent,
shape: CircularNotchedRectangle(), //shape of notch
notchMargin: 5, //notche margin between floating button and bottom appbar
child: Container(
decoration: const BoxDecoration(
gradient: LinearGradient(
colors: [kPrimaryColor, kPrimaryLightColor],
begin: Alignment.topLeft,
end: Alignment.topRight,
stops: [0.1, 0.8],
tileMode: TileMode.clamp,
),
),
child: Row( //children inside bottom appbar
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
IconButton(icon: Icon(Icons.home_filled, color: Colors.white,), onPressed: () {},),
IconButton(icon: Icon(Icons.check_circle, color: Colors.white,), onPressed: () {},),
IconButton(icon: Icon(Icons.analytics, color: Colors.white,), onPressed: () {},),
IconButton(icon: Icon(Icons.person, color: Colors.white,), onPressed: () {},),
],
),
),
),
)
)
) );
}
If anyone knows the answer or can help I'd be grateful .

Add this inside the BottomAppBar
clipBehavior: Clip.antiAlias,

Related

Flutter Material() in ListView builder decoration

How to change Material() border color i have this code, inkWell is a child of sliable widget that also returned in ListView.builder
child:InkWell(
onTap: (){
},
child: Material(
color: Colors.blueAccent,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(18),
),
child: buildListTile(item),
)
));
i need something like
also i can use only Material() class because my ListView.builder return me Sliable widget from Sliable library, and this is only widget i found that must work fine with desing that i wont
You can change the border of the Material widget using the side property inside your RoundedRectangleBorder.
I also typically put the InkWell inside the Material widget too.
Padding(
padding: const EdgeInsets.all(8.0),
child: Material(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(18),
side: const BorderSide(color: Colors.blueAccent),
),
child: InkWell(
borderRadius: BorderRadius.circular(18),
onTap: () {},
child: const ListTile(title: Text('item')),
),
),
),
You can use Card also try below code hope its help to you I have tried same as your image.
Card(
shape: RoundedRectangleBorder(
side: BorderSide(color: Colors.green.shade300),
borderRadius: BorderRadius.circular(15.0),
),
child: Column(
children: [
ListTile(
leading: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text('OK'),
Text('OK'),
],
),
title: Text('name'),
),
],
),
),
Your result screen->

FlatButton's left and right edges are not colorizing

I am trying to make a gradient colored flat button but left and right edges of the button are not getting colorized as the image.
And here is my flatbutton codes:
return new Container(
width: MediaQuery.of(context).size.width,
height: 40,
child: RaisedButton(
focusNode: buttonFocusNode,
onPressed: () {},
child: Container(
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.centerLeft,
end: Alignment.centerRight,
colors: [Colors.pink, Colors.purple],
),
),
),
),
);
}
It happens on both emulator and real device. My hyerarchy to button in build is : SafeArea->Scaffold->Container->Stack->Container->Column->Button. I tried to wrap it inside container, sizedbox, played with width but nothing helped. Any idea why this is happening and how can I solve it? Thanks in advance.
Solution with an ElevatedButton:
ElevatedButton(
onPressed: () {},
style: ElevatedButton.styleFrom(
padding: EdgeInsets.zero,
shape: RoundedRectangleBorder(
borderRadius: new BorderRadius.circular(30.0),
),
),
clipBehavior: Clip.antiAlias, // <====== [2]
child: Container(
padding: EdgeInsets.symmetric(horizontal: 16.0, vertical: 8.0), // <====== [1]
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.centerLeft,
end: Alignment.centerRight,
colors: [Colors.pink, Colors.purple],
),
),
child: Text(
'CLICK ME!',
style: TextStyle(color: Colors.white, fontSize: 48.0),
),
),
)
Important point 1
Since you remove the padding on the button, remember to add it on the child Container. Otherwise, you'll have problems once you add some text:
Important point 2
If you want rounded corners, remember to set the Clip Behavior of the button. Otherwise, you will not get your rounded corners:
Because RaisedButton adds padding for the child. You need to set the padding to EdgeInsets.zero.
Example
RaisedButton(
padding: EdgeInsets.zero,

How to make a radial gradient floating action button

Is there any way to set the floating action buttons color as a radial gradient in flutter? Something like below:
Set a container as the child of that FAB and assign a gradient to the container.
FloatingActionButton(
onPressed: () {},
tooltip: 'Cool FAB',
child: Container(
decoration: BoxDecoration(
shape: BoxShape.circle,
gradient: RadialGradient(
center: const Alignment(0.0, 0.0),
radius: 0.5,
colors: [ Color(0xFF0187D0), Color(0xFF01579C),],
),
),
),
),
It will look like:
EDIT:
For adding icon, you have to specify a size to your container and set the icon as it's child (I've used the FAB default size of 56x56).
FloatingActionButton(
onPressed: () {},
tooltip: 'Cool FAB',
child: Container(
width: 56,
height: 56,
child: Icon(Icons.settings),
decoration: BoxDecoration(
shape: BoxShape.circle,
gradient: RadialGradient(
center: const Alignment(0.0, 0.0),
radius: 0.5,
colors: [ Color(0xFF0187D0), Color(0xFF01579C),],
),
),
),
),
And now it will look like:

Flutter ListTile splash/ripple effect not matching border

I have a ListTile in flutter but I cannot seem to figure out how to make the splash/ripple effect fit the border. My border is rounded, but the splash is just a normal rectangle with no round borders, as seen on the image below.
ListTile
Below is the code for the ListTile.
Ink(
decoration: BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(borderRadius)),
),
child: ListTile(
title: text(title, 0.0),
leading: Icon(
icon,
color: primaryColor,
),
)
)
You can use InkWell:
InkWell(
customBorder: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10),
),
onTap: () {},
splashColor: Colors.red,
child: ListTile(
title: Text("Title"),
),
),
Surround Ink or InkWell with ClipRRect with border-radius value equal to
BorderRadius.all(Radius.circular(borderRadius))
Better, replace Ink with InkWell and set borderRadius: BorderRadius.all(Radius.circular(borderRadius)) which won't need clipping.
thus you can write
InkWell(
borderRadius: BorderRadius.circular(borderRadius),
onTap: () {},
splashColor: Colors.red,
child: ListTile(
title: Text("Title"),
),
),

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