refactor: Added and applied require_trailing_commas linter rule

This commit is contained in:
Malin Errenst 2023-03-02 10:57:52 +01:00
commit ec7acc5385
112 changed files with 3466 additions and 2855 deletions

View file

@ -69,7 +69,8 @@ class AudioPlayerState extends State<AudioPlayerWidget> {
if (!kIsWeb) {
final tempDir = await getTemporaryDirectory();
final fileName = Uri.encodeComponent(
widget.event.attachmentOrThumbnailMxcUrl()!.pathSegments.last);
widget.event.attachmentOrThumbnailMxcUrl()!.pathSegments.last,
);
file = File('${tempDir.path}/${fileName}_${matrixFile.name}');
await file.writeAsBytes(matrixFile.bytes);
}
@ -224,23 +225,27 @@ class AudioPlayerState extends State<AudioPlayerWidget> {
for (var i = 0; i < AudioPlayerWidget.wavesCount; i++)
Expanded(
child: InkWell(
onTap: () => audioPlayer?.seek(Duration(
onTap: () => audioPlayer?.seek(
Duration(
milliseconds:
(maxPosition / AudioPlayerWidget.wavesCount)
.round() *
i)),
i,
),
),
child: Container(
height: 32,
alignment: Alignment.center,
child: Opacity(
opacity: currentPosition > i ? 1 : 0.5,
child: Container(
margin: const EdgeInsets.symmetric(horizontal: 1),
decoration: BoxDecoration(
color: widget.color,
borderRadius: BorderRadius.circular(64),
),
height: 32 * (waveform[i] / 1024)),
margin: const EdgeInsets.symmetric(horizontal: 1),
decoration: BoxDecoration(
color: widget.color,
borderRadius: BorderRadius.circular(64),
),
height: 32 * (waveform[i] / 1024),
),
),
),
),

View file

@ -38,9 +38,14 @@ class HtmlMessage extends StatelessWidget {
// miss-matching tags, and this way we actually correctly identify what we want to strip and, well,
// strip it.
final renderHtml = html.replaceAll(
RegExp('<mx-reply>.*</mx-reply>',
caseSensitive: false, multiLine: false, dotAll: true),
'');
RegExp(
'<mx-reply>.*</mx-reply>',
caseSensitive: false,
multiLine: false,
dotAll: true,
),
'',
);
// there is no need to pre-validate the html, as we validate it while rendering
@ -61,8 +66,12 @@ class HtmlMessage extends StatelessWidget {
maxLines: maxLines,
onLinkTap: (url) => UrlLauncher(context, url).launchUrl(),
onPillTap: (url) => UrlLauncher(context, url).launchUrl(),
getMxcUrl: (String mxc, double? width, double? height,
{bool? animated = false}) {
getMxcUrl: (
String mxc,
double? width,
double? height, {
bool? animated = false,
}) {
final ratio = MediaQuery.of(context).devicePixelRatio;
return Uri.parse(mxc)
.getThumbnail(
@ -75,19 +84,23 @@ class HtmlMessage extends StatelessWidget {
.toString();
},
onImageTap: (String mxc) => showDialog(
context: Matrix.of(context).navigatorContext,
useRootNavigator: false,
builder: (_) => ImageViewer(Event(
type: EventTypes.Message,
content: <String, dynamic>{
'body': mxc,
'url': mxc,
'msgtype': MessageTypes.Image,
},
senderId: room.client.userID!,
originServerTs: DateTime.now(),
eventId: 'fake_event',
room: room))),
context: Matrix.of(context).navigatorContext,
useRootNavigator: false,
builder: (_) => ImageViewer(
Event(
type: EventTypes.Message,
content: <String, dynamic>{
'body': mxc,
'url': mxc,
'msgtype': MessageTypes.Image,
},
senderId: room.client.userID!,
originServerTs: DateTime.now(),
eventId: 'fake_event',
room: room,
),
),
),
setCodeLanguage: (String key, String value) async {
await matrix.store.setItem('${SettingKeys.codeLanguage}.$key', value);
},

View file

@ -27,18 +27,19 @@ class Message extends StatelessWidget {
final bool selected;
final Timeline timeline;
const Message(this.event,
{this.nextEvent,
this.longPressSelect = false,
this.onSelect,
this.onInfoTab,
this.onAvatarTab,
this.scrollToEventId,
required this.onSwipe,
this.selected = false,
required this.timeline,
Key? key})
: super(key: key);
const Message(
this.event, {
this.nextEvent,
this.longPressSelect = false,
this.onSelect,
this.onInfoTab,
this.onAvatarTab,
this.scrollToEventId,
required this.onSwipe,
this.selected = false,
required this.timeline,
Key? key,
}) : super(key: key);
/// Indicates wheither the user may use a mouse instead
/// of touchscreen.
@ -126,13 +127,15 @@ class Message extends StatelessWidget {
height: 16 * AppConfig.bubbleSizeFactor,
child: event.status == EventStatus.sending
? const CircularProgressIndicator.adaptive(
strokeWidth: 2)
strokeWidth: 2,
)
: event.status == EventStatus.error
? const Icon(Icons.error, color: Colors.red)
: null,
),
),
))
),
)
: FutureBuilder<User?>(
future: event.fetchSenderUser(),
builder: (context, snapshot) {
@ -142,7 +145,8 @@ class Message extends StatelessWidget {
name: user.calcDisplayname(),
onTap: () => onAvatarTab!(event),
);
}),
},
),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
@ -171,7 +175,8 @@ class Message extends StatelessWidget {
: displayname.lightColorText),
),
);
}),
},
),
),
Container(
alignment: alignment,
@ -198,7 +203,8 @@ class Message extends StatelessWidget {
? EdgeInsets.zero
: EdgeInsets.all(16 * AppConfig.bubbleSizeFactor),
constraints: const BoxConstraints(
maxWidth: FluffyThemes.columnWidth * 1.5),
maxWidth: FluffyThemes.columnWidth * 1.5,
),
child: Stack(
children: <Widget>[
Column(
@ -233,11 +239,14 @@ class Message extends StatelessWidget {
child: AbsorbPointer(
child: Container(
margin: EdgeInsets.symmetric(
vertical: 4.0 *
AppConfig.bubbleSizeFactor),
child: ReplyContent(replyEvent,
ownMessage: ownMessage,
timeline: timeline),
vertical:
4.0 * AppConfig.bubbleSizeFactor,
),
child: ReplyContent(
replyEvent,
ownMessage: ownMessage,
timeline: timeline,
),
),
),
);
@ -249,10 +258,13 @@ class Message extends StatelessWidget {
onInfoTab: onInfoTab,
),
if (event.hasAggregatedEvents(
timeline, RelationshipTypes.edit))
timeline,
RelationshipTypes.edit,
))
Padding(
padding: EdgeInsets.only(
top: 4.0 * AppConfig.bubbleSizeFactor),
top: 4.0 * AppConfig.bubbleSizeFactor,
),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
@ -301,26 +313,29 @@ class Message extends StatelessWidget {
Padding(
padding: displayTime
? EdgeInsets.symmetric(
vertical: 8.0 * AppConfig.bubbleSizeFactor)
vertical: 8.0 * AppConfig.bubbleSizeFactor,
)
: EdgeInsets.zero,
child: Center(
child: Material(
color: displayTime
? Theme.of(context).colorScheme.background
: Theme.of(context)
.colorScheme
.background
.withOpacity(0.33),
borderRadius: BorderRadius.circular(AppConfig.borderRadius / 2),
clipBehavior: Clip.antiAlias,
child: Padding(
padding: const EdgeInsets.all(6.0),
child: Text(
event.originServerTs.localizedTime(context),
style: TextStyle(fontSize: 14 * AppConfig.fontSizeFactor),
child: Material(
color: displayTime
? Theme.of(context).colorScheme.background
: Theme.of(context)
.colorScheme
.background
.withOpacity(0.33),
borderRadius:
BorderRadius.circular(AppConfig.borderRadius / 2),
clipBehavior: Clip.antiAlias,
child: Padding(
padding: const EdgeInsets.all(6.0),
child: Text(
event.originServerTs.localizedTime(context),
style: TextStyle(fontSize: 14 * AppConfig.fontSizeFactor),
),
),
),
)),
),
),
row,
if (event.hasAggregatedEvents(timeline, RelationshipTypes.reaction))

View file

@ -27,21 +27,27 @@ class MessageContent extends StatelessWidget {
final Color textColor;
final void Function(Event)? onInfoTab;
const MessageContent(this.event,
{this.onInfoTab, Key? key, required this.textColor})
: super(key: key);
const MessageContent(
this.event, {
this.onInfoTab,
Key? key,
required this.textColor,
}) : super(key: key);
void _verifyOrRequestKey(BuildContext context) async {
final l10n = L10n.of(context)!;
if (event.content['can_request_session'] != true) {
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(
event.type == EventTypes.Encrypted
? l10n.needPantalaimonWarning
: event.calcLocalizedBodyFallback(
MatrixLocals(l10n),
),
)));
event.type == EventTypes.Encrypted
? l10n.needPantalaimonWarning
: event.calcLocalizedBodyFallback(
MatrixLocals(l10n),
),
),
),
);
return;
}
final client = Matrix.of(context).client;
@ -213,73 +219,83 @@ class MessageContent extends StatelessWidget {
default:
if (event.redacted) {
return FutureBuilder<User?>(
future: event.redactedBecause?.fetchSenderUser(),
builder: (context, snapshot) {
return _ButtonContent(
label: L10n.of(context)!.redactedAnEvent(snapshot.data
?.calcDisplayname() ??
event.senderFromMemoryOrFallback.calcDisplayname()),
icon: const Icon(Icons.delete_outlined),
textColor: buttonTextColor,
onPressed: () => onInfoTab!(event),
);
});
future: event.redactedBecause?.fetchSenderUser(),
builder: (context, snapshot) {
return _ButtonContent(
label: L10n.of(context)!.redactedAnEvent(
snapshot.data?.calcDisplayname() ??
event.senderFromMemoryOrFallback.calcDisplayname(),
),
icon: const Icon(Icons.delete_outlined),
textColor: buttonTextColor,
onPressed: () => onInfoTab!(event),
);
},
);
}
final bigEmotes = event.onlyEmotes &&
event.numberEmotes > 0 &&
event.numberEmotes <= 10;
return FutureBuilder<String>(
future: event.calcLocalizedBody(MatrixLocals(L10n.of(context)!),
hideReply: true),
builder: (context, snapshot) {
return LinkText(
text: snapshot.data ??
event.calcLocalizedBodyFallback(
MatrixLocals(L10n.of(context)!),
hideReply: true),
textStyle: TextStyle(
color: textColor,
fontSize: bigEmotes ? fontSize * 3 : fontSize,
decoration:
event.redacted ? TextDecoration.lineThrough : null,
),
linkStyle: TextStyle(
color: textColor.withAlpha(150),
fontSize: bigEmotes ? fontSize * 3 : fontSize,
decoration: TextDecoration.underline,
decorationColor: textColor.withAlpha(150),
),
onLinkTap: (url) => UrlLauncher(context, url).launchUrl(),
);
});
future: event.calcLocalizedBody(
MatrixLocals(L10n.of(context)!),
hideReply: true,
),
builder: (context, snapshot) {
return LinkText(
text: snapshot.data ??
event.calcLocalizedBodyFallback(
MatrixLocals(L10n.of(context)!),
hideReply: true,
),
textStyle: TextStyle(
color: textColor,
fontSize: bigEmotes ? fontSize * 3 : fontSize,
decoration:
event.redacted ? TextDecoration.lineThrough : null,
),
linkStyle: TextStyle(
color: textColor.withAlpha(150),
fontSize: bigEmotes ? fontSize * 3 : fontSize,
decoration: TextDecoration.underline,
decorationColor: textColor.withAlpha(150),
),
onLinkTap: (url) => UrlLauncher(context, url).launchUrl(),
);
},
);
}
case EventTypes.CallInvite:
return FutureBuilder<User?>(
future: event.fetchSenderUser(),
builder: (context, snapshot) {
return _ButtonContent(
label: L10n.of(context)!.startedACall(
snapshot.data?.calcDisplayname() ??
event.senderFromMemoryOrFallback.calcDisplayname()),
icon: const Icon(Icons.phone_outlined),
textColor: buttonTextColor,
onPressed: () => onInfoTab!(event),
);
});
future: event.fetchSenderUser(),
builder: (context, snapshot) {
return _ButtonContent(
label: L10n.of(context)!.startedACall(
snapshot.data?.calcDisplayname() ??
event.senderFromMemoryOrFallback.calcDisplayname(),
),
icon: const Icon(Icons.phone_outlined),
textColor: buttonTextColor,
onPressed: () => onInfoTab!(event),
);
},
);
default:
return FutureBuilder<User?>(
future: event.fetchSenderUser(),
builder: (context, snapshot) {
return _ButtonContent(
label: L10n.of(context)!.userSentUnknownEvent(
snapshot.data?.calcDisplayname() ??
event.senderFromMemoryOrFallback.calcDisplayname(),
event.type),
icon: const Icon(Icons.info_outlined),
textColor: buttonTextColor,
onPressed: () => onInfoTab!(event),
);
});
future: event.fetchSenderUser(),
builder: (context, snapshot) {
return _ButtonContent(
label: L10n.of(context)!.userSentUnknownEvent(
snapshot.data?.calcDisplayname() ??
event.senderFromMemoryOrFallback.calcDisplayname(),
event.type,
),
icon: const Icon(Icons.info_outlined),
textColor: buttonTextColor,
onPressed: () => onInfoTab!(event),
);
},
);
}
}
}

