lemmur-app-android/lib/widgets/tile_action.dart

46 lines
1.3 KiB
Dart
Raw Normal View History

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;
final DelayedLoading? delayedLoading;
final bool loading;
final Color? iconColor;
2021-02-24 20:52:18 +01:00
const TileAction({
2022-05-11 22:23:18 +02:00
super.key,
2021-02-24 20:52:18 +01:00
this.delayedLoading,
this.iconColor,
required this.icon,
required this.onPressed,
required this.tooltip,
this.loading = false,
2022-05-11 22:23:18 +02:00
});
2021-02-24 20:52:18 +01:00
@override
Widget build(BuildContext context) => IconButton(
constraints: BoxConstraints.tight(const Size(36, 30)),
padding: EdgeInsets.zero,
splashRadius: 25,
iconSize: 25,
tooltip: tooltip,
onPressed: delayedLoading?.pending ?? loading ? () {} : onPressed,
icon: delayedLoading?.loading ?? loading
2021-02-24 20:52:18 +01:00
? SizedBox.fromSize(
size: const Size.square(22),
child: const CircularProgressIndicator.adaptive(),
)
2021-02-24 20:52:18 +01:00
: Icon(
icon,
color: iconColor ??
Theme.of(context).iconTheme.color?.withAlpha(190),
2021-02-24 20:52:18 +01:00
),
);
}