Overflowed with some Row of raisedbuton in flutter - flutter

Hello I only try to create circular button for each days of the week. For this I used Raisedbutton and CircleBorder shape, but when I have more than 4 raisedbutton, I have an overflowed, as if there was a padding hidden in the raisedbutton...
new Row (
children: <Widget>[
RaisedButton(
hoverElevation:5,
textColor: Colors.black,
color: Colors.white,
child: Text(("Lu"), style: TextStyle(color: Colors.black, fontWeight: FontWeight.w600, fontSize: 15.0)),
onPressed: ()
{
},
shape: new CircleBorder(
)
),
RaisedButton(),
RaisedButton(),
RaisedButton(),
RaisedButton....
]
)

For one line you can use SingleChildScrollView widget for scrolling
SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: Row(children: <Widget>[
RaisedButton(
hoverElevation: 5,
textColor: Colors.black,
color: Colors.white,
child: Text(("Lu"),
style: TextStyle(
color: Colors.black,
fontWeight: FontWeight.w600,
fontSize: 15.0)),
onPressed: () {},
shape: new CircleBorder()),
RaisedButton(
hoverElevation: 5,
textColor: Colors.black,
color: Colors.white,
child: Text(("Lu"),
style: TextStyle(
color: Colors.black,
fontWeight: FontWeight.w600,
fontSize: 15.0)),
onPressed: () {},
shape: new CircleBorder()),
RaisedButton(),
RaisedButton(),
RaisedButton(),
RaisedButton(),
]),
)
or You just have to use Wrap widget for multi line
Wrap(
spacing: 2.0, // gap between adjacent chips
runSpacing: 2.0, // gap between lines
children: <Widget>[
RaisedButton(
hoverElevation: 5,
textColor: Colors.black,
color: Colors.white,
child: Text(("Lu"),
style: TextStyle(
color: Colors.black,
fontWeight: FontWeight.w600,
fontSize: 15.0)),
onPressed: () {},
shape: new CircleBorder()),
RaisedButton(
hoverElevation: 5,
textColor: Colors.black,
color: Colors.white,
child: Text(("Lu"),
style: TextStyle(
color: Colors.black,
fontWeight: FontWeight.w600,
fontSize: 15.0)),
onPressed: () {},
shape: new CircleBorder()),
RaisedButton(
hoverElevation: 5,
textColor: Colors.black,
color: Colors.white,
child: Text(("Lu"),
style: TextStyle(
color: Colors.black,
fontWeight: FontWeight.w600,
fontSize: 15.0)),
onPressed: () {},
shape: new CircleBorder()),
RaisedButton(),
RaisedButton(),
RaisedButton(),
RaisedButton(),
])

I found this solution
I can custom the padding with this solution
new Row (
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Material(
borderRadius: BorderRadius.circular(30.0),
shadowColor: Colors.white,
child: InkWell
(
onTap:() { setState(() {
change=1;
swiper1(); }
);
},
child: Padding(
padding: const EdgeInsets.all(12.0),
child : Text(("Lu"), style: TextStyle(color: Colors.black, fontWeight: FontWeight.w600, fontSize: 15.0)),
)
)
),
Material(
borderRadius: BorderRadius.circular(30.0),
shadowColor: Colors.white,
child: InkWell
(
onTap:() { setState(() {
change=2;
swiper1(); }
);
},
child: Padding(
padding: const EdgeInsets.all(12.0),
child : Text(("Ma"), style: TextStyle(color: Colors.black, fontWeight: FontWeight.w600, fontSize: 15.0)),
)
)
),
....

Related

How can I give my text a background color?

I want to give color to the text background like the picture below:
while mine is still like this:
And the code that I have written is like this:
Text(
'Last Activity',
style: TextStyle(
fontSize: 16,
color: ColorName.whitePrimary,
),
),
body: Center(
child: TextButton.icon(
style: TextButton.styleFrom(
textStyle: TextStyle(color: Colors.blue),
backgroundColor: Colors.white,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(6.0),
),
),
onPressed: () => {},
icon: Text('Last Activity'),
label: Icon(Icons.chevron_right),
),
),
Set the style parameter in your Text widget:
Text(
'Hello, World!',
style: TextStyle(fontSize: 32, backgroundColor: Colors.green),
);
See also
TextStyle (flutter.dev)
Try the following code:
Text(
'Last Activity',
style: TextStyle(
fontSize: 16,
color: ColorName.whitePrimary,
backgroundColor: Colors.indigo[400],
),
),
Refer below code hope its help to you, I have try 2 ways TextButton.icon and Row
1. Using TextButton Widget
TextButton.icon(
style: TextButton.styleFrom(
foregroundColor: Colors.white,
backgroundColor: const Color.fromRGBO(60, 75, 175, 1),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(6.0),
),
),
onPressed: () => {},
icon: const Text('Last Activity'),
label: const Icon(Icons.chevron_right),
),
Result Using TextButton.icon->
2. Using Row
GestureDetector(
onTap: () {},
child: Container(
height: 30,//change on your need
width: 120,//change on your need
padding: const EdgeInsets.all(5),
alignment: Alignment.center,
color: const Color.fromRGBO(60, 75, 175, 1),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: const [
Text(
'Last Activity',
style: TextStyle(
color: Colors.white,
),
),
Icon(
Icons.chevron_right,
color: Colors.white,
),
],
),
),
),
Result Using Row->
Try the following code:
Text(
'Last Activity',
style: TextStyle(
fontSize: 16,
color: ColorName.whitePrimary,
),
),