View file

@ -46,45 +46,51 @@ class MessageReactions extends StatelessWidget {
final reactionList = reactionMap.values.toList();
reactionList.sort((a, b) => b.count - a.count > 0 ? 1 : -1);
return Wrap(spacing: 4.0, runSpacing: 4.0, children: [
...reactionList
.map(
(r) => _Reaction(
reactionKey: r.key,
count: r.count,
reacted: r.reacted,
onTap: () {
if (r.reacted) {
final evt = allReactionEvents.firstWhereOrNull((e) =>
e.senderId == e.room.client.userID &&
e.content['m.relates_to']['key'] == r.key);
if (evt != null) {
showFutureLoadingDialog(
context: context,
future: () => evt.redactEvent(),
return Wrap(
spacing: 4.0,
runSpacing: 4.0,
children: [
...reactionList
.map(
(r) => _Reaction(
reactionKey: r.key,
count: r.count,
reacted: r.reacted,
onTap: () {
if (r.reacted) {
final evt = allReactionEvents.firstWhereOrNull(
(e) =>
e.senderId == e.room.client.userID &&
e.content['m.relates_to']['key'] == r.key,
);
if (evt != null) {
showFutureLoadingDialog(
context: context,
future: () => evt.redactEvent(),
);
}
} else {
event.room.sendReaction(event.eventId, r.key!);
}
} else {
event.room.sendReaction(event.eventId, r.key!);
}
},
onLongPress: () async => await _AdaptableReactorsDialog(
client: client,
reactionEntry: r,
).show(context),
},
onLongPress: () async => await _AdaptableReactorsDialog(
client: client,
reactionEntry: r,
).show(context),
),
)
.toList(),
if (allReactionEvents.any((e) => e.status.isSending))
const SizedBox(
width: 28,
height: 28,
child: Padding(
padding: EdgeInsets.all(4.0),
child: CircularProgressIndicator.adaptive(strokeWidth: 1),
),
)
.toList(),
if (allReactionEvents.any((e) => e.status.isSending))
const SizedBox(
width: 28,
height: 28,
child: Padding(
padding: EdgeInsets.all(4.0),
child: CircularProgressIndicator.adaptive(strokeWidth: 1),
),
),
]);
],
);
}
}
@ -121,11 +127,13 @@ class _Reaction extends StatelessWidget {
height: fontSize,
),
const SizedBox(width: 4),
Text(count.toString(),
style: TextStyle(
color: textColor,
fontSize: DefaultTextStyle.of(context).style.fontSize,
)),
Text(
count.toString(),
style: TextStyle(
color: textColor,
fontSize: DefaultTextStyle.of(context).style.fontSize,
),
),
],
);
} else {
@ -133,11 +141,13 @@ class _Reaction extends StatelessWidget {
if (renderKey.length > 10) {
renderKey = renderKey.getRange(0, 9) + Characters('');
}
content = Text('$renderKey $count',
style: TextStyle(
color: textColor,
fontSize: DefaultTextStyle.of(context).style.fontSize,
));
content = Text(
'$renderKey $count',
style: TextStyle(
color: textColor,
fontSize: DefaultTextStyle.of(context).style.fontSize,
),
);
}
return InkWell(
onTap: () => onTap != null ? onTap!() : null,

View file

@ -84,21 +84,22 @@ class ReplyContent extends StatelessWidget {
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
FutureBuilder<User?>(
future: displayEvent.fetchSenderUser(),
builder: (context, snapshot) {
return Text(
'${snapshot.data?.calcDisplayname() ?? displayEvent.senderFromMemoryOrFallback.calcDisplayname()}:',
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(
fontWeight: FontWeight.bold,
color: ownMessage
? Theme.of(context).colorScheme.onPrimary
: Theme.of(context).colorScheme.onBackground,
fontSize: fontSize,
),
);
}),
future: displayEvent.fetchSenderUser(),
builder: (context, snapshot) {
return Text(
'${snapshot.data?.calcDisplayname() ?? displayEvent.senderFromMemoryOrFallback.calcDisplayname()}:',
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(
fontWeight: FontWeight.bold,
color: ownMessage
? Theme.of(context).colorScheme.onPrimary
: Theme.of(context).colorScheme.onBackground,
fontSize: fontSize,
),
);
},
),
replyBody,
],
),

