fluffychat/lib/pages/chat_list/start_chat_fab.dart

89 lines
2.4 KiB
Dart
Raw Normal View History

import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:go_router/go_router.dart';
import '../../config/themes.dart';
import 'chat_list.dart';
class StartChatFloatingActionButton extends StatelessWidget {
2023-03-19 18:59:50 +00:00
final ActiveFilter activeFilter;
final ValueNotifier<bool> scrolledToTop;
2023-03-19 18:59:50 +00:00
final bool roomsIsEmpty;
2023-12-23 14:07:35 +00:00
final void Function() createNewSpace;
2023-03-19 18:59:50 +00:00
const StartChatFloatingActionButton({
super.key,
2023-03-19 18:59:50 +00:00
required this.activeFilter,
required this.scrolledToTop,
required this.roomsIsEmpty,
2023-12-23 14:07:35 +00:00
required this.createNewSpace,
});
2023-12-23 14:07:35 +00:00
void _onPressed(BuildContext context) async {
2023-03-19 18:59:50 +00:00
switch (activeFilter) {
2022-08-30 18:24:36 +00:00
case ActiveFilter.allChats:
case ActiveFilter.messages:
2023-08-07 16:40:02 +00:00
context.go('/rooms/newprivatechat');
2022-08-30 18:24:36 +00:00
break;
case ActiveFilter.groups:
2023-08-07 16:40:02 +00:00
context.go('/rooms/newgroup');
2022-08-30 18:24:36 +00:00
break;
case ActiveFilter.spaces:
2023-12-23 14:07:35 +00:00
createNewSpace();
2022-08-30 18:24:36 +00:00
break;
}
}
IconData get icon {
2023-03-19 18:59:50 +00:00
switch (activeFilter) {
2022-08-30 18:24:36 +00:00
case ActiveFilter.allChats:
case ActiveFilter.messages:
2023-03-19 18:59:50 +00:00
return Icons.add_outlined;
2022-08-30 18:24:36 +00:00
case ActiveFilter.groups:
return Icons.group_add_outlined;
case ActiveFilter.spaces:
return Icons.workspaces_outlined;
}
}
String getLabel(BuildContext context) {
2023-03-19 18:59:50 +00:00
switch (activeFilter) {
2022-08-30 18:24:36 +00:00
case ActiveFilter.allChats:
case ActiveFilter.messages:
2023-03-19 18:59:50 +00:00
return roomsIsEmpty
2022-12-29 09:26:01 +00:00
? L10n.of(context)!.startFirstChat
: L10n.of(context)!.newChat;
2022-08-30 18:24:36 +00:00
case ActiveFilter.groups:
return L10n.of(context)!.newGroup;
case ActiveFilter.spaces:
return L10n.of(context)!.newSpace;
}
}
@override
Widget build(BuildContext context) {
return ValueListenableBuilder<bool>(
valueListenable: scrolledToTop,
2023-06-03 15:49:13 +00:00
builder: (context, scrolledToTop, _) => AnimatedSize(
duration: FluffyThemes.animationDuration,
curve: FluffyThemes.animationCurve,
2023-06-03 15:49:13 +00:00
clipBehavior: Clip.none,
child: scrolledToTop
? FloatingActionButton.extended(
onPressed: () => _onPressed(context),
icon: Icon(icon),
label: Text(
getLabel(context),
overflow: TextOverflow.fade,
),
)
: FloatingActionButton(
onPressed: () => _onPressed(context),
child: Icon(icon),
2022-08-30 18:24:36 +00:00
),
),
);
}
}