nc-photos/lib/widget/selectable.dart

63 lines
1.6 KiB
Dart
Raw Normal View History

2021-07-05 18:21:58 +02:00
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:nc_photos/theme.dart';
// Overlay a check mark if an item is selected
class Selectable extends StatelessWidget {
Selectable({
2021-07-23 22:05:57 +02:00
Key? key,
required this.child,
2021-07-05 18:21:58 +02:00
this.isSelected = false,
2021-07-23 22:05:57 +02:00
required this.iconSize,
2021-07-05 18:21:58 +02:00
this.borderRadius,
this.onTap,
this.onLongPress,
}) : super(key: key);
@override
build(BuildContext context) {
return Stack(
fit: StackFit.expand,
children: [
child,
if (isSelected)
Positioned.fill(
child: Container(
decoration: BoxDecoration(
color: AppTheme.getSelectionOverlayColor(context),
borderRadius: borderRadius,
),
child: Align(
alignment: Alignment.center,
child: Icon(
Icons.check_circle_outlined,
size: iconSize,
color: AppTheme.getSelectionCheckColor(context),
),
),
),
),
if (onTap != null || onLongPress != null)
Positioned.fill(
child: Material(
type: MaterialType.transparency,
child: InkWell(
onTap: onTap,
onLongPress: onLongPress,
borderRadius: borderRadius,
),
),
),
],
);
}
final Widget child;
final bool isSelected;
final double iconSize;
2021-07-23 22:05:57 +02:00
final BorderRadius? borderRadius;
2021-07-05 18:21:58 +02:00
2021-07-23 22:05:57 +02:00
final VoidCallback? onTap;
final VoidCallback? onLongPress;
2021-07-05 18:21:58 +02:00
}