View file

@ -25,22 +25,23 @@ class StateMessage extends StatelessWidget {
borderRadius: BorderRadius.circular(AppConfig.borderRadius / 2),
),
child: FutureBuilder<String>(
future: event.calcLocalizedBody(MatrixLocals(L10n.of(context)!)),
builder: (context, snapshot) {
return Text(
snapshot.data ??
event.calcLocalizedBodyFallback(
MatrixLocals(L10n.of(context)!),
),
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 14 * AppConfig.fontSizeFactor,
color: Theme.of(context).colorScheme.onSecondaryContainer,
decoration:
event.redacted ? TextDecoration.lineThrough : null,
),
);
}),
future: event.calcLocalizedBody(MatrixLocals(L10n.of(context)!)),
builder: (context, snapshot) {
return Text(
snapshot.data ??
event.calcLocalizedBodyFallback(
MatrixLocals(L10n.of(context)!),
),
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 14 * AppConfig.fontSizeFactor,
color: Theme.of(context).colorScheme.onSecondaryContainer,
decoration:
event.redacted ? TextDecoration.lineThrough : null,
),
);
},
),
),
),
);

View file

@ -9,9 +9,11 @@ class VerificationRequestContent extends StatelessWidget {
final Event event;
final Timeline timeline;
const VerificationRequestContent(
{required this.event, required this.timeline, Key? key})
: super(key: key);
const VerificationRequestContent({
required this.event,
required this.timeline,
Key? key,
}) : super(key: key);
@override
Widget build(BuildContext context) {
@ -43,18 +45,22 @@ class VerificationRequestContent extends StatelessWidget {
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Icon(Icons.lock_outlined,
color: canceled
? Colors.red
: (fullyDone ? Colors.green : Colors.grey)),
Icon(
Icons.lock_outlined,
color: canceled
? Colors.red
: (fullyDone ? Colors.green : Colors.grey),
),
const SizedBox(width: 8),
Text(canceled
? 'Error ${cancel.first.content.tryGet<String>('code')}: ${cancel.first.content.tryGet<String>('reason')}'
: (fullyDone
? L10n.of(context)!.verifySuccess
: (started
? L10n.of(context)!.loadingPleaseWait
: L10n.of(context)!.newVerificationRequest)))
Text(
canceled
? 'Error ${cancel.first.content.tryGet<String>('code')}: ${cancel.first.content.tryGet<String>('reason')}'
: (fullyDone
? L10n.of(context)!.verifySuccess
: (started
? L10n.of(context)!.loadingPleaseWait
: L10n.of(context)!.newVerificationRequest)),
)
],
),
),

