Refactor: Reduce .of(context) calls theme

Signed commit
This commit is contained in:
Thomas Klein Langenhorst 2024-08-04 14:09:36 +02:00
commit 5d2aaef3ca
No known key found for this signature in database
GPG key ID: CA868C3CB279DA5B
69 changed files with 525 additions and 501 deletions

View file

@ -57,6 +57,8 @@ class Message extends StatelessWidget {
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
if (!{
EventTypes.Message,
EventTypes.Sticker,
@ -78,7 +80,7 @@ class Message extends StatelessWidget {
final ownMessage = event.senderId == client.userID;
final alignment = ownMessage ? Alignment.topRight : Alignment.topLeft;
// ignore: deprecated_member_use
var color = Theme.of(context).colorScheme.surfaceVariant;
var color = theme.colorScheme.surfaceVariant;
final displayTime = event.type == EventTypes.RoomCreate ||
nextEvent == null ||
!event.originServerTs.sameEnvironment(nextEvent!.originServerTs);
@ -100,9 +102,8 @@ class Message extends StatelessWidget {
previousEvent!.senderId == event.senderId &&
previousEvent!.originServerTs.sameEnvironment(event.originServerTs);
final textColor = ownMessage
? Theme.of(context).colorScheme.onPrimary
: Theme.of(context).colorScheme.onSurface;
final textColor =
ownMessage ? theme.colorScheme.onPrimary : theme.colorScheme.onSurface;
final rowMainAxisAlignment =
ownMessage ? MainAxisAlignment.end : MainAxisAlignment.start;
@ -131,7 +132,7 @@ class Message extends StatelessWidget {
if (ownMessage) {
color = displayEvent.status.isError
? Colors.redAccent
: Theme.of(context).colorScheme.primary;
: theme.colorScheme.primary;
}
final resetAnimateIn = this.resetAnimateIn;
@ -168,14 +169,10 @@ class Message extends StatelessWidget {
borderRadius:
BorderRadius.circular(AppConfig.borderRadius / 2),
color: selected
? Theme.of(context)
.colorScheme
.secondaryContainer
? theme.colorScheme.secondaryContainer
.withAlpha(100)
: highlightMarker
? Theme.of(context)
.colorScheme
.tertiaryContainer
? theme.colorScheme.tertiaryContainer
.withAlpha(100)
: Colors.transparent,
),
@ -253,8 +250,7 @@ class Message extends StatelessWidget {
displayname,
style: TextStyle(
fontSize: 12,
color: (Theme.of(context)
.brightness ==
color: (theme.brightness ==
Brightness.light
? displayname.color
: displayname
@ -442,10 +438,10 @@ class Message extends StatelessWidget {
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 12 * AppConfig.fontSizeFactor,
color: Theme.of(context).colorScheme.secondary,
color: theme.colorScheme.secondary,
shadows: [
Shadow(
color: Theme.of(context).colorScheme.surface,
color: theme.colorScheme.surface,
blurRadius: 3,
),
],
@ -473,14 +469,14 @@ class Message extends StatelessWidget {
Row(
children: [
Expanded(
child: Divider(color: Theme.of(context).colorScheme.primary),
child: Divider(color: theme.colorScheme.primary),
),
Container(
decoration: BoxDecoration(
border: Border.all(
color: Theme.of(context).colorScheme.primary,
color: theme.colorScheme.primary,
),
color: Theme.of(context).colorScheme.primaryContainer,
color: theme.colorScheme.primaryContainer,
borderRadius: BorderRadius.circular(4),
),
margin: const EdgeInsets.all(8.0),
@ -489,12 +485,11 @@ class Message extends StatelessWidget {
),
child: Text(
L10n.of(context)!.readUpToHere,
style:
TextStyle(color: Theme.of(context).colorScheme.primary),
style: TextStyle(color: theme.colorScheme.primary),
),
),
Expanded(
child: Divider(color: Theme.of(context).colorScheme.primary),
child: Divider(color: theme.colorScheme.primary),
),
],
),