![]() |
VOOZH | about |
Outlined Widgets are material design components that are used to give outlines to buttons. It is in no way different from text buttons except for the special feature of the border this class provides. These contain nonprimary actions for the apps. It is introduced in version 1.22 of flutter. Outlined buttons have child as their label with text widgets or icons widgets as the child widget to this parent class. You can set the styling of outlined buttons using ButtonStyle. To use this class you need to import the material package i.e. "package/flutter/material.dart".
const OutlinedButton({
Key key,
@required VoidCallback onPressed,
VoidCallback onLongPress,
ButtonStyle style,
FocusNode focusNode,
bool autofocus = false,
Clip clipBehavior = Clip.none,
@required Widget child,
})1. child: This represents the button's label.
OutlinedButton(
child: Text('Raised Button'),
),
2. onPressed: This represents the action to be executed when the button is tapped
onPressed: () => Navigator.of(context) .push(MaterialPageRoute(builder: (context) => const NewScreen())),
Button is styled by giving OutlinedButton.styleFrom constructor to the style parameter.
OutlinedButton(
child: Text('Outlined Button'),
style: OutlinedButton.styleFrom(
primary: Colors.green,
),
onPressed: () => Navigator.of(context)
.push(MaterialPageRoute(builder: (context) => const NewScreen())),
),The coloring requires two parameters,
1. backgroundcolor
OutlinedButton(
child: Text('Outlined Button'),
style: OutlinedButton.styleFrom(
backgroundColor: Colors.green,
),
onPressed: () => Navigator.of(context)
.push(MaterialPageRoute(builder: (context) => const NewScreen())),
),
2. primary
OutlinedButton(
child: Text('Outlined Button'),
style: OutlinedButton.styleFrom(
backgroundColor: Colors.green,
primary: Colors.white,
),
onPressed: () => Navigator.of(context)
.push(MaterialPageRoute(builder: (context) => const NewScreen())),
),The shape of the border can be adjusted by the use of OutlinedBorder constructor as a parameter to the style with the border radius of your choice.
OutlinedButton(
child: Text('Outlined Button'),
style: OutlinedButton.styleFrom(
primary: Colors.black,
textStyle: TextStyle(fontSize: 15, fontStyle: FontStyle.italic),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(10)))),
onPressed: () => Navigator.of(context)
.push(MaterialPageRoute(builder: (context) => const NewScreen())),
),This can be done by passing textstyle to the TextStyle constructor of the outlined button
OutlinedButton(
child: Text('Outlined Button'),
style: OutlinedButton.styleFrom(
backgroundColor: Colors.green,
primary: Colors.white,
textStyle: TextStyle(fontSize: 15, fontStyle: FontStyle.italic),
),
onPressed: () => Navigator.of(context)
.push(MaterialPageRoute(builder: (context) => const NewScreen())),
),Let's understand outlined button and its properties with the help of an example