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

@ -28,6 +28,7 @@ class ChatSearchFilesTab extends StatelessWidget {
return StreamBuilder(
stream: searchStream,
builder: (context, snapshot) {
final theme = Theme.of(context);
final events = snapshot.data?.$1;
if (searchStream == null || events == null) {
return Column(
@ -82,10 +83,8 @@ class ChatSearchFilesTab extends StatelessWidget {
padding: const EdgeInsets.all(16.0),
child: TextButton.icon(
style: TextButton.styleFrom(
backgroundColor:
Theme.of(context).colorScheme.secondaryContainer,
foregroundColor:
Theme.of(context).colorScheme.onSecondaryContainer,
backgroundColor: theme.colorScheme.secondaryContainer,
foregroundColor: theme.colorScheme.onSecondaryContainer,
),
onPressed: () => startSearch(
prevBatch: nextBatch,
@ -127,21 +126,21 @@ class ChatSearchFilesTab extends StatelessWidget {
Expanded(
child: Container(
height: 1,
color: Theme.of(context).dividerColor,
color: theme.dividerColor,
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: Text(
event.originServerTs.localizedTime(context),
style: Theme.of(context).textTheme.labelSmall,
style: theme.textTheme.labelSmall,
textAlign: TextAlign.center,
),
),
Expanded(
child: Container(
height: 1,
color: Theme.of(context).dividerColor,
color: theme.dividerColor,
),
),
],
@ -151,7 +150,7 @@ class ChatSearchFilesTab extends StatelessWidget {
Material(
borderRadius:
BorderRadius.circular(AppConfig.borderRadius),
color: Theme.of(context).colorScheme.onInverseSurface,
color: theme.colorScheme.onInverseSurface,
clipBehavior: Clip.hardEdge,
child: ListTile(
leading: const Icon(Icons.file_present_outlined),

View file

@ -28,6 +28,7 @@ class ChatSearchImagesTab extends StatelessWidget {
return StreamBuilder(
stream: searchStream,
builder: (context, snapshot) {
final theme = Theme.of(context);
final events = snapshot.data?.$1;
if (searchStream == null || events == null) {
return Column(
@ -91,10 +92,8 @@ class ChatSearchImagesTab extends StatelessWidget {
padding: const EdgeInsets.all(16.0),
child: TextButton.icon(
style: TextButton.styleFrom(
backgroundColor:
Theme.of(context).colorScheme.secondaryContainer,
foregroundColor:
Theme.of(context).colorScheme.onSecondaryContainer,
backgroundColor: theme.colorScheme.secondaryContainer,
foregroundColor: theme.colorScheme.onSecondaryContainer,
),
onPressed: () => startSearch(
prevBatch: nextBatch,
@ -119,7 +118,7 @@ class ChatSearchImagesTab extends StatelessWidget {
Expanded(
child: Container(
height: 1,
color: Theme.of(context).dividerColor,
color: theme.dividerColor,
),
),
Padding(
@ -128,14 +127,14 @@ class ChatSearchImagesTab extends StatelessWidget {
DateFormat.yMMMM(
Localizations.localeOf(context).languageCode,
).format(eventsByMonthList[i].key),
style: Theme.of(context).textTheme.labelSmall,
style: theme.textTheme.labelSmall,
textAlign: TextAlign.center,
),
),
Expanded(
child: Container(
height: 1,
color: Theme.of(context).dividerColor,
color: theme.dividerColor,
),
),
],

View file

@ -33,6 +33,7 @@ class ChatSearchMessageTab extends StatelessWidget {
key: ValueKey(searchQuery),
stream: searchStream,
builder: (context, snapshot) {
final theme = Theme.of(context);
if (searchStream == null) {
return Column(
mainAxisAlignment: MainAxisAlignment.center,
@ -55,7 +56,7 @@ class ChatSearchMessageTab extends StatelessWidget {
child: ListView.separated(
itemCount: events.length + 1,
separatorBuilder: (context, _) => Divider(
color: Theme.of(context).dividerColor,
color: theme.dividerColor,
height: 1,
),
itemBuilder: (context, i) {
@ -79,10 +80,8 @@ class ChatSearchMessageTab extends StatelessWidget {
padding: const EdgeInsets.all(16.0),
child: TextButton.icon(
style: TextButton.styleFrom(
backgroundColor:
Theme.of(context).colorScheme.secondaryContainer,
foregroundColor:
Theme.of(context).colorScheme.onSecondaryContainer,
backgroundColor: theme.colorScheme.secondaryContainer,
foregroundColor: theme.colorScheme.onSecondaryContainer,
),
onPressed: () => startSearch(
prevBatch: nextBatch,
@ -130,6 +129,8 @@ class _MessageSearchResultListTile extends StatelessWidget {
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
return ListTile(
title: Row(
children: [
@ -153,9 +154,9 @@ class _MessageSearchResultListTile extends StatelessWidget {
subtitle: Linkify(
options: const LinkifyOptions(humanize: false),
linkStyle: TextStyle(
color: Theme.of(context).colorScheme.primary,
color: theme.colorScheme.primary,
decoration: TextDecoration.underline,
decorationColor: Theme.of(context).colorScheme.primary,
decorationColor: theme.colorScheme.primary,
),
onOpen: (url) => UrlLauncher(context, url.url).launchUrl(),
text: event