ripple effect in this container widget is not working

I am new to flutter and trying to apply the ripple effect on button press in this container widget through the documentation but unable to do
Padding(
padding: const EdgeInsets.symmetric(horizontal: 25.0),
child: GestureDetector(
onTap: signIn,
child: Container(
padding: EdgeInsets.all(20),
decoration: BoxDecoration(
color: Colors.deepPurple,
borderRadius: BorderRadius.circular(12)),
child: Center(
child: Text(
'Sign In',
style: TextStyle(
color: Colors.white,
fontSize: 18,
fontWeight: FontWeight.bold,
),
),
),
),
),
),
Inner container color is over the splash color. And to have splash effect use InkWell instead of GestureDetector
Padding(
padding: const EdgeInsets.symmetric(horizontal: 25.0),
child: Material(
color: Colors.deepPurple,
child: InkWell(
onTap: () {},
splashColor: Colors.red,
child: Center(
child: Text(
'Sign In',
style: TextStyle(
color: Colors.white,
fontSize: 18,
fontWeight: FontWeight.bold,
),
),
),
),
),
You can simply replace GestureDetector with InkWell widget as below.
InkWell(
onTap: signIn,
child: Container(
padding: EdgeInsets.all(20),
decoration: BoxDecoration(color: Colors.deepPurple, borderRadius: BorderRadius.circular(12)),
child: Center(
child: Text(
'Sign In',
style: TextStyle(
color: Colors.white,
fontSize: 18,
fontWeight: FontWeight.bold,
),
),
),
),
)
you can use InkWell and wrap it with Material with transparant color if your container has background color;
Material(
color: Colors.transparent,
child: InkWell(
splashColor: Colors.blue,
onTap: () {},
child: Container(
padding: EdgeInsets.all(20),
decoration: BoxDecoration(
color: Colors.deepPurple,
borderRadius: BorderRadius.circular(12)),
child: Center(
child: Text(
'Sign In',
style: TextStyle(
color: Colors.white,
fontSize: 18,
fontWeight: FontWeight.bold,
),
),
),
),
))
Padding(
padding: const EdgeInsets.symmetric(horizontal: 25.0),
child: Material(
borderRadius: BorderRadius.circular(12),
color: Colors.deepPurple,
child: InkWell(
splashColor: Colors.white60,
borderRadius: BorderRadius.circular(12),
onTap: (() {}),
child: Container(
padding: EdgeInsets.all(20),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(12)),
child: Center(
child: Text(
'Sign In',
style: TextStyle(
color: Colors.white,
fontSize: 18,
fontWeight: FontWeight.bold,
),
),
),
),
),
),
),

How to add icon from the assets/icons into my button components

