feat: add context menu actions for desktops

Related: #849

Signed-off-by: TheOneWithTheBraid <the-one@with-the-braid.cf>
This commit is contained in:
TheOneWithTheBraid 2022-03-02 20:28:16 +01:00
parent 004edc7f8f
commit 49f0a5bde8
7 changed files with 513 additions and 345 deletions

View File

@ -2750,5 +2750,6 @@
"experimentalVideoCalls": "Experimental video calls", "experimentalVideoCalls": "Experimental video calls",
"@experimentalVideoCalls": {}, "@experimentalVideoCalls": {},
"emailOrUsername": "Email or username", "emailOrUsername": "Email or username",
"@emailOrUsername": {} "@emailOrUsername": {},
"select": "Select"
} }

View File

@ -1,3 +1,4 @@
import 'package:fluffychat/utils/contextual_actions.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:adaptive_dialog/adaptive_dialog.dart'; import 'package:adaptive_dialog/adaptive_dialog.dart';
@ -6,6 +7,7 @@ import 'package:future_loading_dialog/future_loading_dialog.dart';
import 'package:matrix/matrix.dart'; import 'package:matrix/matrix.dart';
import 'package:pedantic/pedantic.dart'; import 'package:pedantic/pedantic.dart';
import 'package:vrouter/vrouter.dart'; import 'package:vrouter/vrouter.dart';
import 'package:contextmenu/contextmenu.dart';
import 'package:fluffychat/config/app_config.dart'; import 'package:fluffychat/config/app_config.dart';
import 'package:fluffychat/utils/matrix_sdk_extensions.dart/matrix_locals.dart'; import 'package:fluffychat/utils/matrix_sdk_extensions.dart/matrix_locals.dart';
@ -155,171 +157,235 @@ class ChatListItem extends StatelessWidget {
? 20.0 ? 20.0
: 14.0 : 14.0
: 0.0; : 0.0;
return ListTile( return ContextMenuArea(
selected: selected || activeChat, builder: (c) {
selectedTileColor: selected // important to separate between [c] and [context]
? Theme.of(context).primaryColor.withAlpha(100) final provider = ContextualActions.of(context);
: Theme.of(context).secondaryHeaderColor, if (provider.actions.isNotEmpty) {
onLongPress: onLongPress as void Function()?, return provider.buildContextMenu(c)
leading: selected ..insert(
? SizedBox( 0,
width: Avatar.defaultSize, ListTile(
height: Avatar.defaultSize, title: Text(L10n.of(context)!.select),
child: Material( leading: const Icon(Icons.select_all),
color: Theme.of(context).primaryColor, onTap: () {
borderRadius: BorderRadius.circular(Avatar.defaultSize), Navigator.of(c).pop();
child: const Icon(Icons.check, color: Colors.white), onLongPress?.call();
},
), ),
) );
: Avatar( } else {
mxContent: room.avatar, return [
name: room.displayname, ListTile(
onTap: onLongPress as void Function()?, title: Text(L10n.of(context)!.select),
leading: const Icon(Icons.select_all),
onTap: () {
Navigator.of(c).pop();
onLongPress?.call();
},
), ),
title: Row( /*
children: <Widget>[ if (controller.spaces.isNotEmpty)
Expanded( ContextualAction(
child: Text( label: L10n.of(context)!.addToSpace,
room.getLocalizedDisplayname(MatrixLocals(L10n.of(context)!)), icon: const Icon(Icons.group_work_outlined),
maxLines: 1, action: controller.addOrRemoveToSpace,
overflow: TextOverflow.ellipsis, ),
softWrap: false, ContextualAction(
style: TextStyle( label: L10n.of(context)!.toggleUnread,
fontWeight: FontWeight.bold, icon: Icon(controller.anySelectedRoomNotMarkedUnread
color: unread ? Icons.mark_chat_read_outlined
? Theme.of(context).colorScheme.secondary : Icons.mark_chat_unread_outlined),
: Theme.of(context).textTheme.bodyText1!.color, action: controller.toggleUnread,
),
ContextualAction(
label: L10n.of(context)!.toggleFavorite,
icon: Icon(controller.anySelectedRoomNotFavorite
? Icons.push_pin_outlined
: Icons.push_pin),
action: controller.toggleFavouriteRoom,
),
ContextualAction(
icon: Icon(controller.anySelectedRoomNotMuted
? Icons.notifications_off_outlined
: Icons.notifications_outlined),
label: L10n.of(context)!.toggleMuted,
action: controller.toggleMuted,
),
ContextualAction(
icon: const Icon(Icons.delete_outlined),
label: L10n.of(context)!.archive,
action: controller.archiveAction,
), */
];
}
},
child: ListTile(
selected: selected || activeChat,
selectedTileColor: selected
? Theme.of(context).primaryColor.withAlpha(100)
: Theme.of(context).secondaryHeaderColor,
onLongPress: onLongPress as void Function()?,
leading: selected
? SizedBox(
width: Avatar.defaultSize,
height: Avatar.defaultSize,
child: Material(
color: Theme.of(context).primaryColor,
borderRadius: BorderRadius.circular(Avatar.defaultSize),
child: const Icon(Icons.check, color: Colors.white),
),
)
: Avatar(
mxContent: room.avatar,
name: room.displayname,
onTap: onLongPress as void Function()?,
),
title: Row(
children: <Widget>[
Expanded(
child: Text(
room.getLocalizedDisplayname(MatrixLocals(L10n.of(context)!)),
maxLines: 1,
overflow: TextOverflow.ellipsis,
softWrap: false,
style: TextStyle(
fontWeight: FontWeight.bold,
color: unread
? Theme.of(context).colorScheme.secondary
: Theme.of(context).textTheme.bodyText1!.color,
),
), ),
), ),
), if (isMuted)
if (isMuted) const Padding(
const Padding( padding: EdgeInsets.only(left: 4.0),
padding: EdgeInsets.only(left: 4.0), child: Icon(
child: Icon( Icons.notifications_off_outlined,
Icons.notifications_off_outlined, size: 16,
size: 16, ),
),
if (room.isFavourite)
Padding(
padding: EdgeInsets.only(
right: room.notificationCount > 0 ? 4.0 : 0.0),
child: Icon(
Icons.push_pin_outlined,
size: 16,
color: Theme.of(context).colorScheme.secondary,
),
), ),
),
if (room.isFavourite)
Padding( Padding(
padding: EdgeInsets.only( padding: const EdgeInsets.only(left: 4.0),
right: room.notificationCount > 0 ? 4.0 : 0.0), child: Text(
child: Icon( room.timeCreated.localizedTimeShort(context),
Icons.push_pin_outlined, style: TextStyle(
size: 16, fontSize: 13,
color: Theme.of(context).colorScheme.secondary, color: unread
? Theme.of(context).colorScheme.secondary
: Theme.of(context).textTheme.bodyText2!.color,
),
), ),
), ),
Padding(
padding: const EdgeInsets.only(left: 4.0),
child: Text(
room.timeCreated.localizedTimeShort(context),
style: TextStyle(
fontSize: 13,
color: unread
? Theme.of(context).colorScheme.secondary
: Theme.of(context).textTheme.bodyText2!.color,
),
),
),
],
),
subtitle: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
if (typingText.isEmpty &&
ownMessage &&
room.lastEvent!.status.isSending) ...[
const SizedBox(
width: 16,
height: 16,
child: CircularProgressIndicator.adaptive(strokeWidth: 2),
),
const SizedBox(width: 4),
], ],
AnimatedContainer( ),
width: typingText.isEmpty ? 0 : 18, subtitle: Row(
clipBehavior: Clip.hardEdge, mainAxisAlignment: MainAxisAlignment.center,
decoration: const BoxDecoration(), children: <Widget>[
duration: const Duration(milliseconds: 300), if (typingText.isEmpty &&
curve: Curves.bounceInOut, ownMessage &&
padding: const EdgeInsets.only(right: 4), room.lastEvent!.status.isSending) ...[
child: Icon( const SizedBox(
Icons.edit_outlined, width: 16,
color: Theme.of(context).colorScheme.secondary, height: 16,
size: 14, child: CircularProgressIndicator.adaptive(strokeWidth: 2),
),
const SizedBox(width: 4),
],
AnimatedContainer(
width: typingText.isEmpty ? 0 : 18,
clipBehavior: Clip.hardEdge,
decoration: const BoxDecoration(),
duration: const Duration(milliseconds: 300),
curve: Curves.bounceInOut,
padding: const EdgeInsets.only(right: 4),
child: Icon(
Icons.edit_outlined,
color: Theme.of(context).colorScheme.secondary,
size: 14,
),
), ),
), Expanded(
Expanded( child: typingText.isNotEmpty
child: typingText.isNotEmpty
? Text(
typingText,
style: TextStyle(
color: Theme.of(context).colorScheme.secondary,
),
softWrap: false,
)
: Text(
room.membership == Membership.invite
? L10n.of(context)!.youAreInvitedToThisChat
: room.lastEvent?.getLocalizedBody(
MatrixLocals(L10n.of(context)!),
hideReply: true,
hideEdit: true,
plaintextBody: true,
withSenderNamePrefix: !room.isDirectChat ||
room.directChatMatrixID !=
room.lastEvent?.senderId,
) ??
L10n.of(context)!.emptyChat,
softWrap: false,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(
color: unread
? Theme.of(context).colorScheme.secondary
: Theme.of(context).textTheme.bodyText2!.color,
decoration: room.lastEvent?.redacted == true
? TextDecoration.lineThrough
: null,
),
),
),
const SizedBox(width: 8),
AnimatedContainer(
duration: const Duration(milliseconds: 300),
curve: Curves.bounceInOut,
padding: const EdgeInsets.symmetric(horizontal: 7),
height: unreadBubbleSize,
width:
room.notificationCount == 0 && !unread && !room.hasNewMessages
? 0
: (unreadBubbleSize - 9) *
room.notificationCount.toString().length +
9,
decoration: BoxDecoration(
color: room.highlightCount > 0
? Colors.red
: room.notificationCount > 0
? Theme.of(context).primaryColor
: Theme.of(context).primaryColor.withAlpha(100),
borderRadius: BorderRadius.circular(AppConfig.borderRadius),
),
child: Center(
child: room.notificationCount > 0
? Text( ? Text(
room.notificationCount.toString(), typingText,
style: const TextStyle( style: TextStyle(
color: Colors.white, color: Theme.of(context).colorScheme.secondary,
fontSize: 13,
), ),
softWrap: false,
) )
: Container(), : Text(
room.membership == Membership.invite
? L10n.of(context)!.youAreInvitedToThisChat
: room.lastEvent?.getLocalizedBody(
MatrixLocals(L10n.of(context)!),
hideReply: true,
hideEdit: true,
plaintextBody: true,
withSenderNamePrefix: !room.isDirectChat ||
room.directChatMatrixID !=
room.lastEvent?.senderId,
) ??
L10n.of(context)!.emptyChat,
softWrap: false,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(
color: unread
? Theme.of(context).colorScheme.secondary
: Theme.of(context).textTheme.bodyText2!.color,
decoration: room.lastEvent?.redacted == true
? TextDecoration.lineThrough
: null,
),
),
), ),
), const SizedBox(width: 8),
], AnimatedContainer(
duration: const Duration(milliseconds: 300),
curve: Curves.bounceInOut,
padding: const EdgeInsets.symmetric(horizontal: 7),
height: unreadBubbleSize,
width:
room.notificationCount == 0 && !unread && !room.hasNewMessages
? 0
: (unreadBubbleSize - 9) *
room.notificationCount.toString().length +
9,
decoration: BoxDecoration(
color: room.highlightCount > 0
? Colors.red
: room.notificationCount > 0
? Theme.of(context).primaryColor
: Theme.of(context).primaryColor.withAlpha(100),
borderRadius: BorderRadius.circular(AppConfig.borderRadius),
),
child: Center(
child: room.notificationCount > 0
? Text(
room.notificationCount.toString(),
style: const TextStyle(
color: Colors.white,
fontSize: 13,
),
)
: Container(),
),
),
],
),
onTap: () => clickAction(context),
), ),
onTap: () => clickAction(context),
); );
} }
} }

