ente/lib/ui/common/dynamic_fab.dart

92 lines
2.5 KiB
Dart
Raw Normal View History

2023-04-10 04:17:45 +00:00
2022-11-01 06:13:06 +00:00
import 'dart:math' as math;
import 'package:ente_auth/ente_theme_data.dart';
import 'package:flutter/material.dart';
class DynamicFAB extends StatelessWidget {
2023-04-10 04:17:45 +00:00
final bool? isKeypadOpen;
final bool? isFormValid;
final String? buttonText;
final Function? onPressedFunction;
2022-11-01 06:13:06 +00:00
const DynamicFAB({
2023-04-10 04:17:45 +00:00
Key? key,
2022-11-01 06:13:06 +00:00
this.isKeypadOpen,
this.buttonText,
this.isFormValid,
this.onPressedFunction,
}) : super(key: key);
@override
Widget build(BuildContext context) {
2023-04-10 04:17:45 +00:00
if (isKeypadOpen!) {
2022-11-01 06:13:06 +00:00
return Container(
decoration: BoxDecoration(
boxShadow: [
BoxShadow(
2023-08-22 04:47:15 +00:00
color: Theme.of(context).colorScheme.background,
2022-11-01 06:13:06 +00:00
spreadRadius: 200,
blurRadius: 100,
offset: const Offset(0, 230),
)
],
),
width: double.infinity,
child: Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
FloatingActionButton(
heroTag: 'FAB',
backgroundColor:
Theme.of(context).colorScheme.dynamicFABBackgroundColor,
foregroundColor:
Theme.of(context).colorScheme.dynamicFABTextColor,
2023-04-10 04:17:45 +00:00
onPressed: isFormValid!
? onPressedFunction as void Function()?
2022-11-01 06:13:06 +00:00
: () {
FocusScope.of(context).unfocus();
},
child: Transform.rotate(
2023-04-10 04:17:45 +00:00
angle: isFormValid! ? 0 : math.pi / 2,
2022-11-01 06:13:06 +00:00
child: const Icon(
Icons.chevron_right,
size: 36,
),
), //keypad down here
),
],
),
);
} else {
return Container(
width: double.infinity,
height: 56,
padding: const EdgeInsets.symmetric(horizontal: 20),
child: OutlinedButton(
2023-04-10 04:17:45 +00:00
onPressed: isFormValid! ? onPressedFunction as void Function()? : null,
child: Text(buttonText!),
2022-11-01 06:13:06 +00:00
),
);
}
}
}
class NoScalingAnimation extends FloatingActionButtonAnimator {
@override
2023-04-10 04:17:45 +00:00
Offset getOffset({Offset? begin, required Offset end, double? progress}) {
2022-11-01 06:13:06 +00:00
return end;
}
@override
2023-04-10 04:17:45 +00:00
Animation<double> getRotationAnimation({required Animation<double> parent}) {
2022-11-01 06:13:06 +00:00
return Tween<double>(begin: 1.0, end: 1.0).animate(parent);
}
@override
2023-04-10 04:17:45 +00:00
Animation<double> getScaleAnimation({required Animation<double> parent}) {
2022-11-01 06:13:06 +00:00
return Tween<double>(begin: 1.0, end: 1.0).animate(parent);
}
}