Fladder/lib/screens/shared/flat_button.dart

76 lines
2.2 KiB
Dart

import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:fladder/theme.dart';
class FlatButton extends ConsumerWidget {
final Widget? child;
final bool autoFocus;
final FocusNode? focusNode;
final Function(bool value)? onFocusChange;
final Function()? onTap;
final Function()? onLongPress;
final Function()? onDoubleTap;
final Function(TapDownDetails details)? onSecondaryTapDown;
final BorderRadius? borderRadiusGeometry;
final Color? splashColor;
final double elevation;
final bool showFeedback;
final Clip clipBehavior;
final List<Widget> overlays;
const FlatButton({
this.child,
this.onFocusChange,
this.focusNode,
this.autoFocus = false,
this.onTap,
this.onLongPress,
this.onDoubleTap,
this.onSecondaryTapDown,
this.borderRadiusGeometry,
this.splashColor,
this.elevation = 0,
this.showFeedback = true,
this.clipBehavior = Clip.none,
this.overlays = const [],
super.key,
});
bool get _hasInteraction => onTap != null || onLongPress != null || onDoubleTap != null;
@override
Widget build(BuildContext context, WidgetRef ref) {
if (!_hasInteraction) {
return child ?? Container();
}
return Stack(
fit: StackFit.passthrough,
children: [
child ?? Container(),
Positioned.fill(
child: Material(
color: Colors.transparent,
clipBehavior: clipBehavior,
borderRadius: borderRadiusGeometry ?? FladderTheme.defaultShape.borderRadius,
elevation: 0,
child: InkWell(
autofocus: autoFocus,
focusNode: focusNode,
onTap: onTap,
onLongPress: onLongPress,
onFocusChange: onFocusChange,
onDoubleTap: onDoubleTap,
onSecondaryTapDown: onSecondaryTapDown,
borderRadius: borderRadiusGeometry ?? BorderRadius.circular(10),
splashColor: splashColor ?? Theme.of(context).colorScheme.primary.withValues(alpha: 0.5),
hoverColor: showFeedback ? null : Colors.transparent,
splashFactory: InkSparkle.splashFactory,
),
),
),
...overlays,
],
);
}
}