dynamic_fab.dart 2.5 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 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. height: 56,
  60. padding: const EdgeInsets.symmetric(horizontal: 20),
  61. child: OutlinedButton(
  62. onPressed: 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. }