this is my button component code :
Widget build(BuildContext context) {
return MaterialButton(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(40)),
side: BorderSide(color: kPrimaryColor)
),
padding: padding,
color: color,
minWidth: 280,
onPressed: press,
child: Text(
text,
style: TextStyle(
color: Colors.grey[900],
fontSize: 15,
),
),
);
}
Wrap your child with a Row and add the icon as the second element of your Row's children. It will turn out something like below:
child: Row(
children: [
Text(
text,
style: TextStyle(
color: Colors.grey[900],
fontSize: 15,
),
),
Image.asset('assets/icons/my_icon.png'),
],
),
You can use a TextButton.icon widget
And flip the label and icon (both accept a widget)
TextButton.icon(
icon: Text("MyText",
style: TextStyle(
fontSize: 11.0,
fontFamily: "Raleway"
),
),
label: Image.asset('assets/myImage.png', width: 20.0,height: 20.0,),
style: ButtonStyle(
// backgroundColor:
// MaterialStateProperty.all(Colors.green.shade200),
overlayColor: MaterialStateProperty.all(Colors.green),
side: MaterialStateProperty.resolveWith((states) {
return BorderSide(color: Colors.grey, width: 1);
})),
)
Inside the TextButton, I manage to add a row that contains icon and text
TextButton(
onPressed: (){},
child: Row(
mainAxisSize: MainAxisSize.min,
children: const [
Icon(
Icons.arrow_back_ios,
color: Themes.primaryColor,
),
Text(
'Back',
style: TextStyle(
fontSize: 17,
color: Themes.primaryColor,
),
),
],
),
),

Why it is not changing the heigth and width of the button

InkWell(
borderRadius: BorderRadius.all(Radius.circular(5)),
onTap: () {},
child: SizedBox(
height: 25,
width: screenWidth *65,
child: Container(
color: Colors.blueAccent,
child: Text(
'Confirm',
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 15,
color: Color(0xff000000),
fontWeight: FontWeight.w500),
),
),
),
),
Is this what you are looking for?
Container(
padding: EdgeInsets.all(6),
width: double.infinity,
child: FlatButton(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(5))
),
color: Colors.blueAccent,
onPressed: () => print('pressed'),
child: Text('Confirm',
style: TextStyle(
fontSize: 15,
color: Color(0xff000000),
fontWeight: FontWeight.w500
),
)
),
),
Remove SizedBox widget as it not of any issue in your current widget tree anyway as you are using container already
and use those height and width parameter inside container widget
try this
InkWell(
borderRadius: BorderRadius.all(Radius.circular(5)),
onTap: () {},
child: Container(
height: 25,
width: screenWidth *65,
color: Colors.blueAccent,
child: Text(
'Confirm',
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 15,
color: Color(0xff000000),
fontWeight: FontWeight.w500),
),
),
),

My screen is not jumping to the next screen as required

I am using RawMaterialButton and I need to switch screen when the button is pressed, but it is not switching?
Here is my code - first Screen:
Widget _buildListItem(String picture) {
return Row(
children: <Widget>[
Row(
children: <Widget>[
Container(
height: 100.0,
width: 130.0,
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage(picture),
fit: BoxFit.cover
),
borderRadius: BorderRadius.only(topRight: Radius.circular(10.0), bottomRight: Radius.circular(10.0))),
),
SizedBox(width: 10.0),
Container(
height: 120.0,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text('Maple Mustard Tempeh',
style: TextStyle(
fontSize: 15.0,
fontFamily: 'Montserrat',
fontWeight: FontWeight.bold
),
),
SizedBox(height: 5.0),
Text('Marinated kale, onion, tomato and roasted',
style: TextStyle(
fontSize: 11.0,
fontFamily: 'Montserrat',
fontWeight: FontWeight.bold,
color: Colors.grey
),
),
Text('garlic aioli on grilled spelt bread',
style: TextStyle(
fontSize: 11.0,
fontFamily: 'Montserrat',
fontWeight: FontWeight.bold,
color: Colors.grey
),
),
SizedBox(height: 10.0),
Row(
children: <Widget>[
Text('\u20B9 11.25',
style: TextStyle(
fontSize: 20.0,
fontFamily: 'Montserrat',
fontWeight: FontWeight.bold,
color: Colors.grey
),
),
SizedBox(width: 60.0,),
Cbutton(onPressed: ()=> item_details()),
],
),
],
),
),
],
),
],
);
}
RawMaterialButton
return new RawMaterialButton(
fillColor: Colors.green,
splashColor: Colors.greenAccent,
child: Padding(
padding: const EdgeInsets.symmetric(
horizontal: 20.0,
vertical: 8.0),
child: Row(
mainAxisSize: MainAxisSize.min,
children: const <Widget>[
Icon(
Icons.add,
color: Colors.white,),
SizedBox(width: 8.0,),
Text("Add", style: TextStyle(
color: Colors.white
),),
],
),
),
onPressed: onPressed,
shape: StadiumBorder(),
);
}
}
If you want to change screens, you can user Navigator.
onPressed: () {
Navigator.push( context, MaterialPageRoute(
builder: (context) => SecondScreen()
));
}