chore: Fix chat list regressions

This commit is contained in:
Krille Fear 2021-12-30 09:50:41 +01:00
parent b0e566c0a3
commit c1a0cb3f8d
2 changed files with 87 additions and 129 deletions

View File

@ -2182,7 +2182,7 @@
"senderName": {} "senderName": {}
} }
}, },
"startYourFirstChat": "Start your first chat right now! 🙂\n- Tap on the message button\n- Enter the username of a friend\n- Have fun chatting", "startYourFirstChat": "Start your first chat right now! 🙂\n- Tap on 'New chat'\n- Scan the QR code of a friend\n- Have fun chatting",
"@startYourFirstChat": { "@startYourFirstChat": {
"type": "text", "type": "text",
"placeholders": {} "placeholders": {}

View File

@ -1,5 +1,4 @@
import 'dart:async'; import 'dart:async';
import 'dart:math';
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
@ -284,10 +283,10 @@ class _ChatListViewBodyState extends State<_ChatListViewBody> {
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
children: <Widget>[ children: <Widget>[
const Icon( Image.asset(
Icons.maps_ugc_outlined, 'assets/private_chat_wallpaper.png',
size: 80, width: 160,
color: Colors.grey, height: 160,
), ),
Center( Center(
child: Text( child: Text(
@ -301,37 +300,90 @@ class _ChatListViewBodyState extends State<_ChatListViewBody> {
), ),
], ],
); );
} } else {
final displayStoriesHeader = widget.controller.activeSpaceId == null; final displayStoriesHeader = widget.controller.activeSpaceId == null;
child = ListView.builder( child = ListView.builder(
key: ValueKey(Matrix.of(context).client.userID.toString() + key: ValueKey(Matrix.of(context).client.userID.toString() +
widget.controller.activeSpaceId.toString()), widget.controller.activeSpaceId.toString()),
controller: widget.controller.scrollController, controller: widget.controller.scrollController,
itemCount: rooms.length + (displayStoriesHeader ? 1 : 0), itemCount: rooms.length + (displayStoriesHeader ? 1 : 0),
itemBuilder: (BuildContext context, int i) { itemBuilder: (BuildContext context, int i) {
if (displayStoriesHeader) { if (displayStoriesHeader) {
if (i == 0) { if (i == 0) {
return const StoriesHeader(); return const StoriesHeader();
}
i--;
} }
i--; return ChatListItem(
} rooms[i],
return ChatListItem( selected: widget.controller.selectedRoomIds.contains(rooms[i].id),
rooms[i], onTap: widget.controller.selectMode == SelectMode.select
selected: widget.controller.selectedRoomIds.contains(rooms[i].id), ? () => widget.controller.toggleSelection(rooms[i].id)
onTap: widget.controller.selectMode == SelectMode.select : null,
? () => widget.controller.toggleSelection(rooms[i].id) onLongPress: () => widget.controller.toggleSelection(rooms[i].id),
: null, activeChat: widget.controller.activeChat == rooms[i].id,
onLongPress: () => widget.controller.toggleSelection(rooms[i].id), );
activeChat: widget.controller.activeChat == rooms[i].id, },
); );
}, }
);
} else { } else {
child = ListView( const dummyChatCount = 8;
key: const ValueKey(false), final titleColor =
children: List.filled( Theme.of(context).textTheme.bodyText1.color.withAlpha(100);
8, final subtitleColor =
const _DummyChat(), Theme.of(context).textTheme.bodyText1.color.withAlpha(50);
child = ListView.builder(
itemCount: dummyChatCount,
itemBuilder: (context, i) => Opacity(
opacity: (dummyChatCount - i) / dummyChatCount,
child: ListTile(
leading: CircleAvatar(
backgroundColor: titleColor,
child: CircularProgressIndicator(
strokeWidth: 1,
color: Theme.of(context).textTheme.bodyText1.color,
),
),
title: Row(
children: [
Expanded(
child: Container(
height: 14,
decoration: BoxDecoration(
color: titleColor,
borderRadius: BorderRadius.circular(3),
),
),
),
const SizedBox(width: 36),
Container(
height: 14,
width: 14,
decoration: BoxDecoration(
color: subtitleColor,
borderRadius: BorderRadius.circular(14),
),
),
const SizedBox(width: 12),
Container(
height: 14,
width: 14,
decoration: BoxDecoration(
color: subtitleColor,
borderRadius: BorderRadius.circular(14),
),
),
],
),
subtitle: Container(
decoration: BoxDecoration(
color: subtitleColor,
borderRadius: BorderRadius.circular(3),
),
height: 12,
margin: const EdgeInsets.only(right: 22),
),
),
), ),
); );
} }
@ -389,100 +441,6 @@ class _ChatListViewBodyState extends State<_ChatListViewBody> {
} }
} }
class _DummyChat extends StatefulWidget {
const _DummyChat({Key key}) : super(key: key);
@override
State<_DummyChat> createState() => _DummyChatState();
}
class _DummyChatState extends State<_DummyChat> {
double opacity = Random().nextDouble();
Timer _timer;
static const duration = Duration(seconds: 1);
void _setRandomOpacity(_) {
if (mounted) {
setState(() => opacity = Random().nextDouble());
}
}
@override
void initState() {
WidgetsBinding.instance.addPostFrameCallback(_setRandomOpacity);
_timer ??= Timer.periodic(duration, _setRandomOpacity);
super.initState();
}
@override
void dispose() {
_timer?.cancel();
super.dispose();
}
@override
Widget build(BuildContext context) {
final titleColor =
Theme.of(context).textTheme.bodyText1.color.withAlpha(100);
final subtitleColor =
Theme.of(context).textTheme.bodyText1.color.withAlpha(50);
return AnimatedOpacity(
opacity: opacity,
duration: duration,
child: ListTile(
leading: CircleAvatar(
backgroundColor: titleColor,
child: CircularProgressIndicator(
strokeWidth: 1,
color: Theme.of(context).textTheme.bodyText1.color,
),
),
title: Row(
children: [
Expanded(
child: Container(
height: 14,
decoration: BoxDecoration(
color: titleColor,
borderRadius: BorderRadius.circular(3),
),
),
),
const SizedBox(width: 36),
Container(
height: 14,
width: 14,
decoration: BoxDecoration(
color: subtitleColor,
borderRadius: BorderRadius.circular(14),
),
),
const SizedBox(width: 12),
Container(
height: 14,
width: 14,
decoration: BoxDecoration(
color: subtitleColor,
borderRadius: BorderRadius.circular(14),
),
),
],
),
subtitle: Container(
decoration: BoxDecoration(
color: subtitleColor,
borderRadius: BorderRadius.circular(3),
),
height: 12,
margin: const EdgeInsets.only(right: 22),
),
),
);
}
}
enum ChatListPopupMenuItemActions { enum ChatListPopupMenuItemActions {
createGroup, createGroup,
createSpace, createSpace,