Overlap two buttons Flutter - flutter

I am new to flutter. I have created two raised buttons. Both are created as widgets which are then being called in the main Scaffold widget. I want them to overlap with each other. I am trying the stack widget but then one button goes missing. I have also tried padding and positioning but nothing works. I do not want to use toggle buttons as those are just placed next to each other and are not overlapped.
Code
Widget business(context, setState) {
return
Padding(
padding: const EdgeInsets.only(left: 12.0),
child: ClipRRect(
borderRadius: BorderRadius.circular(25.0),
child: SizedBox(
height: 60,
width: 60,
child: RaisedButton(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(25.0),
side: BorderSide(color: button2 ? primaryColor : Colors.white)
),
color: button1 ? primaryColor : Colors.white,
onPressed: () {
setState(() {
button1 = true;
button2 = false;
});
Fluttertoast.showToast(
msg:
"Business",
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.BOTTOM,
timeInSecForIosWeb: 4,
backgroundColor: primaryColor,
textColor: Colors.white,
fontSize: 16.0,
);
},
child: Icon(
MyFlutterApp.office,
color: button1 ? Colors.white : Colors.black,
),
),
),
),
);
}
else {
return Container();
}
Widget personal(context, setState) {
return
Padding(
padding: const EdgeInsets.only(left: 12.0),
child: ClipRRect(
borderRadius: BorderRadius.circular(25.0),
child: SizedBox(
height: 60,
width: 60,
child: RaisedButton(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(25.0),
side: BorderSide(color: button1 ? primaryColor : Colors.white)
),
color: button2 ? primaryColor : Colors.white,
onPressed: () {
setState(() {
button1 = false;
button2 = true;
});
Fluttertoast.showToast(
msg:
"Personal",
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.BOTTOM,
timeInSecForIosWeb: 4,
backgroundColor: primaryColor,
textColor: Colors.white,
fontSize: 16.0,
);
},
child: Icon(
MyFlutterApp.personal,
color: button2 ? Colors.white : Colors.black,
),
),
),
),
);
}
else {
return Container();
}

Based on Flutter Oficial Documentation, you can use the Stack widget to achieve this effect. Here is a quick tutorial about this widget.
Using RaisedButton, always remember to remove the elevation from the upper buttons, to not cause a black overlay impression.
Here is a example:
Stack(
children: <Widget>[
RaisedButton(
onPressed: () => {},
color: Colors.red,
child: Text('First'),
),
RaisedButton(
onPressed: () => {},
color: Colors.transparent,
elevation: 0,
child: Text('Second'),
),
],
)
Here is the result.

I have minimal reproduction code of stack in flutter which I can give you
Stack(
children: [
Icon(
Icons.shopping_cart,
),
Positioned(
right: 0,
top: 0,
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
color: Colors.red,
),
child: Padding(
padding: const EdgeInsets.all(2),
child: Text(
_bookModel.conutCart.toString(),
style: TextStyle(
color: Colors.white,
fontSize: 8.0,
),
),
),
),
),
],
),

Related

How to create button in flutter?

How do you create this button in this way? Need for my academic work. Please help me!!
enter image description here
ElevatedButton(
onPressed: () {
},
style: ElevatedButton.styleFrom(
foregroundColor: Colors.white,
backgroundColor: green,
shadowColor: green,
elevation: 3,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(32.0)),
minimumSize: const Size(100, 50),
),
child: const Padding(
padding: EdgeInsets.all(4.0),
child: Text(
"Arabic",
style: forteenWhite,
),
)),
Try this :
Container(
width: 300,
height: 60,
color: const Color(0xFF9c1f5d),
padding: EdgeInsets.all(10),
child:
ElevatedButton(
onPressed: () {},
child: const Text(
'Register your account today !',
style: TextStyle(
color: Colors.black
)
),
style: ElevatedButton.styleFrom(
primary: const Color(0xFFcc4e8c),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20),
),
),
),
),
Container(
padding: Padding.Edgeall(10.0),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10.0),
color: Colors.white,
),
height: 55,
child: Text("This is button")
),
And to use onClick wrap the Text or container with InkWell.

Animate the button into progressindicator

