2021-02-24 20:52:18 +01:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
|
|
|
import '../hooks/delayed_loading.dart';
|
|
|
|
|
|
|
|
/// [IconButton], usually at the bottom of some tile, that performs an async
|
|
|
|
/// action that uses [DelayedLoading], has reduced size to be more compact,
|
|
|
|
/// and has built in spinner
|
|
|
|
class TileAction extends StatelessWidget {
|
|
|
|
final IconData icon;
|
|
|
|
final VoidCallback onPressed;
|
|
|
|
final String tooltip;
|
2021-04-09 00:11:44 +02:00
|
|
|
final DelayedLoading? delayedLoading;
|
|
|
|
final Color? iconColor;
|
2021-02-24 20:52:18 +01:00
|
|
|
|
|
|
|
const TileAction({
|
2021-04-09 00:11:44 +02:00
|
|
|
Key? key,
|
2021-02-24 20:52:18 +01:00
|
|
|
this.delayedLoading,
|
|
|
|
this.iconColor,
|
2021-04-09 00:11:44 +02:00
|
|
|
required this.icon,
|
|
|
|
required this.onPressed,
|
|
|
|
required this.tooltip,
|
|
|
|
}) : super(key: key);
|
2021-02-24 20:52:18 +01:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) => IconButton(
|
|
|
|
constraints: BoxConstraints.tight(const Size(36, 30)),
|
|
|
|
icon: delayedLoading?.loading ?? false
|
|
|
|
? SizedBox.fromSize(
|
|
|
|
size: const Size.square(22),
|
|
|
|
child: const CircularProgressIndicator())
|
|
|
|
: Icon(
|
|
|
|
icon,
|
|
|
|
color: iconColor ??
|
2021-04-09 00:11:44 +02:00
|
|
|
Theme.of(context).iconTheme.color?.withAlpha(190),
|
2021-02-24 20:52:18 +01:00
|
|
|
),
|
|
|
|
splashRadius: 25,
|
|
|
|
onPressed: delayedLoading?.pending ?? false ? () {} : onPressed,
|
|
|
|
iconSize: 25,
|
|
|
|
tooltip: tooltip,
|
|
|
|
padding: const EdgeInsets.all(0),
|
|
|
|
);
|
|
|
|
}
|