dynamic_fab.dart 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. import 'dart:math' as math;
  2. import 'package:flutter/material.dart';
  3. import 'package:photos/ente_theme_data.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).backgroundColor,
  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
  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. height: 56,
  60. padding: const EdgeInsets.symmetric(horizontal: 20),
  61. child: OutlinedButton(
  62. onPressed: isFormValid //var here
  63. ? onPressedFunction
  64. : null,
  65. child: Text(buttonText),
  66. ),
  67. );
  68. }
  69. }
  70. }
  71. class NoScalingAnimation extends FloatingActionButtonAnimator {
  72. @override
  73. Offset getOffset({Offset begin, Offset end, double progress}) {
  74. return end;
  75. }
  76. @override
  77. Animation<double> getRotationAnimation({Animation<double> parent}) {
  78. return Tween<double>(begin: 1.0, end: 1.0).animate(parent);
  79. }
  80. @override
  81. Animation<double> getScaleAnimation({Animation<double> parent}) {
  82. return Tween<double>(begin: 1.0, end: 1.0).animate(parent);
  83. }
  84. }