View File

@ -1,5 +1,6 @@
import 'dart:async'; import 'dart:async';
import 'package:fluffychat/utils/contextual_actions.dart';
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
@ -25,214 +26,221 @@ class ChatListView extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return StreamBuilder<Object?>( return ContextualActions(
stream: Matrix.of(context).onShareContentChanged.stream, child: Builder(builder: (context) {
builder: (_, __) { return StreamBuilder<Object?>(
final selectMode = controller.selectMode; stream: Matrix.of(context).onShareContentChanged.stream,
return VWidgetGuard( builder: (context, __) {
onSystemPop: (redirector) async { final selectMode = controller.selectMode;
final selMode = controller.selectMode; if (selectMode == SelectMode.select) {
if (selMode != SelectMode.normal) controller.cancelAction(); ContextualActions.of(context).actions.addAll({
if (selMode == SelectMode.select) redirector.stopRedirection(); if (controller.spaces.isNotEmpty)
}, ContextualAction(
child: Scaffold( label: L10n.of(context)!.addToSpace,
appBar: AppBar( icon: const Icon(Icons.group_work_outlined),
elevation: controller.scrolledToTop ? 0 : null, action: controller.addOrRemoveToSpace,
actionsIconTheme: IconThemeData( ),
color: controller.selectedRoomIds.isEmpty ContextualAction(
? null label: L10n.of(context)!.toggleUnread,
: Theme.of(context).colorScheme.primary, icon: Icon(controller.anySelectedRoomNotMarkedUnread
? Icons.mark_chat_read_outlined
: Icons.mark_chat_unread_outlined),
action: controller.toggleUnread,
), ),
leading: selectMode == SelectMode.normal ContextualAction(
? Matrix.of(context).isMultiAccount label: L10n.of(context)!.toggleFavorite,
? ClientChooserButton(controller) icon: Icon(controller.anySelectedRoomNotFavorite
: null ? Icons.push_pin_outlined
: IconButton( : Icons.push_pin),
tooltip: L10n.of(context)!.cancel, action: controller.toggleFavouriteRoom,
icon: const Icon(Icons.close_outlined), ),
onPressed: controller.cancelAction, ContextualAction(
color: Theme.of(context).colorScheme.primary, icon: Icon(controller.anySelectedRoomNotMuted
), ? Icons.notifications_off_outlined
centerTitle: false, : Icons.notifications_outlined),
actions: selectMode == SelectMode.share label: L10n.of(context)!.toggleMuted,
? null action: controller.toggleMuted,
: selectMode == SelectMode.select ),
? [ ContextualAction(
if (controller.spaces.isNotEmpty) icon: const Icon(Icons.delete_outlined),
label: L10n.of(context)!.archive,
action: controller.archiveAction,
),
});
}
return VWidgetGuard(
onSystemPop: (redirector) async {
final selMode = controller.selectMode;
if (selMode != SelectMode.normal) controller.cancelAction();
if (selMode == SelectMode.select) redirector.stopRedirection();
},
child: Scaffold(
appBar: AppBar(
elevation: controller.scrolledToTop ? 0 : null,
actionsIconTheme: IconThemeData(
color: controller.selectedRoomIds.isEmpty
? null
: Theme.of(context).colorScheme.primary,
),
leading: selectMode == SelectMode.normal
? Matrix.of(context).isMultiAccount
? ClientChooserButton(controller)
: null
: IconButton(
tooltip: L10n.of(context)!.cancel,
icon: const Icon(Icons.close_outlined),
onPressed: controller.cancelAction,
color: Theme.of(context).colorScheme.primary,
),
centerTitle: false,
actions: selectMode == SelectMode.share
? null
: selectMode == SelectMode.select
? ContextualActions.of(context).buildAppBar()
: [
IconButton( IconButton(
tooltip: L10n.of(context)!.addToSpace, icon: const Icon(Icons.search_outlined),
icon: const Icon(Icons.group_work_outlined), tooltip: L10n.of(context)!.search,
onPressed: controller.addOrRemoveToSpace,
),
IconButton(
tooltip: L10n.of(context)!.toggleUnread,
icon: Icon(
controller.anySelectedRoomNotMarkedUnread
? Icons.mark_chat_read_outlined
: Icons.mark_chat_unread_outlined),
onPressed: controller.toggleUnread,
),
IconButton(
tooltip: L10n.of(context)!.toggleFavorite,
icon: Icon(controller.anySelectedRoomNotFavorite
? Icons.push_pin_outlined
: Icons.push_pin),
onPressed: controller.toggleFavouriteRoom,
),
IconButton(
icon: Icon(controller.anySelectedRoomNotMuted
? Icons.notifications_off_outlined
: Icons.notifications_outlined),
tooltip: L10n.of(context)!.toggleMuted,
onPressed: controller.toggleMuted,
),
IconButton(
icon: const Icon(Icons.delete_outlined),
tooltip: L10n.of(context)!.archive,
onPressed: controller.archiveAction,
),
]
: [
IconButton(
icon: const Icon(Icons.search_outlined),
tooltip: L10n.of(context)!.search,
onPressed: () =>
VRouter.of(context).to('/search'),
),
if (selectMode == SelectMode.normal)
IconButton(
icon: const Icon(Icons.camera_alt_outlined),
tooltip: L10n.of(context)!.addToStory,
onPressed: () => onPressed: () =>
VRouter.of(context).to('/stories/create'), VRouter.of(context).to('/search'),
), ),
PopupMenuButton<PopupMenuAction>( if (selectMode == SelectMode.normal)
onSelected: controller.onPopupMenuSelect, IconButton(
itemBuilder: (_) => [ icon: const Icon(Icons.camera_alt_outlined),
PopupMenuItem( tooltip: L10n.of(context)!.addToStory,
value: PopupMenuAction.setStatus, onPressed: () =>
child: Row( VRouter.of(context).to('/stories/create'),
mainAxisSize: MainAxisSize.min,
children: [
const Icon(Icons.edit_outlined),
const SizedBox(width: 12),
Text(L10n.of(context)!.setStatus),
],
),
), ),
PopupMenuItem( PopupMenuButton<PopupMenuAction>(
value: PopupMenuAction.newGroup, onSelected: controller.onPopupMenuSelect,
child: Row( itemBuilder: (_) => [
mainAxisSize: MainAxisSize.min, PopupMenuItem(
children: [ value: PopupMenuAction.setStatus,
const Icon(Icons.group_add_outlined), child: Row(
const SizedBox(width: 12), mainAxisSize: MainAxisSize.min,
Text(L10n.of(context)!.createNewGroup), children: [
], const Icon(Icons.edit_outlined),
const SizedBox(width: 12),
Text(L10n.of(context)!.setStatus),
],
),
), ),
), PopupMenuItem(
PopupMenuItem( value: PopupMenuAction.newGroup,
value: PopupMenuAction.newSpace, child: Row(
child: Row( mainAxisSize: MainAxisSize.min,
mainAxisSize: MainAxisSize.min, children: [
children: [ const Icon(Icons.group_add_outlined),
const Icon(Icons.group_work_outlined), const SizedBox(width: 12),
const SizedBox(width: 12), Text(L10n.of(context)!.createNewGroup),
Text(L10n.of(context)!.createNewSpace), ],
], ),
), ),
), PopupMenuItem(
PopupMenuItem( value: PopupMenuAction.newSpace,
value: PopupMenuAction.invite, child: Row(
child: Row( mainAxisSize: MainAxisSize.min,
mainAxisSize: MainAxisSize.min, children: [
children: [ const Icon(Icons.group_work_outlined),
const Icon(Icons.share_outlined), const SizedBox(width: 12),
const SizedBox(width: 12), Text(L10n.of(context)!.createNewSpace),
Text(L10n.of(context)!.inviteContact), ],
], ),
), ),
), PopupMenuItem(
PopupMenuItem( value: PopupMenuAction.invite,
value: PopupMenuAction.archive, child: Row(
child: Row( mainAxisSize: MainAxisSize.min,
mainAxisSize: MainAxisSize.min, children: [
children: [ const Icon(Icons.share_outlined),
const Icon(Icons.archive_outlined), const SizedBox(width: 12),
const SizedBox(width: 12), Text(L10n.of(context)!.inviteContact),
Text(L10n.of(context)!.archive), ],
], ),
), ),
), PopupMenuItem(
PopupMenuItem( value: PopupMenuAction.archive,
value: PopupMenuAction.settings, child: Row(
child: Row( mainAxisSize: MainAxisSize.min,
mainAxisSize: MainAxisSize.min, children: [
children: [ const Icon(Icons.archive_outlined),
const Icon(Icons.settings_outlined), const SizedBox(width: 12),
const SizedBox(width: 12), Text(L10n.of(context)!.archive),
Text(L10n.of(context)!.settings), ],
], ),
), ),
), PopupMenuItem(
], value: PopupMenuAction.settings,
), child: Row(
], mainAxisSize: MainAxisSize.min,
title: Text(selectMode == SelectMode.share children: [
? L10n.of(context)!.share const Icon(Icons.settings_outlined),
: selectMode == SelectMode.select const SizedBox(width: 12),
? controller.selectedRoomIds.length.toString() Text(L10n.of(context)!.settings),
: controller.activeSpaceId == null ],
? AppConfig.applicationName ),
: Matrix.of(context) ),
.client ],
.getRoomById(controller.activeSpaceId!)! ),
.displayname), ],
), title: Text(selectMode == SelectMode.share
body: Column(children: [ ? L10n.of(context)!.share
AnimatedContainer( : selectMode == SelectMode.select
height: controller.showChatBackupBanner ? 54 : 0, ? controller.selectedRoomIds.length.toString()
duration: const Duration(milliseconds: 300), : controller.activeSpaceId == null
clipBehavior: Clip.hardEdge, ? AppConfig.applicationName
curve: Curves.bounceInOut, : Matrix.of(context)
decoration: const BoxDecoration(), .client
child: Material( .getRoomById(controller.activeSpaceId!)!
color: Theme.of(context).colorScheme.surface, .displayname),
child: ListTile( ),
leading: Image.asset( body: Column(children: [
'assets/backup.png', AnimatedContainer(
fit: BoxFit.contain, height: controller.showChatBackupBanner ? 54 : 0,
width: 44, duration: const Duration(milliseconds: 300),
clipBehavior: Clip.hardEdge,
curve: Curves.bounceInOut,
decoration: const BoxDecoration(),
child: Material(
color: Theme.of(context).colorScheme.surface,
child: ListTile(
leading: Image.asset(
'assets/backup.png',
fit: BoxFit.contain,
width: 44,
),
title: Text(L10n.of(context)!.setupChatBackupNow),
trailing: const Icon(Icons.chevron_right_outlined),
onTap: controller.firstRunBootstrapAction,
), ),
title: Text(L10n.of(context)!.setupChatBackupNow),
trailing: const Icon(Icons.chevron_right_outlined),
onTap: controller.firstRunBootstrapAction,
), ),
), ),
Expanded(child: _ChatListViewBody(controller)),
]),
floatingActionButton: selectMode == SelectMode.normal
? FloatingActionButton.extended(
isExtended: controller.scrolledToTop,
onPressed: () =>
VRouter.of(context).to('/newprivatechat'),
icon: const Icon(CupertinoIcons.chat_bubble),
label: Text(L10n.of(context)!.newChat),
)
: null,
bottomNavigationBar: Column(
mainAxisSize: MainAxisSize.min,
children: [
const ConnectionStatusHeader(),
if (controller.spaces.isNotEmpty &&
controller.selectedRoomIds.isEmpty)
SpacesBottomBar(controller),
],
), ),
Expanded(child: _ChatListViewBody(controller)),
]),
floatingActionButton: selectMode == SelectMode.normal
? FloatingActionButton.extended(
isExtended: controller.scrolledToTop,
onPressed: () =>
VRouter.of(context).to('/newprivatechat'),
icon: const Icon(CupertinoIcons.chat_bubble),
label: Text(L10n.of(context)!.newChat),
)
: null,
bottomNavigationBar: Column(
mainAxisSize: MainAxisSize.min,
children: [
const ConnectionStatusHeader(),
if (controller.spaces.isNotEmpty &&
controller.selectedRoomIds.isEmpty)
SpacesBottomBar(controller),
],
), ),
), );
); },
}); );
}),
);
} }
} }

