Added docs for the Action button, refactored to extract the button body into a method
This commit is contained in:
parent
b6e74cceb3
commit
578c6dd57f
1 changed files with 42 additions and 20 deletions
|
|
@ -1,14 +1,31 @@
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
class ActionButton extends StatelessWidget {
|
class ActionButton extends StatelessWidget {
|
||||||
|
/// Function to be called when the button is pressed
|
||||||
final VoidCallback onPressed;
|
final VoidCallback onPressed;
|
||||||
|
|
||||||
|
/// Background color of the button.
|
||||||
final Color color;
|
final Color color;
|
||||||
|
|
||||||
|
/// Text and icon color.
|
||||||
final Color textColor;
|
final Color textColor;
|
||||||
|
|
||||||
|
/// Icon to be placed before the text.
|
||||||
final IconData leadingIconData;
|
final IconData leadingIconData;
|
||||||
|
|
||||||
|
/// Icon to be placed after the text.
|
||||||
final IconData trailingIconData;
|
final IconData trailingIconData;
|
||||||
|
|
||||||
|
/// Text for the button.
|
||||||
final String text;
|
final String text;
|
||||||
|
|
||||||
|
/// Width of the button.
|
||||||
final double width;
|
final double width;
|
||||||
|
|
||||||
|
/// Height of the button.
|
||||||
final double height;
|
final double height;
|
||||||
|
|
||||||
|
/// Border radius for the button.
|
||||||
final double radius;
|
final double radius;
|
||||||
|
|
||||||
ActionButton({
|
ActionButton({
|
||||||
|
|
@ -24,6 +41,26 @@ class ActionButton extends StatelessWidget {
|
||||||
});
|
});
|
||||||
|
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
return ConstrainedBox(
|
||||||
|
constraints: BoxConstraints(
|
||||||
|
minHeight: 25,
|
||||||
|
minWidth: 60,
|
||||||
|
),
|
||||||
|
child: Container(
|
||||||
|
width: width,
|
||||||
|
height: height,
|
||||||
|
padding: EdgeInsets.all(2),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: color,
|
||||||
|
borderRadius: BorderRadius.circular(radius),
|
||||||
|
),
|
||||||
|
child: getButtonBody(),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns the button body.
|
||||||
|
Widget getButtonBody() {
|
||||||
final children = <Widget>[];
|
final children = <Widget>[];
|
||||||
if (leadingIconData != null) {
|
if (leadingIconData != null) {
|
||||||
children.addAll([
|
children.addAll([
|
||||||
|
|
@ -59,26 +96,11 @@ class ActionButton extends StatelessWidget {
|
||||||
),
|
),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
return ConstrainedBox(
|
return Row(
|
||||||
constraints: BoxConstraints(
|
|
||||||
minHeight: 25,
|
|
||||||
minWidth: 60,
|
|
||||||
),
|
|
||||||
child: Container(
|
|
||||||
width: width,
|
|
||||||
height: height,
|
|
||||||
padding: EdgeInsets.all(2),
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: color,
|
|
||||||
borderRadius: BorderRadius.circular(radius),
|
|
||||||
),
|
|
||||||
child: Row(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.center,
|
crossAxisAlignment: CrossAxisAlignment.center,
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
children: children,
|
children: children,
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue