2022-09-05 12:04:08 +02:00
|
|
|
import 'package:flutter/material.dart';
|
2022-09-06 07:58:41 +02:00
|
|
|
import 'package:nc_photos/k.dart' as k;
|
2022-11-12 10:55:33 +01:00
|
|
|
import 'package:nc_photos/material3.dart';
|
2022-09-05 12:04:08 +02:00
|
|
|
|
2022-09-06 07:58:41 +02:00
|
|
|
/// Button in the image editor toolbar
|
|
|
|
///
|
|
|
|
/// If [activationOrder] != null, this button is considered activated. And if
|
|
|
|
/// [activationOrder] >= 0, a number will be drawn on top to represent its
|
|
|
|
/// current order.
|
2022-09-05 12:04:08 +02:00
|
|
|
class ToolbarButton extends StatelessWidget {
|
|
|
|
const ToolbarButton({
|
|
|
|
Key? key,
|
|
|
|
required this.icon,
|
|
|
|
required this.label,
|
|
|
|
required this.onPressed,
|
|
|
|
this.isSelected = false,
|
2022-09-06 07:58:41 +02:00
|
|
|
this.activationOrder,
|
2022-09-05 12:04:08 +02:00
|
|
|
}) : super(key: key);
|
|
|
|
|
|
|
|
@override
|
|
|
|
build(BuildContext context) {
|
2022-11-12 10:55:33 +01:00
|
|
|
final Color backgroundColor, foregroundColor;
|
|
|
|
if (isSelected) {
|
|
|
|
backgroundColor = Theme.of(context).colorScheme.secondaryContainer;
|
|
|
|
foregroundColor = Theme.of(context).colorScheme.onSecondaryContainer;
|
|
|
|
} else {
|
|
|
|
if (isActivated) {
|
|
|
|
backgroundColor = M3.of(context).filterChip.disabled.containerSelected;
|
|
|
|
foregroundColor = Theme.of(context).colorScheme.onSurface;
|
|
|
|
} else {
|
|
|
|
backgroundColor = Theme.of(context).colorScheme.secondaryContainer;
|
|
|
|
foregroundColor = M3.of(context).filterChip.disabled.labelText;
|
|
|
|
}
|
|
|
|
}
|
2022-09-05 12:04:08 +02:00
|
|
|
return InkWell(
|
|
|
|
onTap: onPressed,
|
|
|
|
child: Padding(
|
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
|
|
children: [
|
|
|
|
SizedBox(
|
|
|
|
width: 64,
|
|
|
|
height: 64,
|
|
|
|
child: Stack(
|
|
|
|
fit: StackFit.expand,
|
|
|
|
children: [
|
|
|
|
AnimatedOpacity(
|
|
|
|
opacity: isSelected || isActivated ? 1 : 0,
|
|
|
|
duration: k.animationDurationNormal,
|
|
|
|
child: Container(
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
borderRadius: BorderRadius.circular(32),
|
2022-11-12 10:55:33 +01:00
|
|
|
color: backgroundColor,
|
2022-09-05 12:04:08 +02:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Center(
|
|
|
|
child: Icon(
|
|
|
|
icon,
|
|
|
|
size: 32,
|
2022-11-12 10:55:33 +01:00
|
|
|
color: foregroundColor,
|
2022-09-05 12:04:08 +02:00
|
|
|
),
|
|
|
|
),
|
2022-09-06 07:58:41 +02:00
|
|
|
if (isActivated && activationOrder! >= 0)
|
2022-09-05 12:04:08 +02:00
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.only(top: 2),
|
|
|
|
child: Align(
|
|
|
|
alignment: Alignment.topCenter,
|
|
|
|
child: Text(
|
2022-09-06 07:58:41 +02:00
|
|
|
(activationOrder! + 1).toString(),
|
2022-09-05 12:04:08 +02:00
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 12,
|
2022-11-12 10:55:33 +01:00
|
|
|
color: foregroundColor,
|
2022-09-05 12:04:08 +02:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
const SizedBox(height: 8),
|
|
|
|
Text(
|
|
|
|
label,
|
|
|
|
textAlign: TextAlign.center,
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 12,
|
2022-11-12 10:55:33 +01:00
|
|
|
color: isSelected
|
|
|
|
? Theme.of(context).colorScheme.onSurface
|
|
|
|
: Theme.of(context).colorScheme.onSurfaceVariant,
|
2022-09-05 12:04:08 +02:00
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-09-06 07:58:41 +02:00
|
|
|
bool get isActivated => activationOrder != null;
|
2022-09-05 12:04:08 +02:00
|
|
|
|
|
|
|
final IconData icon;
|
|
|
|
final String label;
|
|
|
|
final VoidCallback? onPressed;
|
|
|
|
final bool isSelected;
|
2022-09-06 07:58:41 +02:00
|
|
|
final int? activationOrder;
|
2022-09-05 12:04:08 +02:00
|
|
|
}
|