2022-07-24 22:09:26 +02:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
|
|
|
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
|
|
|
import 'package:vrouter/vrouter.dart';
|
|
|
|
|
2023-01-07 09:22:31 +01:00
|
|
|
import '../../config/themes.dart';
|
2022-07-24 22:09:26 +02:00
|
|
|
import 'chat_list.dart';
|
|
|
|
|
|
|
|
class StartChatFloatingActionButton extends StatelessWidget {
|
2023-03-19 19:59:50 +01:00
|
|
|
final ActiveFilter activeFilter;
|
|
|
|
final bool scrolledToTop;
|
|
|
|
final bool roomsIsEmpty;
|
2022-07-24 22:09:26 +02:00
|
|
|
|
2023-03-19 19:59:50 +01:00
|
|
|
const StartChatFloatingActionButton({
|
|
|
|
Key? key,
|
|
|
|
required this.activeFilter,
|
|
|
|
required this.scrolledToTop,
|
|
|
|
required this.roomsIsEmpty,
|
|
|
|
}) : super(key: key);
|
2022-07-24 22:09:26 +02:00
|
|
|
|
2022-08-30 20:24:36 +02:00
|
|
|
void _onPressed(BuildContext context) {
|
2023-03-19 19:59:50 +01:00
|
|
|
switch (activeFilter) {
|
2022-08-30 20:24:36 +02:00
|
|
|
case ActiveFilter.allChats:
|
|
|
|
case ActiveFilter.messages:
|
|
|
|
VRouter.of(context).to('/newprivatechat');
|
|
|
|
break;
|
|
|
|
case ActiveFilter.groups:
|
|
|
|
VRouter.of(context).to('/newgroup');
|
|
|
|
break;
|
|
|
|
case ActiveFilter.spaces:
|
|
|
|
VRouter.of(context).to('/newspace');
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
IconData get icon {
|
2023-03-19 19:59:50 +01:00
|
|
|
switch (activeFilter) {
|
2022-08-30 20:24:36 +02:00
|
|
|
case ActiveFilter.allChats:
|
|
|
|
case ActiveFilter.messages:
|
2023-03-19 19:59:50 +01:00
|
|
|
return Icons.add_outlined;
|
2022-08-30 20:24:36 +02:00
|
|
|
case ActiveFilter.groups:
|
|
|
|
return Icons.group_add_outlined;
|
|
|
|
case ActiveFilter.spaces:
|
|
|
|
return Icons.workspaces_outlined;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
String getLabel(BuildContext context) {
|
2023-03-19 19:59:50 +01:00
|
|
|
switch (activeFilter) {
|
2022-08-30 20:24:36 +02:00
|
|
|
case ActiveFilter.allChats:
|
|
|
|
case ActiveFilter.messages:
|
2023-03-19 19:59:50 +01:00
|
|
|
return roomsIsEmpty
|
2022-12-29 10:26:01 +01:00
|
|
|
? L10n.of(context)!.startFirstChat
|
|
|
|
: L10n.of(context)!.newChat;
|
2022-08-30 20:24:36 +02:00
|
|
|
case ActiveFilter.groups:
|
|
|
|
return L10n.of(context)!.newGroup;
|
|
|
|
case ActiveFilter.spaces:
|
|
|
|
return L10n.of(context)!.newSpace;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-24 22:09:26 +02:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2022-08-30 20:24:36 +02:00
|
|
|
return AnimatedContainer(
|
2023-01-07 09:22:31 +01:00
|
|
|
duration: FluffyThemes.animationDuration,
|
|
|
|
curve: FluffyThemes.animationCurve,
|
2023-03-19 19:59:50 +01:00
|
|
|
width: roomsIsEmpty
|
2022-12-29 10:26:01 +01:00
|
|
|
? null
|
2023-03-19 19:59:50 +01:00
|
|
|
: scrolledToTop
|
2022-12-29 10:26:01 +01:00
|
|
|
? 144
|
2023-01-07 09:22:31 +01:00
|
|
|
: 56,
|
2023-03-19 19:59:50 +01:00
|
|
|
child: scrolledToTop
|
2022-08-30 20:24:36 +02:00
|
|
|
? FloatingActionButton.extended(
|
|
|
|
onPressed: () => _onPressed(context),
|
|
|
|
icon: Icon(icon),
|
|
|
|
label: Text(
|
|
|
|
getLabel(context),
|
|
|
|
overflow: TextOverflow.fade,
|
|
|
|
),
|
|
|
|
)
|
|
|
|
: FloatingActionButton(
|
|
|
|
onPressed: () => _onPressed(context),
|
|
|
|
child: Icon(icon),
|
|
|
|
),
|
2022-07-24 22:09:26 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|