feat: Implement mouse select chat list items
This commit is contained in:
parent
525fa8320a
commit
380e09489f
5 changed files with 82 additions and 38 deletions
|
|
@ -1,4 +1,5 @@
|
|||
import 'package:bot_toast/bot_toast.dart';
|
||||
import 'package:circular_check_box/circular_check_box.dart';
|
||||
import 'package:famedlysdk/famedlysdk.dart';
|
||||
import 'package:fluffychat/utils/matrix_locals.dart';
|
||||
import 'package:fluffychat/views/chat.dart';
|
||||
|
|
@ -13,6 +14,7 @@ import '../avatar.dart';
|
|||
import '../dialogs/send_file_dialog.dart';
|
||||
import '../dialogs/simple_dialogs.dart';
|
||||
import '../matrix.dart';
|
||||
import '../mouse_over_builder.dart';
|
||||
import '../theme_switcher.dart';
|
||||
|
||||
class ChatListItem extends StatelessWidget {
|
||||
|
|
@ -128,7 +130,20 @@ class ChatListItem extends StatelessWidget {
|
|||
color: chatListItemColor(context, activeChat, selected),
|
||||
child: ListTile(
|
||||
onLongPress: onLongPress,
|
||||
leading: Avatar(room.avatar, room.displayname),
|
||||
leading: MouseOverBuilder(
|
||||
builder: (context, hover) =>
|
||||
onLongPress != null && (hover || selected)
|
||||
? Container(
|
||||
width: Avatar.defaultSize,
|
||||
height: Avatar.defaultSize,
|
||||
alignment: Alignment.center,
|
||||
child: CircularCheckBox(
|
||||
value: selected,
|
||||
onChanged: (_) => onLongPress(),
|
||||
),
|
||||
)
|
||||
: Avatar(room.avatar, room.displayname),
|
||||
),
|
||||
title: Row(
|
||||
children: <Widget>[
|
||||
Expanded(
|
||||
|
|
|
|||
28
lib/components/mouse_over_builder.dart
Normal file
28
lib/components/mouse_over_builder.dart
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
import 'package:flutter/material.dart';
|
||||
|
||||
class MouseOverBuilder extends StatefulWidget {
|
||||
final Function(BuildContext, bool) builder;
|
||||
|
||||
const MouseOverBuilder({Key key, this.builder}) : super(key: key);
|
||||
@override
|
||||
_MouseOverBuilderState createState() => _MouseOverBuilderState();
|
||||
}
|
||||
|
||||
class _MouseOverBuilderState extends State<MouseOverBuilder> {
|
||||
bool _hover = false;
|
||||
|
||||
void _toggleHover(bool hover) {
|
||||
if (_hover != hover) {
|
||||
setState(() => _hover = hover);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return MouseRegion(
|
||||
onEnter: (_) => _toggleHover(true),
|
||||
onExit: (_) => _toggleHover(false),
|
||||
child: widget.builder != null ? widget.builder(context, _hover) : null,
|
||||
);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue