style: New modal bottom sheets
This commit is contained in:
parent
4376070733
commit
2df72b5d13
19 changed files with 328 additions and 355 deletions
|
|
@ -10,6 +10,17 @@ import 'package:fluffychat/widgets/permission_slider_dialog.dart';
|
|||
import '../../widgets/matrix.dart';
|
||||
import 'user_bottom_sheet_view.dart';
|
||||
|
||||
enum UserBottomSheetAction {
|
||||
report,
|
||||
mention,
|
||||
ban,
|
||||
kick,
|
||||
unban,
|
||||
permission,
|
||||
message,
|
||||
ignore,
|
||||
}
|
||||
|
||||
class UserBottomSheet extends StatefulWidget {
|
||||
final User user;
|
||||
final Function? onMention;
|
||||
|
|
@ -27,7 +38,7 @@ class UserBottomSheet extends StatefulWidget {
|
|||
}
|
||||
|
||||
class UserBottomSheetController extends State<UserBottomSheet> {
|
||||
void participantAction(String action) async {
|
||||
void participantAction(UserBottomSheetAction action) async {
|
||||
// ignore: prefer_function_declarations_over_variables
|
||||
final Function askConfirmation = () async => (await showOkCancelAlertDialog(
|
||||
useRootNavigator: false,
|
||||
|
|
@ -38,7 +49,7 @@ class UserBottomSheetController extends State<UserBottomSheet> {
|
|||
) ==
|
||||
OkCancelResult.ok);
|
||||
switch (action) {
|
||||
case 'report':
|
||||
case UserBottomSheetAction.report:
|
||||
final event = widget.user;
|
||||
final score = await showConfirmationDialog<int>(
|
||||
context: context,
|
||||
|
|
@ -82,11 +93,11 @@ class UserBottomSheetController extends State<UserBottomSheet> {
|
|||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text(L10n.of(context)!.contentHasBeenReported)));
|
||||
break;
|
||||
case 'mention':
|
||||
case UserBottomSheetAction.mention:
|
||||
Navigator.of(context, rootNavigator: false).pop();
|
||||
widget.onMention!();
|
||||
break;
|
||||
case 'ban':
|
||||
case UserBottomSheetAction.ban:
|
||||
if (await askConfirmation()) {
|
||||
await showFutureLoadingDialog(
|
||||
context: context,
|
||||
|
|
@ -95,7 +106,7 @@ class UserBottomSheetController extends State<UserBottomSheet> {
|
|||
Navigator.of(context, rootNavigator: false).pop();
|
||||
}
|
||||
break;
|
||||
case 'unban':
|
||||
case UserBottomSheetAction.unban:
|
||||
if (await askConfirmation()) {
|
||||
await showFutureLoadingDialog(
|
||||
context: context,
|
||||
|
|
@ -104,7 +115,7 @@ class UserBottomSheetController extends State<UserBottomSheet> {
|
|||
Navigator.of(context, rootNavigator: false).pop();
|
||||
}
|
||||
break;
|
||||
case 'kick':
|
||||
case UserBottomSheetAction.kick:
|
||||
if (await askConfirmation()) {
|
||||
await showFutureLoadingDialog(
|
||||
context: context,
|
||||
|
|
@ -113,7 +124,7 @@ class UserBottomSheetController extends State<UserBottomSheet> {
|
|||
Navigator.of(context, rootNavigator: false).pop();
|
||||
}
|
||||
break;
|
||||
case 'permission':
|
||||
case UserBottomSheetAction.permission:
|
||||
final newPermission = await showPermissionChooser(
|
||||
context,
|
||||
currentLevel: widget.user.powerLevel,
|
||||
|
|
@ -127,7 +138,7 @@ class UserBottomSheetController extends State<UserBottomSheet> {
|
|||
Navigator.of(context, rootNavigator: false).pop();
|
||||
}
|
||||
break;
|
||||
case 'message':
|
||||
case UserBottomSheetAction.message:
|
||||
final roomIdResult = await showFutureLoadingDialog(
|
||||
context: context,
|
||||
future: () => widget.user.startDirectChat(),
|
||||
|
|
@ -137,7 +148,7 @@ class UserBottomSheetController extends State<UserBottomSheet> {
|
|||
.toSegments(['rooms', roomIdResult.result!]);
|
||||
Navigator.of(context, rootNavigator: false).pop();
|
||||
break;
|
||||
case 'ignore':
|
||||
case UserBottomSheetAction.ignore:
|
||||
if (await askConfirmation()) {
|
||||
await showFutureLoadingDialog(
|
||||
context: context,
|
||||
|
|
|
|||
|
|
@ -1,15 +1,11 @@
|
|||
import 'dart:math';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
import 'package:matrix/matrix.dart';
|
||||
|
||||
import 'package:fluffychat/config/themes.dart';
|
||||
import 'package:fluffychat/utils/fluffy_share.dart';
|
||||
import 'package:fluffychat/widgets/avatar.dart';
|
||||
import '../../utils/matrix_sdk_extensions/presence_extension.dart';
|
||||
import '../../widgets/content_banner.dart';
|
||||
import '../../widgets/m2_popup_menu_button.dart';
|
||||
import '../../widgets/matrix.dart';
|
||||
import 'user_bottom_sheet.dart';
|
||||
|
||||
|
|
@ -23,155 +19,114 @@ class UserBottomSheetView extends StatelessWidget {
|
|||
final user = controller.widget.user;
|
||||
final client = Matrix.of(context).client;
|
||||
final presence = client.presences[user.id];
|
||||
return Center(
|
||||
child: SizedBox(
|
||||
width: min(
|
||||
MediaQuery.of(context).size.width, FluffyThemes.columnWidth * 1.5),
|
||||
child: Material(
|
||||
elevation: 4,
|
||||
child: SafeArea(
|
||||
child: Scaffold(
|
||||
extendBodyBehindAppBar: true,
|
||||
appBar: AppBar(
|
||||
elevation: 0,
|
||||
backgroundColor:
|
||||
Theme.of(context).scaffoldBackgroundColor.withOpacity(0.5),
|
||||
leading: IconButton(
|
||||
icon: const Icon(Icons.arrow_downward_outlined),
|
||||
onPressed: Navigator.of(context, rootNavigator: false).pop,
|
||||
tooltip: L10n.of(context)!.close,
|
||||
),
|
||||
title: Text(user.calcDisplayname()),
|
||||
actions: [
|
||||
if (user.id != client.userID)
|
||||
M2PopupMenuButton(
|
||||
itemBuilder: (_) => [
|
||||
if (controller.widget.onMention != null)
|
||||
PopupMenuItem(
|
||||
value: 'mention',
|
||||
child: _TextWithIcon(
|
||||
L10n.of(context)!.mention,
|
||||
Icons.alternate_email_outlined,
|
||||
),
|
||||
),
|
||||
if (user.id != client.userID && !user.room.isDirectChat)
|
||||
PopupMenuItem(
|
||||
value: 'message',
|
||||
child: _TextWithIcon(
|
||||
L10n.of(context)!.sendAMessage,
|
||||
Icons.send_outlined,
|
||||
),
|
||||
),
|
||||
if (user.canChangePowerLevel)
|
||||
PopupMenuItem(
|
||||
value: 'permission',
|
||||
child: _TextWithIcon(
|
||||
L10n.of(context)!.setPermissionsLevel,
|
||||
Icons.edit_attributes_outlined,
|
||||
),
|
||||
),
|
||||
if (user.canKick)
|
||||
PopupMenuItem(
|
||||
value: 'kick',
|
||||
child: _TextWithIcon(
|
||||
L10n.of(context)!.kickFromChat,
|
||||
Icons.exit_to_app_outlined,
|
||||
),
|
||||
),
|
||||
if (user.canBan && user.membership != Membership.ban)
|
||||
PopupMenuItem(
|
||||
value: 'ban',
|
||||
child: _TextWithIcon(
|
||||
L10n.of(context)!.banFromChat,
|
||||
Icons.warning_sharp,
|
||||
),
|
||||
)
|
||||
else if (user.canBan &&
|
||||
user.membership == Membership.ban)
|
||||
PopupMenuItem(
|
||||
value: 'unban',
|
||||
child: _TextWithIcon(
|
||||
L10n.of(context)!.unbanFromChat,
|
||||
Icons.warning_outlined,
|
||||
),
|
||||
),
|
||||
if (!client.ignoredUsers.contains(user.id))
|
||||
PopupMenuItem(
|
||||
value: 'ignore',
|
||||
child: _TextWithIcon(
|
||||
L10n.of(context)!.ignore,
|
||||
Icons.block,
|
||||
),
|
||||
),
|
||||
PopupMenuItem(
|
||||
value: 'report',
|
||||
child: _TextWithIcon(
|
||||
L10n.of(context)!.reportUser,
|
||||
Icons.shield_outlined,
|
||||
),
|
||||
),
|
||||
],
|
||||
onSelected: controller.participantAction,
|
||||
),
|
||||
],
|
||||
),
|
||||
body: Column(
|
||||
children: [
|
||||
Expanded(
|
||||
child: ContentBanner(
|
||||
mxContent: user.avatarUrl,
|
||||
defaultIcon: Icons.account_circle_outlined,
|
||||
client: client,
|
||||
),
|
||||
),
|
||||
ListTile(
|
||||
title: Text(L10n.of(context)!.username),
|
||||
subtitle: Text(user.id),
|
||||
trailing: Icon(Icons.adaptive.share_outlined),
|
||||
onTap: () => FluffyShare.share(
|
||||
user.id,
|
||||
context,
|
||||
),
|
||||
),
|
||||
if (presence != null)
|
||||
ListTile(
|
||||
title: Text(presence.getLocalizedStatusMessage(context)),
|
||||
subtitle:
|
||||
Text(presence.getLocalizedLastActiveAgo(context)),
|
||||
trailing: Icon(Icons.circle,
|
||||
color: presence.presence == PresenceType.online
|
||||
? Colors.green
|
||||
: Colors.grey),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
return SafeArea(
|
||||
child: Scaffold(
|
||||
appBar: AppBar(
|
||||
leading: CloseButton(
|
||||
onPressed: Navigator.of(context, rootNavigator: false).pop,
|
||||
),
|
||||
title: Text(user.calcDisplayname()),
|
||||
actions: [
|
||||
if (user.id != client.userID)
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: OutlinedButton.icon(
|
||||
onPressed: () => controller
|
||||
.participantAction(UserBottomSheetAction.message),
|
||||
icon: const Icon(Icons.chat_outlined),
|
||||
label: Text(L10n.of(context)!.newChat),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
body: ListView(
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: Avatar(
|
||||
mxContent: user.avatarUrl,
|
||||
name: user.calcDisplayname(),
|
||||
size: Avatar.defaultSize * 2,
|
||||
fontSize: 24,
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: ListTile(
|
||||
contentPadding: const EdgeInsets.only(right: 16.0),
|
||||
title: Text(user.id),
|
||||
subtitle: presence == null
|
||||
? null
|
||||
: Text(presence.getLocalizedLastActiveAgo(context)),
|
||||
trailing: IconButton(
|
||||
icon: Icon(Icons.adaptive.share),
|
||||
onPressed: () => FluffyShare.share(
|
||||
user.id,
|
||||
context,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
if (controller.widget.onMention != null)
|
||||
ListTile(
|
||||
trailing: const Icon(Icons.alternate_email_outlined),
|
||||
title: Text(L10n.of(context)!.mention),
|
||||
onTap: () =>
|
||||
controller.participantAction(UserBottomSheetAction.mention),
|
||||
),
|
||||
if (user.canChangePowerLevel)
|
||||
ListTile(
|
||||
title: Text(L10n.of(context)!.setPermissionsLevel),
|
||||
trailing: const Icon(Icons.edit_attributes_outlined),
|
||||
onTap: () => controller
|
||||
.participantAction(UserBottomSheetAction.permission),
|
||||
),
|
||||
if (user.canKick)
|
||||
ListTile(
|
||||
title: Text(L10n.of(context)!.kickFromChat),
|
||||
trailing: const Icon(Icons.exit_to_app_outlined),
|
||||
onTap: () =>
|
||||
controller.participantAction(UserBottomSheetAction.kick),
|
||||
),
|
||||
if (user.canBan && user.membership != Membership.ban)
|
||||
ListTile(
|
||||
title: Text(L10n.of(context)!.banFromChat),
|
||||
trailing: const Icon(Icons.warning_sharp),
|
||||
onTap: () =>
|
||||
controller.participantAction(UserBottomSheetAction.ban),
|
||||
)
|
||||
else if (user.canBan && user.membership == Membership.ban)
|
||||
ListTile(
|
||||
title: Text(L10n.of(context)!.unbanFromChat),
|
||||
trailing: const Icon(Icons.warning_outlined),
|
||||
onTap: () =>
|
||||
controller.participantAction(UserBottomSheetAction.unban),
|
||||
),
|
||||
if (user.id != client.userID &&
|
||||
!client.ignoredUsers.contains(user.id))
|
||||
ListTile(
|
||||
textColor: Theme.of(context).colorScheme.onErrorContainer,
|
||||
iconColor: Theme.of(context).colorScheme.onErrorContainer,
|
||||
title: Text(L10n.of(context)!.ignore),
|
||||
trailing: const Icon(Icons.block),
|
||||
onTap: () =>
|
||||
controller.participantAction(UserBottomSheetAction.ignore),
|
||||
),
|
||||
if (user.id != client.userID)
|
||||
ListTile(
|
||||
textColor: Theme.of(context).colorScheme.error,
|
||||
iconColor: Theme.of(context).colorScheme.error,
|
||||
title: Text(L10n.of(context)!.reportUser),
|
||||
trailing: const Icon(Icons.shield_outlined),
|
||||
onTap: () =>
|
||||
controller.participantAction(UserBottomSheetAction.report),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _TextWithIcon extends StatelessWidget {
|
||||
final String text;
|
||||
final IconData iconData;
|
||||
|
||||
const _TextWithIcon(
|
||||
this.text,
|
||||
this.iconData, {
|
||||
Key? key,
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(iconData),
|
||||
const SizedBox(width: 16),
|
||||
Text(text),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue