aves/lib/widgets/common/behaviour/intents.dart
Thibault Deckers 32bbee8bfd tv: info
2023-01-31 19:10:38 +01:00

44 lines
1.1 KiB
Dart

import 'package:flutter/widgets.dart';
class VerticalScrollIntent extends Intent {
const VerticalScrollIntent({
required this.type,
});
const VerticalScrollIntent.up() : type = VerticalScrollDirection.up;
const VerticalScrollIntent.down() : type = VerticalScrollDirection.down;
final VerticalScrollDirection type;
}
enum VerticalScrollDirection {
up,
down,
}
class VerticalScrollIntentAction extends CallbackAction<VerticalScrollIntent> {
VerticalScrollIntentAction({
required ScrollController scrollController,
}) : super(onInvoke: (intent) => _onScrollIntent(intent, scrollController));
static void _onScrollIntent(
VerticalScrollIntent intent,
ScrollController scrollController,
) {
late int factor;
switch (intent.type) {
case VerticalScrollDirection.up:
factor = -1;
break;
case VerticalScrollDirection.down:
factor = 1;
break;
}
scrollController.animateTo(
scrollController.offset + factor * 150,
duration: const Duration(milliseconds: 500),
curve: Curves.easeOutCubic,
);
}
}