button function
Widget
button({
- String? title,
- Widget? titleWidget,
- VoidCallback? onTap,
- IconData? icon,
- double? width,
- double? height,
- TextStyle? textStyle,
- Color? backgroundColor,
- ButtonType buttonType = ButtonType.elevated,
- EdgeInsets? padding,
- PageState state = PageState.initial,
- int countDownSeconds = 120,
Implementation
Widget button({
final String? title,
final Widget? titleWidget,
final VoidCallback? onTap,
final IconData? icon,
final double? width,
final double? height,
final TextStyle? textStyle,
final Color? backgroundColor,
final ButtonType buttonType = ButtonType.elevated,
final EdgeInsets? padding,
final PageState state = PageState.initial,
final int countDownSeconds = 120,
}) {
final Rx<PageState> buttonState = state.obs;
if (buttonType == ButtonType.elevated)
return Obx(
() {
if (buttonState.value == PageState.initial)
return ElevatedButton(
style: ButtonStyle(
textStyle: textStyle == null ? null : WidgetStatePropertyAll<TextStyle>(textStyle),
backgroundColor: WidgetStateProperty.all(backgroundColor),
padding: WidgetStateProperty.all(padding),
),
onPressed: onTap,
child: SizedBox(
height: height ?? 20,
width: width ?? MediaQuery.sizeOf(navigatorKey.currentContext!).width,
child: Center(
child: titleWidget ?? Text(title ?? '', textAlign: TextAlign.center),
),
),
);
else if (buttonState.value == PageState.loading)
return const CircularProgressIndicator().alignAtCenter();
else if (buttonState.value == PageState.paging)
return SlideCountdown(
separatorStyle: TextStyle(color: Theme.of(navigatorKey.currentContext!).colorScheme.onSurface),
decoration: const BoxDecoration(),
style: Theme.of(navigatorKey.currentContext!).textTheme.bodyMedium!,
duration: Duration(seconds: countDownSeconds),
onDone: () => buttonState(PageState.initial),
).alignAtCenter();
else
return const SizedBox();
},
);
if (buttonType == ButtonType.outlined)
return OutlinedButton(
style: ButtonStyle(
textStyle: textStyle == null ? null : WidgetStatePropertyAll<TextStyle>(textStyle),
backgroundColor: WidgetStateProperty.all(backgroundColor),
padding: WidgetStateProperty.all(padding),
),
onPressed: onTap,
child: SizedBox(
height: height ?? 20,
width: width ?? MediaQuery.sizeOf(navigatorKey.currentContext!).width,
child: Center(
child: titleWidget ?? Text(title ?? '', textAlign: TextAlign.center),
),
),
);
if (buttonType == ButtonType.text)
return TextButton(
style: ButtonStyle(
textStyle: textStyle == null ? null : WidgetStatePropertyAll<TextStyle>(textStyle),
backgroundColor: WidgetStateProperty.all(backgroundColor),
padding: WidgetStateProperty.all(padding),
),
onPressed: onTap,
child: SizedBox(
height: height ?? 20,
width: width ?? MediaQuery.sizeOf(navigatorKey.currentContext!).width,
child: Center(
child: titleWidget ?? Text(title ?? '', textAlign: TextAlign.center),
),
),
);
return const SizedBox();
}