Merge branch 'krille/implement-hover-select' into 'main'

feat: Implement mouse select chat list items

See merge request ChristianPauly/fluffychat-flutter!228
This commit is contained in:
Christian Pauly 2020-10-17 09:28:33 +00:00
commit 12cfc6a5f4
5 changed files with 82 additions and 38 deletions

View file

@ -1,4 +1,5 @@
import 'package:bot_toast/bot_toast.dart'; import 'package:bot_toast/bot_toast.dart';
import 'package:circular_check_box/circular_check_box.dart';
import 'package:famedlysdk/famedlysdk.dart'; import 'package:famedlysdk/famedlysdk.dart';
import 'package:fluffychat/utils/matrix_locals.dart'; import 'package:fluffychat/utils/matrix_locals.dart';
import 'package:fluffychat/views/chat.dart'; import 'package:fluffychat/views/chat.dart';
@ -13,6 +14,7 @@ import '../avatar.dart';
import '../dialogs/send_file_dialog.dart'; import '../dialogs/send_file_dialog.dart';
import '../dialogs/simple_dialogs.dart'; import '../dialogs/simple_dialogs.dart';
import '../matrix.dart'; import '../matrix.dart';
import '../mouse_over_builder.dart';
import '../theme_switcher.dart'; import '../theme_switcher.dart';
class ChatListItem extends StatelessWidget { class ChatListItem extends StatelessWidget {
@ -128,7 +130,20 @@ class ChatListItem extends StatelessWidget {
color: chatListItemColor(context, activeChat, selected), color: chatListItemColor(context, activeChat, selected),
child: ListTile( child: ListTile(
onLongPress: onLongPress, 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( title: Row(
children: <Widget>[ children: <Widget>[
Expanded( Expanded(

View 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,
);
}
}

View file

@ -420,9 +420,7 @@ class _ChatListState extends State<ChatList> {
), ),
), ),
), ),
floatingActionButton: floatingActionButton: AdaptivePageLayout.columnMode(context)
(AdaptivePageLayout.columnMode(context) ||
selectMode != SelectMode.normal)
? null ? null
: Column( : Column(
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
@ -441,8 +439,7 @@ class _ChatListState extends State<ChatList> {
SizedBox(height: 16.0), SizedBox(height: 16.0),
FloatingActionButton( FloatingActionButton(
child: Icon(Icons.add), child: Icon(Icons.add),
backgroundColor: backgroundColor: Theme.of(context).primaryColor,
Theme.of(context).primaryColor,
onPressed: () => Navigator.of(context) onPressed: () => Navigator.of(context)
.pushAndRemoveUntil( .pushAndRemoveUntil(
AppRoute.defaultRoute( AppRoute.defaultRoute(
@ -532,11 +529,7 @@ class _ChatListState extends State<ChatList> {
(BuildContext context, int i) { (BuildContext context, int i) {
if (i == 0) { if (i == 0) {
final displayPresences = final displayPresences =
Matrix.of(context) selectMode != SelectMode.share;
.userStatuses
.isNotEmpty &&
selectMode ==
SelectMode.normal;
final displayShareStatus = final displayShareStatus =
selectMode == selectMode ==
SelectMode.share && SelectMode.share &&

View file

@ -99,6 +99,13 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.2.0-nullsafety.1" version: "1.2.0-nullsafety.1"
circular_check_box:
dependency: "direct main"
description:
name: circular_check_box
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.4"
cli_util: cli_util:
dependency: transitive dependency: transitive
description: description:
@ -526,7 +533,7 @@ packages:
name: meta name: meta
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.3.0-nullsafety.3" version: "1.3.0-nullsafety.4"
mime: mime:
dependency: transitive dependency: transitive
description: description:
@ -862,7 +869,7 @@ packages:
name: stack_trace name: stack_trace
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.10.0-nullsafety.1" version: "1.10.0-nullsafety.2"
stream_channel: stream_channel:
dependency: transitive dependency: transitive
description: description:

View file

@ -60,6 +60,7 @@ dependencies:
flutter_olm: ^1.0.1 flutter_olm: ^1.0.1
intl: ^0.16.1 intl: ^0.16.1
intl_translation: ^0.17.9 intl_translation: ^0.17.9
circular_check_box: ^1.0.4
flutter_localizations: flutter_localizations:
sdk: flutter sdk: flutter
sqflite: ^1.1.7 # Still used to obtain the database location sqflite: ^1.1.7 # Still used to obtain the database location