View file

@ -39,7 +39,8 @@ class EventVideoPlayerState extends State<EventVideoPlayer> {
} else {
final tempDir = await getTemporaryDirectory();
final fileName = Uri.encodeComponent(
widget.event.attachmentOrThumbnailMxcUrl()!.pathSegments.last);
widget.event.attachmentOrThumbnailMxcUrl()!.pathSegments.last,
);
final file = File('${tempDir.path}/${fileName}_${videoFile.name}');
if (await file.exists() == false) {
await file.writeAsBytes(videoFile.bytes);
@ -62,13 +63,17 @@ class EventVideoPlayerState extends State<EventVideoPlayer> {
);
}
} on MatrixConnectionException catch (e) {
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text(e.toLocalizedString(context)),
));
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(e.toLocalizedString(context)),
),
);
} catch (e, s) {
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text(e.toLocalizedString(context)),
));
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(e.toLocalizedString(context)),
),
);
Logs().w('Error while playing video', e, s);
} finally {
// Workaround for Chewie needs time to get the aspectRatio
@ -120,14 +125,16 @@ class EventVideoPlayerState extends State<EventVideoPlayer> {
width: 24,
height: 24,
child: CircularProgressIndicator.adaptive(
strokeWidth: 2),
strokeWidth: 2,
),
)
: const Icon(Icons.download_outlined),
label: Text(
_isDownloading
? L10n.of(context)!.loadingPleaseWait
: L10n.of(context)!.videoWithSize(
widget.event.sizeString ?? '?MB'),
widget.event.sizeString ?? '?MB',
),
),
onPressed: _isDownloading ? null : _downloadAction,
),