dynamic_fab.dart 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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:
  63. isFormValid! ? onPressedFunction as void Function()? : null,
  64. child: Text(buttonText!),
  65. ),
  66. );
  67. }
  68. }
  69. }
  70. class NoScalingAnimation extends FloatingActionButtonAnimator {
  71. @override
  72. Offset getOffset({Offset? begin, required Offset end, double? progress}) {
  73. return end;
  74. }
  75. @override
  76. Animation<double> getRotationAnimation({required Animation<double> parent}) {
  77. return Tween<double>(begin: 1.0, end: 1.0).animate(parent);
  78. }
  79. @override
  80. Animation<double> getScaleAnimation({required Animation<double> parent}) {
  81. return Tween<double>(begin: 1.0, end: 1.0).animate(parent);
  82. }
  83. }