I have a button in on clicking the button I show the progress Indicator, what I need is animate the button in progress indicator something like the transformation from button to progress indicator
showProgressIndicator ? FloatingActionButton(
elevation: 5.0,
child: CircularProgressIndicator(),
backgroundColor: Colors.white,
onPressed: (){}
) : Padding(
padding: const EdgeInsets.only(left: 20.0, right: 20.0),
child: ButtonTheme(
height: 40.0,
child: RaisedButton(
color: Color(0xFFFD6600),
child: Text("Login", style: TextStyle(fontSize: 16.0),),
textColor: Colors.white,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(30.0),
),
onPressed: () {
setState(() {
showProgressIndicator = true;
});
},
),
),
),
Maybe use AnimatedContainer like this:
InkWell(
borderRadius: BorderRadius.circular(20),
onTap: isLoading ? null : () => buttonPressed(),
child: AnimatedContainer(
curve: Curves.easeInOutCubic,
padding: (isLoading)
? EdgeInsets.fromLTRB(10, 10, 10, 10)
: EdgeInsets.fromLTRB(40, 10, 40, 10),
decoration: BoxDecoration(
color: Colors.blueAccent,
borderRadius: BorderRadius.circular(20),
),
duration: Duration(milliseconds: 400),
child: isLoading
? CircularProgressIndicator(
valueColor: new AlwaysStoppedAnimation<Color>(
Colors.white),
)
: Text(
"LOGIN",
style: TextStyle(
fontSize: 18,
color: Colors.white,
),
)),
),
You can use something like this, use a variable to keep button status.
return _isLoading
? Center(
child: CircularProgressIndicator(),
)
: RaisedButton(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(30)),
color: .green,
child: Text(
'Continue',
style: TextStyle(
fontSize: 17.0,
fontFamily: 'SFUIDisplay-Bold',
color: .white),
),
onPressed: () => _submitForm(),
);

How to set rounded border to a MaterialButton on Flutter?

I'm trying set rounded border to my MaterialButton, to do it I'm setting a RoundedRectangleBorder to shape attribute's MaterialButton, the problem is that it's not have effect.
Code:
Widget _showNeedHelpButton() {
return new Padding(
padding: EdgeInsets.fromLTRB(0.0, 5.0, 0.0, 0.0),
child: new MaterialButton(
shape: RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(20.0))),
elevation: 5.0,
minWidth: 200.0,
height: 35,
color: Color(0xFF801E48),
child: new Text('Preciso de ajuda',
style: new TextStyle(fontSize: 16.0, color: Colors.white)),
onPressed: () {
setState(() {
_isNeedHelp = true;
});
},
),
);
}
Result:
If you need to use MaterialButton() - You need to Warp the button with Material Widget, to get the desired behavior.
Widget _showNeedHelpButton() {
return Padding(
padding: EdgeInsets.fromLTRB(0.0, 5.0, 0.0, 0.0),
child: Material( //Wrap with Material
shape: RoundedRectangleBorder(borderRadius:BorderRadius.circular(22.0) ),
elevation: 18.0,
color: Color(0xFF801E48),
clipBehavior: Clip.antiAlias, // Add This
child: MaterialButton(
minWidth: 200.0,
height: 35,
color: Color(0xFF801E48),
child: new Text('Preciso de ajuda',
style: new TextStyle(fontSize: 16.0, color: Colors.white)),
onPressed: () {
// setState(() {
// _isNeedHelp = true;
// });
},
),
),
);
}
Output:
UPDATE:
minWidth: 200.0,
height: 95,
MaterialButton(
child: Text('My Button'),
height: 40,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10.0),
),
)
RoundedRectangleBorder
will help you https://api.flutter.dev/flutter/painting/RoundedRectangleBorder-class.html
Have you tried wrapping it within a ClipRRect() ?
ClipRRect(
borderRadius: BorderRadius.all(Radius.circular(20.0)),
child: MaterialButton(...),
),
You can find the documentation here: ClipRRect()
You should set the shape for MaterialButton and borderRadius for Material to make it round even when animation tab:
Material(
elevation: 10.0,
borderRadius: BorderRadius.circular(30.0),//12
color: Colors.transparent,//Colors.cyan.withOpacity(0.5),
child: MaterialButton(
minWidth: MediaQuery.of(context).size.width,
color: Colors.cyan.withOpacity(0.7),
shape: RoundedRectangleBorder(borderRadius:BorderRadius.circular(30.0) ),
splashColor: Colors.cyan,
onPressed: () async {},
child: Text('Login',
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 18.0,
color: Colors.black,
fontWeight: FontWeight.w400,
//fontFamily: lang.font
)),
),
);

How to implement a bottom navigation drawer in Flutter

