ente/lib/ui/common/dynamic_fab.dart

91 lines
2.5 KiB
Dart
Raw Normal View History

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