View File

@ -0,0 +1,78 @@
import 'package:flutter/material.dart';
class ContextualActions extends InheritedWidget {
final ContextualActionState _state = ContextualActionState();
ContextualActions({Key? key, required Widget child})
: super(key: key, child: child);
static ContextualActions of(BuildContext context) {
final ContextualActions? result =
context.dependOnInheritedWidgetOfExactType<ContextualActions>();
assert(result != null, 'No ContextualActions found in context');
return result!;
}
Set<ContextualAction> get actions => _state.actions;
set actions(Set<ContextualAction> actions) => _state.actions = actions;
List<Widget> buildAppBar() => _state.buildAppBar();
List<Widget> buildContextMenu(BuildContext context) =>
_state.buildContextMenu(context);
@override
bool updateShouldNotify(covariant ContextualActions oldWidget) =>
_state != oldWidget._state;
}
class ContextualActionState {
/// the currently set [ContextualActions]
///
/// use [replace] instead of `=` operator
Set<ContextualAction> actions = {};
Set<ContextualAction> contextMenuOnly = {};
/// unregisters all present actions and adds riven [newActions]
void replace(Iterable<ContextualAction> newActions) {
actions.removeWhere((element) => true);
actions.addAll(newActions);
}
/// buildseach item of [actions] as [IconButton] for use in AppBar
List<Widget> buildAppBar() {
return actions
.map(
(action) => IconButton(
icon: action.icon,
tooltip: action.label,
onPressed: action.action,
),
)
.toList();
}
/// builds each item of [actions] as [ListTile] for use in a [ContextMenuArea]
List<Widget> buildContextMenu(BuildContext context) {
return actions
.map(
(action) => ListTile(
leading: action.icon,
title: Text(action.label),
onTap: () {
Navigator.of(context).pop();
action.action.call();
},
),
)
.toList();
}
}
class ContextualAction {
final VoidCallback action;
final Widget icon;
final String label;
const ContextualAction(
{required this.action, required this.icon, required this.label});
}

