这是CaiYouHui前端,一个关于flutter的安卓app,前端使用flutter实现

app_button.dart 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import 'package:flutter/material.dart';
  2. class AppButton extends StatelessWidget {
  3. final String text;
  4. final VoidCallback onPressed;
  5. final bool isLoading;
  6. final bool enabled;
  7. final Color? backgroundColor;
  8. final Color? textColor;
  9. final double? width;
  10. final double? height;
  11. const AppButton({
  12. super.key,
  13. required this.text,
  14. required this.onPressed,
  15. this.isLoading = false,
  16. this.enabled = true,
  17. this.backgroundColor,
  18. this.textColor,
  19. this.width,
  20. this.height = 50,
  21. });
  22. @override
  23. Widget build(BuildContext context) {
  24. return SizedBox(
  25. width: width ?? double.infinity,
  26. height: height,
  27. child: ElevatedButton(
  28. onPressed: enabled && !isLoading ? onPressed : null,
  29. style: ElevatedButton.styleFrom(
  30. backgroundColor: backgroundColor ?? Theme.of(context).primaryColor,
  31. foregroundColor: textColor ?? Colors.white,
  32. shape: RoundedRectangleBorder(
  33. borderRadius: BorderRadius.circular(10),
  34. ),
  35. elevation: 0,
  36. ),
  37. child: isLoading
  38. ? SizedBox(
  39. width: 24,
  40. height: 24,
  41. child: CircularProgressIndicator(
  42. strokeWidth: 2,
  43. color: textColor ?? Colors.white,
  44. ),
  45. )
  46. : Text(
  47. text,
  48. style: const TextStyle(
  49. fontSize: 16,
  50. fontWeight: FontWeight.w600,
  51. ),
  52. ),
  53. ),
  54. );
  55. }
  56. }