myButton method

Widget myButton(
  1. String text,
  2. bool isEnabled,
  3. void onClick(),
  4. void onLongClick(), {
  5. IconData icon = Icons.cabin_rounded,
  6. String btnType = "tb",
})

Implementation

Widget myButton(String text, bool isEnabled, void Function() onClick, void Function() onLongClick, {IconData icon = Icons.cabin_rounded, String btnType = "tb"}) {
if (btnType=="tb") {
return TextButton(
onPressed: isEnabled ? onClick : null,
onLongPress: isEnabled ? onLongClick : null,
// onFocusChange: () {},
// onHover: () {},
autofocus: false,
focusNode: FocusNode(canRequestFocus: true),
style: TextButton.styleFrom(
backgroundColor: Colors.white,
foregroundColor: Colors.red,
shape: RoundedSuperellipseBorder(borderRadius: BorderRadius.circular(14)),
elevation: 6,
alignment: Alignment.center,
textStyle: TextStyle(
fontSize: 14,
fontWeight: FontWeight.bold,
),
),
child: myTextView(text),
);
}
else if (btnType=="eb") {
return ElevatedButton(
onPressed: isEnabled ? onClick : null,
onLongPress: isEnabled ? onLongClick : null,
// onFocusChange: () {},
// onHover: () {},
autofocus: false,
focusNode: FocusNode(canRequestFocus: true),
style: ButtonStyle(
foregroundColor: WidgetStateProperty.all(Colors.white),
backgroundColor: WidgetStateProperty.resolveWith<Color?>(
    (states)=>states.contains(WidgetState.pressed) ? Colors.blueAccent : Colors.blue,
),
shadowColor: WidgetStateProperty.all(Colors.black),
overlayColor: WidgetStateProperty.all(Colors.white),
alignment: Alignment.center,
elevation: WidgetStateProperty.all(5),
padding: WidgetStateProperty.all(EdgeInsets.symmetric(vertical: 14, horizontal: 20)),
shape: WidgetStateProperty.all(RoundedRectangleBorder(borderRadius: BorderRadius.circular(14))),
side: WidgetStateProperty.all(BorderSide(color: Colors.blueAccent, width: 1)),
minimumSize: WidgetStateProperty.all(Size(120, 45)),
maximumSize: WidgetStateProperty.all(Size(250, 60)),
animationDuration: Duration(milliseconds: 200),
),
child: myTextView(text),
);
}
else if (btnType=="ob") {
return OutlinedButton(
onPressed: isEnabled ? onClick : null,
onLongPress: isEnabled ? onLongClick : null,
// onFocusChange: () {},
// onHover: () {},
autofocus: false,
focusNode: FocusNode(canRequestFocus: true),
style: OutlinedButton.styleFrom(
backgroundColor: Colors.white,
foregroundColor: Colors.red,
shape: RoundedSuperellipseBorder(borderRadius: BorderRadius.circular(14)),
elevation: 6,
alignment: Alignment.center,
),
child: myTextView(text),
);
}
else if (btnType=="ib") {
return IconButton(
onPressed: isEnabled ? onClick : null,
onLongPress: isEnabled ? onLongClick : null,
// onFocusChange: () {},
// onHover: () {},
autofocus: false,
focusNode: FocusNode(canRequestFocus: true),
tooltip: text,
icon: Icon(icon),
iconSize: 32,
color: Colors.red,
splashColor: Colors.red.withValues(alpha: 0.1),
highlightColor: Colors.red.withValues(alpha: 0.1),
);
}
else if (btnType=="fb") {
return FilledButton(
onPressed: isEnabled ? onClick : null,
onLongPress: isEnabled ? onLongClick : null,
// onFocusChange: () {},
// onHover: () {},
autofocus: false,
focusNode: FocusNode(canRequestFocus: true),
style: FilledButton.styleFrom(
backgroundColor: Colors.white,
foregroundColor: Colors.red,
shape: RoundedSuperellipseBorder(borderRadius: BorderRadius.circular(14)),
elevation: 6,
alignment: Alignment.center,
disabledBackgroundColor: Colors.red,
disabledForegroundColor: Colors.red,
shadowColor: Colors.blueAccent,
),
child: myTextView(text),
);
}
else if (btnType=="fabm") {
return FloatingActionButton(
onPressed: isEnabled ? onClick : null,
// onFocusChange: () {},
// onHover: () {},
autofocus: false,
focusNode: FocusNode(canRequestFocus: true),
tooltip: text,
heroTag: "miniFab",
mini: true,
enableFeedback: true,
child: Icon(icon),
);
}
else {
return SizedBox.shrink();
}
}