I'm trying to implement a bottom navigation drawer, similar to the one used in the Reply Material Study, that is an extension of the bottom app bar, and opened and closed via an icon button in the bottom app bar.
I've tried bottom sheets, but that replaces, or hovers on top of, the bottom app bar. I want it to look like the one in the screenshot where the bottom app bar stays on the screen and the bottom navigation drawer slides up when the "menu" button is tapped.
The Material Design site shows this as a component, but doesn't link off to anywhere showing how to implement it in Flutter.
I quickly made it, but you are going to have to implement active page text/icon colors to the listview. Also, the full code is here if you want to copy from the gist.
class ScreenOne extends StatefulWidget {
#override
_ScreenOneState createState() => _ScreenOneState();
}
class _ScreenOneState extends State<ScreenOne> {
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Reply demo"),
),
bottomNavigationBar: BottomAppBar(
elevation: 0,
color: Color(0xff344955),
child: Container(
padding: EdgeInsets.symmetric(horizontal: 10.0),
height: 56.0,
child: Row(children: <Widget>[
IconButton(
onPressed: showMenu,
icon: Icon(Icons.menu),
color: Colors.white,
),
Spacer(),
IconButton(
onPressed: () {},
icon: Icon(Icons.add),
color: Colors.white,
)
]),
),
),
);
}
showMenu() {
showModalBottomSheet(
context: context,
builder: (BuildContext context) {
return Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(16.0),
topRight: Radius.circular(16.0),
),
color: Color(0xff232f34),
),
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.end,
children: <Widget>[
Container(
height: 36,
),
SizedBox(
height: (56 * 6).toDouble(),
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(16.0),
topRight: Radius.circular(16.0),
),
color: Color(0xff344955),
),
child: Stack(
alignment: Alignment(0, 0),
overflow: Overflow.visible,
children: <Widget>[
Positioned(
top: -36,
child: Container(
decoration: BoxDecoration(
borderRadius:
BorderRadius.all(Radius.circular(50)),
border: Border.all(
color: Color(0xff232f34), width: 10)),
child: Center(
child: ClipOval(
child: Image.network(
"https://i.stack.imgur.com/S11YG.jpg?s=64&g=1",
fit: BoxFit.cover,
height: 36,
width: 36,
),
),
),
),
),
Positioned(
child: ListView(
physics: NeverScrollableScrollPhysics(),
children: <Widget>[
ListTile(
title: Text(
"Inbox",
style: TextStyle(color: Colors.white),
),
leading: Icon(
Icons.inbox,
color: Colors.white,
),
onTap: () {},
),
ListTile(
title: Text(
"Starred",
style: TextStyle(color: Colors.white),
),
leading: Icon(
Icons.star_border,
color: Colors.white,
),
onTap: () {},
),
ListTile(
title: Text(
"Sent",
style: TextStyle(color: Colors.white),
),
leading: Icon(
Icons.send,
color: Colors.white,
),
onTap: () {},
),
ListTile(
title: Text(
"Trash",
style: TextStyle(color: Colors.white),
),
leading: Icon(
Icons.delete_outline,
color: Colors.white,
),
onTap: () {},
),
ListTile(
title: Text(
"Spam",
style: TextStyle(color: Colors.white),
),
leading: Icon(
Icons.error,
color: Colors.white,
),
onTap: () {},
),
ListTile(
title: Text(
"Drafts",
style: TextStyle(color: Colors.white),
),
leading: Icon(
Icons.mail_outline,
color: Colors.white,
),
onTap: () {},
),
],
),
)
],
))),
Container(
height: 56,
color: Color(0xff4a6572),
)
],
),
);
});
}
}
You can use BottomSheet . (Thanks to westdabestdb)
Working on flutter_gallery demo app:
class ModalBottomSheetDemo extends StatelessWidget {
static const String routeName = '/material/modal-bottom-sheet';
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Modal bottom sheet'),
actions: <Widget>[MaterialDemoDocumentationButton(routeName)],
),
body: Center(
child: RaisedButton(
child: const Text('SHOW BOTTOM SHEET'),
onPressed: () {
showModalBottomSheet<void>(context: context, builder: (BuildContext context) {
return Container(
child: Padding(
padding: const EdgeInsets.all(32.0),
child: Text('This is the modal bottom sheet. Tap anywhere to dismiss.',
textAlign: TextAlign.center,
style: TextStyle(
color: Theme.of(context).accentColor,
fontSize: 24.0
)
)
)
);
});
}
)
)
);
}
}
Building up on westdabestdb's answer and this article:
If you want a bottom navigation drawer that is not blocking, with rounded corners and that is not depending on a black background, try this:
class GoogleMapsHomeUI extends StatelessWidget {
final GlobalKey<ScaffoldState> scaffoldKey = GlobalKey<ScaffoldState>();
#override
Widget build(BuildContext context) {
showBottomDrawer();
return Scaffold(
key: scaffoldKey, // use the key to reference the Scaffold from outside
... the rest of your background Scaffold
);
}
void showBottomDrawer() {
// the next line is needed, because the Scaffold needs to be finished before this function continues.
WidgetsBinding.instance.addPostFrameCallback((_) {
PersistentBottomSheetController? bottomSheetController = scaffoldKey.currentState?.showBottomSheet((BuildContext context) {
return Container(
height: 300,
decoration: BoxDecoration(
borderRadius: BorderRadius.only( // makes the round corners
topLeft: Radius.circular(20.0),
topRight: Radius.circular(20.0),
),
color: Color(0xff232f34),
),
child: Center(
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.end,
children: <Widget>[
Container(
height: 36,
),
SizedBox(
height: (56 * 6).toDouble(),
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(16.0),
topRight: Radius.circular(16.0),
),
color: Color(0xff344955),
),
child: Stack(
alignment: Alignment(0, 0),
children: <Widget>[
Positioned(
top: -36,
child: Container(
decoration: BoxDecoration(
borderRadius:
BorderRadius.all(Radius.circular(50)),
border: Border.all(
color: Color(0xff232f34), width: 10)),
child: Center(
child: ClipOval(
child: Image.network(
"https://i.stack.imgur.com/S11YG.jpg?s=64&g=1",
fit: BoxFit.cover,
height: 36,
width: 36,
),
),
),
),
),
Positioned(
child: ListView(
physics: NeverScrollableScrollPhysics(),
children: <Widget>[
ListTile(
title: Text(
"Inbox",
style: TextStyle(color: Colors.white),
),
leading: Icon(
Icons.inbox,
color: Colors.white,
),
onTap: () {},
),
ListTile(
title: Text(
"Starred",
style: TextStyle(color: Colors.white),
),
leading: Icon(
Icons.star_border,
color: Colors.white,
),
onTap: () {},
),
ListTile(
title: Text(
"Sent",
style: TextStyle(color: Colors.white),
),
leading: Icon(
Icons.send,
color: Colors.white,
),
onTap: () {},
),
ListTile(
title: Text(
"Trash",
style: TextStyle(color: Colors.white),
),
leading: Icon(
Icons.delete_outline,
color: Colors.white,
),
onTap: () {},
),
ListTile(
title: Text(
"Spam",
style: TextStyle(color: Colors.white),
),
leading: Icon(
Icons.error,
color: Colors.white,
),
onTap: () {},
),
ListTile(
title: Text(
"Drafts",
style: TextStyle(color: Colors.white),
),
leading: Icon(
Icons.mail_outline,
color: Colors.white,
),
onTap: () {},
),
],
),
)
],
))),
Container(
height: 56,
color: Color(0xff4a6572),
)
],
),
),
),
); // Container
},
backgroundColor: Colors.black,
elevation: 5,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.only(topLeft: Radius.circular(15.0), topRight: Radius.circular(15.0)),
), clipBehavior: null,
enableDrag: true,
);
result (I'm not finished with the background yet, but you can interact with the background, while the drawer is open):

Create a rounded button / button with border-radius in Flutter

I'm currently developing an Android app in Flutter. How can I add a rounded button?
1. Solution Summary
FlatButton and RaisedButton are deprecated.
So, you can use shape which placed in the style property, for TextButton and ElevatedButton.
There are some changes since Flutter 2.0:
style: the property type has changed to ButtonStyle
shape: the property type has changed to MaterialStateProperty<T>
2. Rounded Button
Inside the style property exists the shape property:
style: ButtonStyle(
shape: MaterialStateProperty.all<RoundedRectangleBorder>(
RoundedRectangleBorder(
borderRadius: BorderRadius.circular(18.0),
side: BorderSide(color: Colors.red)
)
)
)
Square Button
For a square button you can use ElevatedButton or otherwise add:
style: ButtonStyle(
shape: MaterialStateProperty.all<RoundedRectangleBorder>(
RoundedRectangleBorder(
borderRadius: BorderRadius.zero,
side: BorderSide(color: Colors.red)
)
)
)
Complete Example
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
TextButton(
child: Text(
"Add to cart".toUpperCase(),
style: TextStyle(fontSize: 14)
),
style: ButtonStyle(
padding: MaterialStateProperty.all<EdgeInsets>(EdgeInsets.all(15)),
foregroundColor: MaterialStateProperty.all<Color>(Colors.red),
shape: MaterialStateProperty.all<RoundedRectangleBorder>(
RoundedRectangleBorder(
borderRadius: BorderRadius.circular(18.0),
side: BorderSide(color: Colors.red)
)
)
),
onPressed: () => null
),
SizedBox(width: 10),
ElevatedButton(
child: Text(
"Buy now".toUpperCase(),
style: TextStyle(fontSize: 14)
),
style: ButtonStyle(
foregroundColor: MaterialStateProperty.all<Color>(Colors.white),
backgroundColor: MaterialStateProperty.all<Color>(Colors.red),
shape: MaterialStateProperty.all<RoundedRectangleBorder>(
RoundedRectangleBorder(
borderRadius: BorderRadius.zero,
side: BorderSide(color: Colors.red)
)
)
),
onPressed: () => null
)
]
)
Update
Since the left-sided buttons are now deprecated, use the right-sided ones.
Deprecated --> Recommended
RaisedButton --> ElevatedButton
OutlineButton --> OutlinedButton
FlatButton --> TextButton
ElevatedButton
Using StadiumBorder
ElevatedButton(
onPressed: () {},
child: Text('Button'),
style: ElevatedButton.styleFrom(shape: StadiumBorder()),
)
Using RoundedRectangleBorder
ElevatedButton(
onPressed: () {},
child: Text('Button'),
style: ElevatedButton.styleFrom(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12), // <-- Radius
),
),
)
Using CircleBorder
ElevatedButton(
onPressed: () {},
child: Text('Button'),
style: ElevatedButton.styleFrom(
shape: CircleBorder(),
padding: EdgeInsets.all(24),
),
)
Using BeveledRectangleBorder
ElevatedButton(
onPressed: () {},
child: Text('Button'),
style: ElevatedButton.styleFrom(
shape: BeveledRectangleBorder(
borderRadius: BorderRadius.circular(12)
),
),
)
OutlinedButton
Using StadiumBorder
OutlinedButton(
onPressed: () {},
child: Text('Button'),
style: OutlinedButton.styleFrom(
shape: StadiumBorder(),
),
)
Using RoundedRectangleBorder
OutlinedButton(
onPressed: () {},
child: Text('Button'),
style: OutlinedButton.styleFrom(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
),
),
)
Using CircleBorder:
OutlinedButton(
onPressed: () {},
child: Text('Button'),
style: OutlinedButton.styleFrom(
shape: CircleBorder(),
padding: EdgeInsets.all(24),
),
)
Using BeveledRectangleBorder
OutlinedButton(
onPressed: () {},
child: Text('Button'),
style: OutlinedButton.styleFrom(
shape: BeveledRectangleBorder(
borderRadius: BorderRadius.circular(12),
),
),
)
TextButton
TextButton also works similar to ElevatedButton and OutlinedButton, however, you can only see the shapes when the button is pressed.
You can use the ElevatedButton Widget. The elevated button widget has a shape property which you can use as shown in the below snippet.
ElevatedButton(
style: ButtonStyle(
shape: MaterialStateProperty.all<RoundedRectangleBorder>(
RoundedRectangleBorder(
borderRadius: BorderRadius.circular(18.0),
side: BorderSide(
color: Colors.teal,
width: 2.0,
),
),
),
),
child: Text('Submit'),
onPressed: () {},
),
Since September 2020, Flutter 1.22.0:
Both "RaisedButton" and "FlatButton" are deprecated.
The most up-to-date solution is to use new buttons:
1. ElevatedButton:
Code:
ElevatedButton(
child: Text("ElevatedButton"),
onPressed: () => print("it's pressed"),
style: ElevatedButton.styleFrom(
primary: Colors.red,
onPrimary: Colors.white,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(32.0),
),
),
)
Don't forget, there's also an .icon constructor to add an icon easily:
ElevatedButton.icon(
icon: Icon(Icons.thumb_up),
label: Text("Like"),
onPressed: () => print("it's pressed"),
style: ElevatedButton.styleFrom(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(32.0),
),
),
)
2. OutlinedButton:
Code:
OutlinedButton.icon(
icon: Icon(Icons.star_outline),
label: Text("OutlinedButton"),
onPressed: () => print("it's pressed"),
style: ElevatedButton.styleFrom(
side: BorderSide(width: 2.0, color: Colors.blue),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(32.0),
),
),
)
3. TextButton:
You can always use TextButton if you don't want an outline or color fill.
You can simply use RaisedButton
Padding(
padding: EdgeInsets.only(left: 150.0, right: 0.0),
child: RaisedButton(
textColor: Colors.white,
color: Colors.black,
child: Text("Search"),
onPressed: () {},
shape: new RoundedRectangleBorder(
borderRadius: new BorderRadius.circular(30.0),
),
),
)
Output:
More info: RSCoder
You can simply use RaisedButton or you can use InkWell to get a custom button and also properties like onDoubleTap, onLongPress, etc.:
new InkWell(
onTap: () => print('hello'),
child: new Container(
//width: 100.0,
height: 50.0,
decoration: new BoxDecoration(
color: Colors.blueAccent,
border: new Border.all(color: Colors.white, width: 2.0),
borderRadius: new BorderRadius.circular(10.0),
),
child: new Center(child: new Text('Click Me', style: new TextStyle(fontSize: 18.0, color: Colors.white),),),
),
),
If you want to use the splashColor and highlightColor properties in the InkWell widget, use the Material widget as the parent of the InkWell widget instead of decorating the container (deleting the decoration property). Read about why here.
Different ways to create a rounded button are as follows:
ElevatedButton with ElevatedButton.styleFrom
ElevatedButton(
style: ElevatedButton.styleFrom(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(30.0),
),
),
onPressed: () {},
child:
Text("Buy now".toUpperCase(), style: TextStyle(fontSize: 14)),
),
ElevatedButton with ButtonStyle
ElevatedButton(
style: ButtonStyle(
shape: MaterialStateProperty.all<RoundedRectangleBorder>(
RoundedRectangleBorder(
borderRadius: BorderRadius.circular(50.0),
))),
onPressed: () {},
child: Text("Submit".toUpperCase()),
),
A practical demonstration of a round button can be found in the below Dartpad link:
Rounded Button Demo Examples on DartPad
You can use the below code to make a rounded button with a gradient color.
Container(
width: 130.0,
height: 43.0,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(30.0),
gradient: LinearGradient(
// Where the linear gradient begins and ends
begin: Alignment.topRight,
end: Alignment.bottomLeft,
// Add one stop for each color. Stops should increase from 0 to 1
stops: [0.1, 0.9],
colors: [
// Colors are easy thanks to Flutter's Colors class.
Color(0xff1d83ab),
Color(0xff0cbab8),
],
),
),
child: FlatButton(
child: Text(
'Sign In',
style: TextStyle(
fontSize: 16.0,
fontFamily: 'Righteous',
fontWeight: FontWeight.w600,
),
),
textColor: Colors.white,
color: Colors.transparent,
shape:
RoundedRectangleBorder(borderRadius: BorderRadius.circular(30.0)),
onPressed: () {
},
),
);
Use TextButton instead.
Buttons like the FlatButton, RaisedButton and OutlineButton has been said to be deprecated since October 2020. This is one of the Flutter development team's effort to simplify and make the Flutter API consistent, you can customize its style by using style property.
TextButton(
child: Padding(
padding: const EdgeInsets.only(left: 10.0, right: 10.0),
child: Text('Text here',
style: TextStyle(
color: Colors.teal,
fontSize: 14,
fontWeight: FontWeight.w500)),
),
style: TextButton.styleFrom(
primary: Colors.teal,
onSurface: Colors.yellow,
side: BorderSide(color: Colors.teal, width: 2),
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(25))),
),
onPressed: () {
print('Pressed');
},
),
you can use this code:
ElevatedButton(
onPressed: () {},
style: ElevatedButton.styleFrom(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(borderRadius))),
),
child: Text("ok"),
)
To use any shape in your button, make sure you perform all the code inside the Button widget:
**shape: RoundedRectangleBorder(
borderRadius: new BorderRadius.circular(18.0),
side: BorderSide(color: Colors.red) ),**
If you want make it is square, use BorderRadius.circular(0.0) It automatically makes it into a square.
The button is like this:
Here is the all source code for the give UI screen:
Scaffold(
backgroundColor: Color(0xFF8E44AD),
body: new Center(
child: Column(
children: <Widget>[
Container(
margin: EdgeInsets.fromLTRB(90, 10, 20, 0),
padding: new EdgeInsets.only(top: 92.0),
child: Text(
"Currency Converter",
style: TextStyle(
fontSize: 48,
fontWeight: FontWeight.bold,
color: Colors.white,
),
),
),
Container(
margin: EdgeInsets.only(),
padding: EdgeInsets.all(25),
child: TextFormField(
decoration: new InputDecoration(
filled: true,
fillColor: Colors.white,
labelText: "Amount",
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
),
),
),
),
Container(
padding: EdgeInsets.all(25),
child: TextFormField(
decoration: new InputDecoration(
filled: true,
fillColor: Colors.white,
labelText: "From",
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
),
),
),
),
Container(
padding: EdgeInsets.all(25),
child: TextFormField(
decoration: new InputDecoration(
filled: true,
fillColor: Colors.white,
labelText: "To",
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
)),
),
),
SizedBox(height: 20.0),
MaterialButton(
height: 58,
minWidth: 340,
shape: RoundedRectangleBorder(
borderRadius: new BorderRadius.circular(12)),
onPressed: () {},
child: Text(
"CONVERT",
style: TextStyle(
fontSize: 24,
color: Colors.black,
),
),
color: Color(0xFFF7CA18),
),
],
),
),
),
);
You can use this code for a transparent rounded button by passing a transparent color to the color property inside BoxDecoration.
eg. color: Colors.transparent.
Also, take note that this button makes use of only the Container and GestureDetector widgets.
Container(
height: 50.0,
child: GestureDetector(
onTap: () {},
child: Container(
decoration: BoxDecoration(
border: Border.all(
color: Color(0xFFF05A22),
style: BorderStyle.solid,
width: 1.0,
),
color: Colors.transparent,
borderRadius: BorderRadius.circular(30.0),
),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Center(
child: Text(
"BUTTON",
style: TextStyle(
color: Color(0xFFF05A22),
fontFamily: 'Montserrat',
fontSize: 16,
fontWeight: FontWeight.w600,
letterSpacing: 1,
),
),
)
],
),
),
),
)
In the new update flutter 3.0 flutter uses Material 3 guidelines.
According to which the default border of buttons are rounded.
Default Button
ElevatedButton(
onPressed: () {}, child: const Text("Default Button ")),
Button with Border Radius Zero
ElevatedButton(
style: ElevatedButton.styleFrom(
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.zero)),
onPressed: () {},
child: const Text("Border Radius Zero ")),
Button with custom border radius
ElevatedButton(
style: ElevatedButton.styleFrom(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(50))),
onPressed: () {},
child: const Text("Border Radius Custom ")),
Note: You can use the same logic for FilledButton, TextButton and the like.
Refer https://m3.material.io/components/all-buttons for button style.
If anybody is looking for complete circular button then I achieved it this way:
Center(
child: SizedBox.fromSize(
size: Size(80, 80), // Button width and height
child: ClipOval(
child: Material(
color: Colors.pink[300], // Button color
child: InkWell(
splashColor: Colors.yellow, // splash color
onTap: () {}, // Button pressed
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Icon(Icons.linked_camera), // Icon
Text("Picture"), // Text
],
),
),
),
),
),
)
After the Null safety, use ElevatedButton not RaisedButton because RaisedButton is depreciated as the docs says.
child: ElevatedButton(
onPressed: () {},
child: const Text('Add item to the list'),
style: ButtonStyle(
backgroundColor:
MaterialStateProperty.all<Color>(Common.buttonColor),
shape: MaterialStateProperty.all<RoundedRectangleBorder>(
RoundedRectangleBorder(
borderRadius: BorderRadius.circular(18.0),
),
),
),
),
RaisedButton(
child: Text("Button"),
onPressed: (){},
shape: RoundedRectangleBorder(borderRadius: new BorderRadius.circular(30.0),
side: BorderSide(color: Colors.red))
)
One of the simplest ways to create a rounded button is to use a FlatButton and then specify the roundness by setting its shape property. Follow the code below
FlatButton(
padding: EdgeInsets.all(30.0),
color: Colors.black,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20.0)),
child: child: Text(
"Button",
style: TextStyle(color: Colors.white),
),
onPressed: () {
print('Button pressed');
},
),
Note: In order to change the roundness adjust the value inside BorderRadius.circular()
Here is the code for your problem. You just have to take a simple container with a border radius in boxdecoration.
new Container(
alignment: Alignment.center,
decoration: BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(15.0)),
color: Colors.blue,
),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Padding(
padding: const EdgeInsets.all(10.0),
child: new Text(
"Next",
style: new TextStyle(
fontWeight: FontWeight.w500,
color: Colors.white,
fontSize: 15.0,
),
),
),
],
),
),
You can also use ButtonTheme():
Here is example code -
ButtonTheme(
minWidth: 200.0,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(18.0),
side: BorderSide(color: Colors.green)),
child: RaisedButton(
elevation: 5.0,
hoverColor: Colors.green,
color: Colors.amber,
child: Text(
"Place Order",
style: TextStyle(
color: Colors.white, fontWeight: FontWeight.bold),
),
onPressed: () {},
),
),
Now we have an Icon button to achieve a rounded button click and overlay. However, the background color is not yet available, but the same can be achieved by the Circle avatar widget as follows:
CircleAvatar(
backgroundColor: const Color(0xffF4F3FA),
child: IconButton(
onPressed: () => FlushbarHelper.createInformation(
message: 'Work in progress...')
.show(context),
icon: Icon(Icons.more_vert),
),
),
New Elevate Button
Style
customElevatedButton({radius, color}) => ElevatedButton.styleFrom(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(radius == null ? 100 : radius),
),
primary: color,
);
Icon
Widget saveIcon() => iconsStyle1(
Icons.save,
);
// Common icon style
iconsStyle1(icon) => Icon(
icon,
color: white,
size: 15,
);
Button use
ElevatedButton.icon(
icon: saveIcon(),
style:
customElevatedButton(color: Colors.green[700]),
label: Text('Save',
style: TextStyle(color: Colors.white)),
onPressed: () {
},
),
If you want to Use MaterialButton then,
=======================================
You can add RoundedRectangleBorder Given in Shape Like this,
MaterialButton(
onPressed: () {},
minWidth: MediaQuery.of(context).size.width * 0.4,
height: 34,
color: colorWhite,
highlightColor: colorSplash,
splashColor: colorSplash,
visualDensity: VisualDensity.compact,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(4),
side: BorderSide(
color: colorGrey,
width: 0.6,
),
),
child: Text("CANCEL"),
),
You can create a custom view and put it inside a GestureDetector for it to behave like a button. The benefit is that you can provide endless types of custom decoration (including making it round with specified radius) to the container.
Here is another solution:
Container(
height: MediaQuery.of(context).size.height * 0.10,
width: MediaQuery.of(context).size.width,
child: ButtonTheme(
minWidth: MediaQuery.of(context).size.width * 0.75,
child: RaisedButton(
shape: RoundedRectangleBorder(
borderRadius: new BorderRadius.circular(25.0),
side: BorderSide(color: Colors.blue)),
onPressed: () async {
// Do something
},
color: Colors.red[900],
textColor: Colors.white,
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Text("Button Text,
style: TextStyle(fontSize: 24)),
),
),
),
),
Another cool solution that works in 2021:
TextButton(
child: Padding(
padding: const EdgeInsets.all(5.0),
child: Text('Follow Us'.toUpperCase()),
),
style: TextButton.styleFrom(
backgroundColor: Colors.amber,
shadowColor: Colors.red,
elevation: 2,
textStyle: TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(5.0),)
),
onPressed: () {
print('Pressed');
},
),
With Flutter version 2, try this
ElevatedButton(
style: ButtonStyle(
shape: MaterialStateProperty.all<OutlinedBorder>(
RoundedRectangleBorder(
side:
BorderSide(width: 1.0, color: Colors.red,
borderRadius:
BorderRadius.circular(5.0),),),
backgroundColor: MaterialStateProperty.all<Color>(Colors.red),
foregroundColor: MaterialStateProperty.all<Color>(Colors.green),
elevation:
MaterialStateProperty.all<double>(8.0),
padding: MaterialStateProperty.all<EdgeInsetsGeometry>(
const EdgeInsets.symmetric(
horizontal: 15.0,
vertical: 10.0),),),
onPressed: (){},
child: Text('Button'),)
Container(
width: yourWidth,
height: yourHeight ,
decoration: BoxDecoration(
borderRadius: radius,
gradient: yourGradient,
border: yourBorder),
child: FlatButton(
onPressed: {} (),
shape: RoundedRectangleBorder(borderRadius: radius),
.......
and use the same radius.
In Flutter, the Container() widget is used for styling your widget. Using the Container() widget, you can set a border or rounded corner of any widget.
If you want to set any type of styling and set the decoration, put that widget into the Container() widget. That provides many properties to the decoration.
Container(
width: 100,
padding: EdgeInsets.all(10),
alignment: Alignment.center,
decoration: BoxDecoration(
color: Colors.blueAccent,
borderRadius: BorderRadius.circular(30)), // Make rounded corner
child: Text("Click"),
)
addButton() {
return Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Padding(
padding: const EdgeInsets.symmetric(vertical: 10.0),
child: SizedBox(
height: 45,
width: 200,
child: ElevatedButton.icon(
onPressed: () async {},
style: ButtonStyle(
shape: MaterialStateProperty.all<RoundedRectangleBorder>(
RoundedRectangleBorder(
borderRadius: BorderRadius.circular(30.0),
)),
elevation: MaterialStateProperty.all(1),
backgroundColor: MaterialStateProperty.all(Colors.blue),
),
icon: Icon(Icons.add, size: 18),
label: Text("Add question"),
),
),
),
],
);
}
you can use this style for your elevatedButton to make it circular
style: ButtonStyle(
elevation: MaterialStateProperty.all(8.0),
backgroundColor:
MaterialStateProperty.all(Constants().orangeColor),
textStyle: MaterialStateProperty.all(
TextStyle(
fontSize: 16.0,
),
),
shape: MaterialStateProperty.all<CircleBorder>(
CircleBorder(),
),
shadowColor: MaterialStateProperty.all(Constants().orangeColor),
),