formatting

This commit is contained in:
Steef Hegeman 2021-05-26 20:50:15 +02:00
parent 24b632fc90
commit a67de58d9a
2 changed files with 868 additions and 838 deletions

View File

@ -33,8 +33,7 @@ class ChatListView extends StatelessWidget {
redirector.stopRedirection(); redirector.stopRedirection();
} }
}, },
child: child: Scaffold(
Scaffold(
appBar: AppBar( appBar: AppBar(
elevation: MediaQuery.of(context).size.width > elevation: MediaQuery.of(context).size.width >
FluffyThemes.columnWidth * 2 FluffyThemes.columnWidth * 2
@ -74,8 +73,8 @@ class ChatListView extends StatelessWidget {
IconButton( IconButton(
icon: Icon(Matrix.of(context) icon: Icon(Matrix.of(context)
.client .client
.getRoomById( .getRoomById(controller
controller.selectedRoomIds.single) .selectedRoomIds.single)
.pushRuleState == .pushRuleState ==
PushRuleState.notify PushRuleState.notify
? Icons.notifications_off_outlined ? Icons.notifications_off_outlined
@ -180,7 +179,8 @@ class ChatListView extends StatelessWidget {
if (snapshot.hasData) { if (snapshot.hasData) {
final rooms = List<Room>.from( final rooms = List<Room>.from(
Matrix.of(context).client.rooms); Matrix.of(context).client.rooms);
rooms.removeWhere((room) => room.lastEvent == null); rooms.removeWhere(
(room) => room.lastEvent == null);
if (rooms.isEmpty) { if (rooms.isEmpty) {
return Column( return Column(
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
@ -213,8 +213,8 @@ class ChatListView extends StatelessWidget {
selected: controller.selectedRoomIds selected: controller.selectedRoomIds
.contains(rooms[i].id), .contains(rooms[i].id),
onTap: selectMode == SelectMode.select onTap: selectMode == SelectMode.select
? () => ? () => controller
controller.toggleSelection(rooms[i].id) .toggleSelection(rooms[i].id)
: null, : null,
onLongPress: () => onLongPress: () =>
controller.toggleSelection(rooms[i].id), controller.toggleSelection(rooms[i].id),

View File

@ -61,8 +61,7 @@ class ChatView extends StatelessWidget {
redirector.stopRedirection(); redirector.stopRedirection();
} }
}, },
child: child: Scaffold(
Scaffold(
appBar: AppBar( appBar: AppBar(
leading: controller.selectMode leading: controller.selectMode
? IconButton( ? IconButton(
@ -76,8 +75,8 @@ class ChatView extends StatelessWidget {
? StreamBuilder( ? StreamBuilder(
stream: controller.room.onUpdate.stream, stream: controller.room.onUpdate.stream,
builder: (context, snapshot) => ListTile( builder: (context, snapshot) => ListTile(
leading: Avatar( leading: Avatar(controller.room.avatar,
controller.room.avatar, controller.room.displayname), controller.room.displayname),
contentPadding: EdgeInsets.zero, contentPadding: EdgeInsets.zero,
onTap: controller.room.isDirectChat onTap: controller.room.isDirectChat
? () => showModalBottomSheet( ? () => showModalBottomSheet(
@ -109,15 +108,17 @@ class ChatView extends StatelessWidget {
p.senderId == p.senderId ==
controller.room.directChatMatrixID), controller.room.directChatMatrixID),
builder: (context, snapshot) => Text( builder: (context, snapshot) => Text(
controller.room.getLocalizedStatus(context), controller.room
.getLocalizedStatus(context),
maxLines: 1, maxLines: 1,
//overflow: TextOverflow.ellipsis, //overflow: TextOverflow.ellipsis,
)) ))
: Row( : Row(
children: <Widget>[ children: <Widget>[
Icon(Icons.edit_outlined, Icon(Icons.edit_outlined,
color: color: Theme.of(context)
Theme.of(context).colorScheme.secondary, .colorScheme
.secondary,
size: 13), size: 13),
SizedBox(width: 4), SizedBox(width: 4),
Expanded( Expanded(
@ -136,13 +137,14 @@ class ChatView extends StatelessWidget {
], ],
), ),
)) ))
: Text(L10n.of(context) : Text(L10n.of(context).numberSelected(
.numberSelected(controller.selectedEvents.length.toString())), controller.selectedEvents.length.toString())),
actions: controller.selectMode actions: controller.selectMode
? <Widget>[ ? <Widget>[
if (controller.selectedEvents.length == 1 && if (controller.selectedEvents.length == 1 &&
controller.selectedEvents.first.status > 0 && controller.selectedEvents.first.status > 0 &&
controller.selectedEvents.first.senderId == client.userID) controller.selectedEvents.first.senderId ==
client.userID)
IconButton( IconButton(
icon: Icon(Icons.edit_outlined), icon: Icon(Icons.edit_outlined),
tooltip: L10n.of(context).edit, tooltip: L10n.of(context).edit,
@ -190,7 +192,8 @@ class ChatView extends StatelessWidget {
padding: const EdgeInsets.only(bottom: 56.0), padding: const EdgeInsets.only(bottom: 56.0),
child: FloatingActionButton( child: FloatingActionButton(
onPressed: controller.scrollDown, onPressed: controller.scrollDown,
foregroundColor: Theme.of(context).textTheme.bodyText2.color, foregroundColor:
Theme.of(context).textTheme.bodyText2.color,
backgroundColor: Theme.of(context).scaffoldBackgroundColor, backgroundColor: Theme.of(context).scaffoldBackgroundColor,
mini: true, mini: true,
child: Icon(Icons.arrow_downward_outlined, child: Icon(Icons.arrow_downward_outlined,
@ -211,7 +214,8 @@ class ChatView extends StatelessWidget {
child: Column( child: Column(
children: <Widget>[ children: <Widget>[
ConnectionStatusHeader(), ConnectionStatusHeader(),
if (controller.room.getState(EventTypes.RoomTombstone) != null) if (controller.room.getState(EventTypes.RoomTombstone) !=
null)
Container( Container(
height: 72, height: 72,
child: Material( child: Material(
@ -220,7 +224,8 @@ class ChatView extends StatelessWidget {
leading: CircleAvatar( leading: CircleAvatar(
foregroundColor: foregroundColor:
Theme.of(context).colorScheme.secondary, Theme.of(context).colorScheme.secondary,
backgroundColor: Theme.of(context).backgroundColor, backgroundColor:
Theme.of(context).backgroundColor,
child: Icon(Icons.upgrade_outlined), child: Icon(Icons.upgrade_outlined),
), ),
title: Text( title: Text(
@ -252,8 +257,8 @@ class ChatView extends StatelessWidget {
for (var i = 0; for (var i = 0;
i < controller.filteredEvents.length; i < controller.filteredEvents.length;
i++) { i++) {
thisEventsKeyMap[controller.filteredEvents[i].eventId] = thisEventsKeyMap[
i; controller.filteredEvents[i].eventId] = i;
} }
return ListView.custom( return ListView.custom(
@ -283,15 +288,16 @@ class ChatView extends StatelessWidget {
color: Theme.of(context) color: Theme.of(context)
.primaryColor, .primaryColor,
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
decoration: decoration: TextDecoration
TextDecoration.underline, .underline,
), ),
), ),
) )
: Container() : Container()
: i == 0 : i == 0
? StreamBuilder( ? StreamBuilder(
stream: controller.room.onUpdate.stream, stream:
controller.room.onUpdate.stream,
builder: (_, __) { builder: (_, __) {
final seenByText = controller.room final seenByText = controller.room
.getLocalizedSeenByText( .getLocalizedSeenByText(
@ -301,12 +307,16 @@ class ChatView extends StatelessWidget {
controller.unfolded, controller.unfolded,
); );
return AnimatedContainer( return AnimatedContainer(
height: seenByText.isEmpty ? 0 : 24, height:
seenByText.isEmpty ? 0 : 24,
duration: seenByText.isEmpty duration: seenByText.isEmpty
? Duration(milliseconds: 0) ? Duration(milliseconds: 0)
: Duration(milliseconds: 300), : Duration(
alignment: controller.filteredEvents milliseconds: 300),
.first.senderId == alignment: controller
.filteredEvents
.first
.senderId ==
client.userID client.userID
? Alignment.topRight ? Alignment.topRight
: Alignment.topLeft, : Alignment.topLeft,
@ -323,12 +333,14 @@ class ChatView extends StatelessWidget {
.scaffoldBackgroundColor .scaffoldBackgroundColor
.withOpacity(0.8), .withOpacity(0.8),
borderRadius: borderRadius:
BorderRadius.circular(4), BorderRadius.circular(
4),
), ),
child: Text( child: Text(
seenByText, seenByText,
maxLines: 1, maxLines: 1,
overflow: TextOverflow.ellipsis, overflow:
TextOverflow.ellipsis,
style: TextStyle( style: TextStyle(
color: Theme.of(context) color: Theme.of(context)
.colorScheme .colorScheme
@ -343,24 +355,30 @@ class ChatView extends StatelessWidget {
key: ValueKey(controller key: ValueKey(controller
.filteredEvents[i - 1].eventId), .filteredEvents[i - 1].eventId),
index: i - 1, index: i - 1,
controller: controller.scrollController, controller:
controller.scrollController,
child: Swipeable( child: Swipeable(
key: ValueKey(controller key: ValueKey(controller
.filteredEvents[i - 1].eventId), .filteredEvents[i - 1]
.eventId),
background: Padding( background: Padding(
padding: EdgeInsets.symmetric( padding: EdgeInsets.symmetric(
horizontal: 12.0), horizontal: 12.0),
child: Center( child: Center(
child: Icon(Icons.reply_outlined), child: Icon(
Icons.reply_outlined),
), ),
), ),
direction: SwipeDirection.endToStart, direction:
SwipeDirection.endToStart,
onSwipe: (direction) => onSwipe: (direction) =>
controller.replyAction( controller.replyAction(
replyTo: controller replyTo: controller
.filteredEvents[i - 1]), .filteredEvents[
i - 1]),
child: Message( child: Message(
controller.filteredEvents[i - 1], controller
.filteredEvents[i - 1],
onAvatarTab: (Event event) => onAvatarTab: (Event event) =>
showModalBottomSheet( showModalBottomSheet(
context: context, context: context,
@ -375,28 +393,29 @@ class ChatView extends StatelessWidget {
), ),
), ),
unfold: controller.unfold, unfold: controller.unfold,
onSelect: onSelect: controller
controller.onSelectMessage, .onSelectMessage,
scrollToEventId: scrollToEventId: (String eventId) =>
(String eventId) => controller controller.scrollToEventId(
.scrollToEventId(eventId), eventId),
longPressSelect: controller longPressSelect: controller
.selectedEvents.isEmpty, .selectedEvents.isEmpty,
selected: controller selected: controller
.selectedEvents .selectedEvents
.contains(controller .contains(
.filteredEvents[i - 1]), controller.filteredEvents[
i - 1]),
timeline: controller.timeline, timeline: controller.timeline,
nextEvent: i >= 2 nextEvent: i >= 2
? controller ? controller.filteredEvents[i - 2]
.filteredEvents[i - 2]
: null), : null),
), ),
); );
}, },
childCount: controller.filteredEvents.length + 2, childCount: controller.filteredEvents.length + 2,
findChildIndexCallback: (key) => controller findChildIndexCallback: (key) =>
.findChildIndexCallback(key, thisEventsKeyMap), controller.findChildIndexCallback(
key, thisEventsKeyMap),
), ),
); );
}, },
@ -422,15 +441,17 @@ class ChatView extends StatelessWidget {
final emojis = List<String>.from(AppEmojis.emojis); final emojis = List<String>.from(AppEmojis.emojis);
final allReactionEvents = controller final allReactionEvents = controller
.selectedEvents.first .selectedEvents.first
.aggregatedEvents( .aggregatedEvents(controller.timeline,
controller.timeline, RelationshipTypes.reaction) RelationshipTypes.reaction)
?.where((event) => ?.where((event) =>
event.senderId == event.room.client.userID && event.senderId ==
event.room.client.userID &&
event.type == 'm.reaction'); event.type == 'm.reaction');
allReactionEvents.forEach((event) { allReactionEvents.forEach((event) {
try { try {
emojis.remove(event.content['m.relates_to']['key']); emojis.remove(
event.content['m.relates_to']['key']);
} catch (_) {} } catch (_) {}
}); });
return ListView.builder( return ListView.builder(
@ -514,7 +535,8 @@ class ChatView extends StatelessWidget {
onPressed: controller.forwardEventsAction, onPressed: controller.forwardEventsAction,
child: Row( child: Row(
children: <Widget>[ children: <Widget>[
Icon(Icons.keyboard_arrow_left_outlined), Icon(Icons
.keyboard_arrow_left_outlined),
Text(L10n.of(context).forward), Text(L10n.of(context).forward),
], ],
), ),
@ -529,12 +551,14 @@ class ChatView extends StatelessWidget {
? Container( ? Container(
height: 56, height: 56,
child: TextButton( child: TextButton(
onPressed: controller.replyAction, onPressed:
controller.replyAction,
child: Row( child: Row(
children: <Widget>[ children: <Widget>[
Text(L10n.of(context).reply), Text(
Icon( L10n.of(context).reply),
Icons.keyboard_arrow_right), Icon(Icons
.keyboard_arrow_right),
], ],
), ),
), ),
@ -561,14 +585,15 @@ class ChatView extends StatelessWidget {
AnimatedContainer( AnimatedContainer(
duration: Duration(milliseconds: 200), duration: Duration(milliseconds: 200),
height: 56, height: 56,
width: controller.inputText.isEmpty ? 56 : 0, width:
controller.inputText.isEmpty ? 56 : 0,
alignment: Alignment.center, alignment: Alignment.center,
clipBehavior: Clip.hardEdge, clipBehavior: Clip.hardEdge,
decoration: BoxDecoration(), decoration: BoxDecoration(),
child: PopupMenuButton<String>( child: PopupMenuButton<String>(
icon: Icon(Icons.add_outlined), icon: Icon(Icons.add_outlined),
onSelected: onSelected: controller
controller.onAddPopupMenuButtonSelected, .onAddPopupMenuButtonSelected,
itemBuilder: (BuildContext context) => itemBuilder: (BuildContext context) =>
<PopupMenuEntry<String>>[ <PopupMenuEntry<String>>[
PopupMenuItem<String>( PopupMenuItem<String>(
@ -577,10 +602,11 @@ class ChatView extends StatelessWidget {
leading: CircleAvatar( leading: CircleAvatar(
backgroundColor: Colors.green, backgroundColor: Colors.green,
foregroundColor: Colors.white, foregroundColor: Colors.white,
child: child: Icon(
Icon(Icons.attachment_outlined), Icons.attachment_outlined),
), ),
title: Text(L10n.of(context).sendFile), title:
Text(L10n.of(context).sendFile),
contentPadding: EdgeInsets.all(0), contentPadding: EdgeInsets.all(0),
), ),
), ),
@ -592,7 +618,8 @@ class ChatView extends StatelessWidget {
foregroundColor: Colors.white, foregroundColor: Colors.white,
child: Icon(Icons.image_outlined), child: Icon(Icons.image_outlined),
), ),
title: Text(L10n.of(context).sendImage), title: Text(
L10n.of(context).sendImage),
contentPadding: EdgeInsets.all(0), contentPadding: EdgeInsets.all(0),
), ),
), ),
@ -603,11 +630,11 @@ class ChatView extends StatelessWidget {
leading: CircleAvatar( leading: CircleAvatar(
backgroundColor: Colors.purple, backgroundColor: Colors.purple,
foregroundColor: Colors.white, foregroundColor: Colors.white,
child: child: Icon(
Icon(Icons.camera_alt_outlined), Icons.camera_alt_outlined),
), ),
title: title: Text(
Text(L10n.of(context).openCamera), L10n.of(context).openCamera),
contentPadding: EdgeInsets.all(0), contentPadding: EdgeInsets.all(0),
), ),
), ),
@ -618,11 +645,11 @@ class ChatView extends StatelessWidget {
leading: CircleAvatar( leading: CircleAvatar(
backgroundColor: Colors.red, backgroundColor: Colors.red,
foregroundColor: Colors.white, foregroundColor: Colors.white,
child: child: Icon(
Icon(Icons.mic_none_outlined), Icons.mic_none_outlined),
), ),
title: Text( title: Text(L10n.of(context)
L10n.of(context).voiceMessage), .voiceMessage),
contentPadding: EdgeInsets.all(0), contentPadding: EdgeInsets.all(0),
), ),
), ),
@ -636,8 +663,8 @@ class ChatView extends StatelessWidget {
), ),
Expanded( Expanded(
child: Padding( child: Padding(
padding: padding: const EdgeInsets.symmetric(
const EdgeInsets.symmetric(vertical: 4.0), vertical: 4.0),
child: InputBar( child: InputBar(
room: controller.room, room: controller.room,
minLines: 1, minLines: 1,
@ -646,11 +673,13 @@ class ChatView extends StatelessWidget {
keyboardType: !PlatformInfos.isMobile keyboardType: !PlatformInfos.isMobile
? TextInputType.text ? TextInputType.text
: TextInputType.multiline, : TextInputType.multiline,
onSubmitted: controller.onInputBarSubmitted, onSubmitted:
controller.onInputBarSubmitted,
focusNode: controller.inputFocus, focusNode: controller.inputFocus,
controller: controller.sendController, controller: controller.sendController,
decoration: InputDecoration( decoration: InputDecoration(
hintText: L10n.of(context).writeAMessage, hintText:
L10n.of(context).writeAMessage,
hintMaxLines: 1, hintMaxLines: 1,
border: InputBorder.none, border: InputBorder.none,
enabledBorder: InputBorder.none, enabledBorder: InputBorder.none,
@ -668,7 +697,8 @@ class ChatView extends StatelessWidget {
child: IconButton( child: IconButton(
tooltip: L10n.of(context).voiceMessage, tooltip: L10n.of(context).voiceMessage,
icon: Icon(Icons.mic_none_outlined), icon: Icon(Icons.mic_none_outlined),
onPressed: controller.voiceMessageAction, onPressed:
controller.voiceMessageAction,
), ),
), ),
if (!PlatformInfos.isMobile || if (!PlatformInfos.isMobile ||