dynamic_fab.dart 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. import 'dart:math' as math;
  2. import 'package:ente_auth/ente_theme_data.dart';
  3. import 'package:flutter/material.dart';
  4. class DynamicFAB extends StatelessWidget {
  5. final bool? isKeypadOpen;
  6. final bool? isFormValid;
  7. final String? buttonText;
  8. final Function? onPressedFunction;
  9. const DynamicFAB({
  10. Key? key,
  11. this.isKeypadOpen,
  12. this.buttonText,
  13. this.isFormValid,
  14. this.onPressedFunction,
  15. }) : super(key: key);
  16. @override
  17. Widget build(BuildContext context) {
  18. if (isKeypadOpen!) {
  19. return Container(
  20. decoration: BoxDecoration(
  21. boxShadow: [
  22. BoxShadow(
  23. color: Theme.of(context).colorScheme.background,
  24. spreadRadius: 200,
  25. blurRadius: 100,
  26. offset: const Offset(0, 230),
  27. ),
  28. ],
  29. ),
  30. width: double.infinity,
  31. child: Row(
  32. mainAxisAlignment: MainAxisAlignment.end,
  33. children: [
  34. FloatingActionButton(
  35. heroTag: 'FAB',
  36. backgroundColor:
  37. Theme.of(context).colorScheme.dynamicFABBackgroundColor,
  38. foregroundColor:
  39. Theme.of(context).colorScheme.dynamicFABTextColor,
  40. onPressed: isFormValid!
  41. ? onPressedFunction as void Function()?
  42. : () {
  43. FocusScope.of(context).unfocus();
  44. },
  45. child: Transform.rotate(
  46. angle: isFormValid! ? 0 : math.pi / 2,
  47. child: const Icon(
  48. Icons.chevron_right,
  49. size: 36,
  50. ),
  51. ), //keypad down here
  52. ),
  53. ],
  54. ),
  55. );
  56. } else {
  57. return Container(
  58. width: double.infinity,
  59. padding: const EdgeInsets.symmetric(horizontal: 20),
  60. child: OutlinedButton(
  61. onPressed:
  62. isFormValid! ? onPressedFunction as void Function()? : null,
  63. child: Text(buttonText!),
  64. ),
  65. );
  66. }
  67. }
  68. }
  69. class NoScalingAnimation extends FloatingActionButtonAnimator {
  70. @override
  71. Offset getOffset({Offset? begin, required Offset end, double? progress}) {
  72. return end;
  73. }
  74. @override
  75. Animation<double> getRotationAnimation({required Animation<double> parent}) {
  76. return Tween<double>(begin: 1.0, end: 1.0).animate(parent);
  77. }
  78. @override
  79. Animation<double> getScaleAnimation({required Animation<double> parent}) {
  80. return Tween<double>(begin: 1.0, end: 1.0).animate(parent);
  81. }
  82. }