View File

@ -22,6 +22,13 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.3.0" version: "2.3.0"
after_layout:
dependency: transitive
description:
name: after_layout
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.0"
analyzer: analyzer:
dependency: transitive dependency: transitive
description: description:
@ -241,6 +248,13 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.2.0" version: "1.2.0"
contextmenu:
dependency: "direct main"
description:
name: contextmenu
url: "https://pub.dartlang.org"
source: hosted
version: "3.0.0"
convert: convert:
dependency: transitive dependency: transitive
description: description:

View File

@ -18,6 +18,7 @@ dependencies:
chewie: ^1.2.2 chewie: ^1.2.2
collection: ^1.15.0-nullsafety.4 collection: ^1.15.0-nullsafety.4
connectivity_plus: ^2.2.0 connectivity_plus: ^2.2.0
contextmenu: ^3.0.0
cupertino_icons: any cupertino_icons: any
desktop_drop: ^0.3.2 desktop_drop: ^0.3.2
desktop_lifecycle: ^0.1.0 desktop_lifecycle: ^0.1.0

View File

@ -32,7 +32,7 @@
<link rel="stylesheet" type="text/css" href="splash/style.css"> <link rel="stylesheet" type="text/css" href="splash/style.css">
</head> </head>
<body style="position: fixed; inset: 0px; overflow: hidden; padding: 0px; margin: 0px; user-select: none; touch-action: none; font: 14px sans-serif; color: red;"> <body oncontextmenu="return false;" style="position: fixed; inset: 0px; overflow: hidden; padding: 0px; margin: 0px; user-select: none; touch-action: none; font: 14px sans-serif; color: red;">
<!-- This script installs service_worker.js to provide PWA functionality to <!-- This script installs service_worker.js to provide PWA functionality to
application. For more information, see: application. For more information, see:
https://developers.google.com/web/fundamentals/primers/service-workers --> https://developers.google.com/web/fundamentals/primers/service-workers -->