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,8 @@ class ChatListViewBody extends StatelessWidget {
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
final client = Matrix.of(context).client;
final activeSpace = controller.activeSpaceId;
if (activeSpace != null) {
@ -59,10 +61,8 @@ class ChatListViewBody extends StatelessWidget {
.toList();
final userSearchResult = controller.userSearchResult;
const dummyChatCount = 4;
final titleColor =
Theme.of(context).textTheme.bodyLarge!.color!.withAlpha(100);
final subtitleColor =
Theme.of(context).textTheme.bodyLarge!.color!.withAlpha(50);
final titleColor = theme.textTheme.bodyLarge!.color!.withAlpha(100);
final subtitleColor = theme.textTheme.bodyLarge!.color!.withAlpha(50);
final filter = controller.searchController.text.toLowerCase();
return StreamBuilder(
key: ValueKey(
@ -144,7 +144,7 @@ class ChatListViewBody extends StatelessWidget {
clipBehavior: Clip.hardEdge,
decoration: const BoxDecoration(),
child: Material(
color: Theme.of(context).colorScheme.surface,
color: theme.colorScheme.surface,
child: ListTile(
leading: const Icon(Icons.vpn_key),
title: Text(L10n.of(context)!.dehydrateTor),
@ -199,11 +199,8 @@ class ChatListViewBody extends StatelessWidget {
decoration: BoxDecoration(
color: filter ==
controller.activeFilter
? Theme.of(context)
.colorScheme
.primary
: Theme.of(context)
.colorScheme
? theme.colorScheme.primary
: theme.colorScheme
.secondaryContainer,
borderRadius: BorderRadius.circular(
AppConfig.borderRadius,
@ -219,11 +216,8 @@ class ChatListViewBody extends StatelessWidget {
: FontWeight.normal,
color: filter ==
controller.activeFilter
? Theme.of(context)
.colorScheme
.onPrimary
: Theme.of(context)
.colorScheme
? theme.colorScheme.onPrimary
: theme.colorScheme
.onSecondaryContainer,
),
),
@ -249,7 +243,7 @@ class ChatListViewBody extends StatelessWidget {
child: Icon(
CupertinoIcons.chat_bubble_2,
size: 128,
color: Theme.of(context).colorScheme.secondary,
color: theme.colorScheme.secondary,
),
),
],
@ -266,7 +260,7 @@ class ChatListViewBody extends StatelessWidget {
backgroundColor: titleColor,
child: CircularProgressIndicator(
strokeWidth: 1,
color: Theme.of(context).textTheme.bodyLarge!.color,
color: theme.textTheme.bodyLarge!.color,
),
),
title: Row(

View file

@ -19,6 +19,8 @@ class ChatListHeader extends StatelessWidget implements PreferredSizeWidget {
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
final selectMode = controller.selectMode;
return SliverAppBar(
@ -36,7 +38,7 @@ class ChatListHeader extends StatelessWidget implements PreferredSizeWidget {
tooltip: L10n.of(context)!.cancel,
icon: const Icon(Icons.close_outlined),
onPressed: controller.cancelAction,
color: Theme.of(context).colorScheme.primary,
color: theme.colorScheme.primary,
),
title: selectMode == SelectMode.share
? Text(
@ -52,7 +54,7 @@ class ChatListHeader extends StatelessWidget implements PreferredSizeWidget {
globalSearch: globalSearch,
),
decoration: InputDecoration(
fillColor: Theme.of(context).colorScheme.secondaryContainer,
fillColor: theme.colorScheme.secondaryContainer,
border: OutlineInputBorder(
borderSide: BorderSide.none,
borderRadius: BorderRadius.circular(99),
@ -60,7 +62,7 @@ class ChatListHeader extends StatelessWidget implements PreferredSizeWidget {
contentPadding: EdgeInsets.zero,
hintText: L10n.of(context)!.searchChatsRooms,
hintStyle: TextStyle(
color: Theme.of(context).colorScheme.onPrimaryContainer,
color: theme.colorScheme.onPrimaryContainer,
fontWeight: FontWeight.normal,
),
floatingLabelBehavior: FloatingLabelBehavior.never,
@ -69,14 +71,13 @@ class ChatListHeader extends StatelessWidget implements PreferredSizeWidget {
tooltip: L10n.of(context)!.cancel,
icon: const Icon(Icons.close_outlined),
onPressed: controller.cancelSearch,
color: Theme.of(context).colorScheme.onPrimaryContainer,
color: theme.colorScheme.onPrimaryContainer,
)
: IconButton(
onPressed: controller.startSearch,
icon: Icon(
Icons.search_outlined,
color:
Theme.of(context).colorScheme.onPrimaryContainer,
color: theme.colorScheme.onPrimaryContainer,
),
),
suffixIcon: controller.isSearchMode && globalSearch

View file

@ -63,12 +63,13 @@ class ChatListItem extends StatelessWidget {
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
final isMuted = room.pushRuleState != PushRuleState.notify;
final typingText = room.getLocalizedTypingText(context);
final lastEvent = room.lastEvent;
final ownMessage = lastEvent?.senderId == room.client.userID;
final unread = room.isUnread || room.membership == Membership.invite;
final theme = Theme.of(context);
final directChatMatrixId = room.directChatMatrixID;
final isDirectChat = directChatMatrixId != null;
final unreadBubbleSize = unread || room.hasNewMessages
@ -126,7 +127,7 @@ class ChatListItem extends StatelessWidget {
border: BorderSide(
width: 2,
color: backgroundColor ??
Theme.of(context).colorScheme.surface,
theme.colorScheme.surface,
),
borderRadius: BorderRadius.circular(
AppConfig.borderRadius / 4,
@ -146,7 +147,7 @@ class ChatListItem extends StatelessWidget {
: BorderSide(
width: 2,
color: backgroundColor ??
Theme.of(context).colorScheme.surface,
theme.colorScheme.surface,
),
borderRadius: room.isSpace
? BorderRadius.circular(

View file

@ -35,6 +35,8 @@ class _NaviRailItemState extends State<NaviRailItem> {
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
final borderRadius = BorderRadius.circular(AppConfig.borderRadius);
return SizedBox(
height: 64,
@ -50,7 +52,7 @@ class _NaviRailItemState extends State<NaviRailItem> {
duration: FluffyThemes.animationDuration,
curve: FluffyThemes.animationCurve,
decoration: BoxDecoration(
color: Theme.of(context).colorScheme.primary,
color: theme.colorScheme.primary,
borderRadius: const BorderRadius.only(
topRight: Radius.circular(90),
bottomRight: Radius.circular(90),
@ -66,8 +68,8 @@ class _NaviRailItemState extends State<NaviRailItem> {
child: Material(
borderRadius: borderRadius,
color: widget.isSelected
? Theme.of(context).colorScheme.primaryContainer
: Theme.of(context).colorScheme.surface,
? theme.colorScheme.primaryContainer
: theme.colorScheme.surface,
child: Tooltip(
message: widget.toolTip,
child: InkWell(

View file

@ -27,6 +27,8 @@ class NaviRailItem extends StatelessWidget {
});
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
final borderRadius = BorderRadius.circular(AppConfig.borderRadius);
final icon = isSelected ? selectedIcon ?? this.icon : this.icon;
final unreadBadgeFilter = this.unreadBadgeFilter;
@ -46,7 +48,7 @@ class NaviRailItem extends StatelessWidget {
duration: FluffyThemes.animationDuration,
curve: FluffyThemes.animationCurve,
decoration: BoxDecoration(
color: Theme.of(context).colorScheme.primary,
color: theme.colorScheme.primary,
borderRadius: const BorderRadius.only(
topRight: Radius.circular(90),
bottomRight: Radius.circular(90),
@ -62,8 +64,8 @@ class NaviRailItem extends StatelessWidget {
child: Material(
borderRadius: borderRadius,
color: isSelected
? Theme.of(context).colorScheme.primaryContainer
: Theme.of(context).colorScheme.surface,
? theme.colorScheme.primaryContainer
: theme.colorScheme.surface,
child: Tooltip(
message: toolTip,
child: InkWell(

View file

@ -17,55 +17,59 @@ class SearchTitle extends StatelessWidget {
});
@override
Widget build(BuildContext context) => Material(
shape: Border(
top: BorderSide(
color: Theme.of(context).dividerColor,
width: 1,
),
bottom: BorderSide(
color: Theme.of(context).dividerColor,
width: 1,
),
Widget build(BuildContext context) {
final theme = Theme.of(context);
return Material(
shape: Border(
top: BorderSide(
color: theme.dividerColor,
width: 1,
),
color: color ?? Theme.of(context).colorScheme.surface,
child: InkWell(
onTap: onTap,
splashColor: Theme.of(context).colorScheme.surface,
child: Align(
alignment: Alignment.centerLeft,
child: Padding(
padding: const EdgeInsets.symmetric(
horizontal: 16,
vertical: 8,
),
child: IconTheme(
data: Theme.of(context).iconTheme.copyWith(size: 16),
child: Row(
children: [
icon,
const SizedBox(width: 16),
Text(
title,
textAlign: TextAlign.left,
style: TextStyle(
color: Theme.of(context).colorScheme.onSurface,
fontSize: 12,
fontWeight: FontWeight.bold,
bottom: BorderSide(
color: theme.dividerColor,
width: 1,
),
),
color: color ?? theme.colorScheme.surface,
child: InkWell(
onTap: onTap,
splashColor: theme.colorScheme.surface,
child: Align(
alignment: Alignment.centerLeft,
child: Padding(
padding: const EdgeInsets.symmetric(
horizontal: 16,
vertical: 8,
),
child: IconTheme(
data: theme.iconTheme.copyWith(size: 16),
child: Row(
children: [
icon,
const SizedBox(width: 16),
Text(
title,
textAlign: TextAlign.left,
style: TextStyle(
color: theme.colorScheme.onSurface,
fontSize: 12,
fontWeight: FontWeight.bold,
),
),
if (trailing != null)
Expanded(
child: Align(
alignment: Alignment.centerRight,
child: trailing!,
),
),
if (trailing != null)
Expanded(
child: Align(
alignment: Alignment.centerRight,
child: trailing!,
),
),
],
),
],
),
),
),
),
);
),
);
}
}

View file

@ -241,6 +241,8 @@ class _SpaceViewState extends State<SpaceView> {
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
final room = Matrix.of(context).client.getRoomById(widget.spaceId);
final displayname =
room?.getLocalizedDisplayname() ?? L10n.of(context)!.nothingFound;
@ -359,8 +361,7 @@ class _SpaceViewState extends State<SpaceView> {
onChanged: (_) => setState(() {}),
textInputAction: TextInputAction.search,
decoration: InputDecoration(
fillColor:
Theme.of(context).colorScheme.secondaryContainer,
fillColor: theme.colorScheme.secondaryContainer,
border: OutlineInputBorder(
borderSide: BorderSide.none,
borderRadius: BorderRadius.circular(99),
@ -368,9 +369,7 @@ class _SpaceViewState extends State<SpaceView> {
contentPadding: EdgeInsets.zero,
hintText: L10n.of(context)!.search,
hintStyle: TextStyle(
color: Theme.of(context)
.colorScheme
.onPrimaryContainer,
color: theme.colorScheme.onPrimaryContainer,
fontWeight: FontWeight.normal,
),
floatingLabelBehavior: FloatingLabelBehavior.never,
@ -378,9 +377,7 @@ class _SpaceViewState extends State<SpaceView> {
onPressed: () {},
icon: Icon(
Icons.search_outlined,
color: Theme.of(context)
.colorScheme
.onPrimaryContainer,
color: theme.colorScheme.onPrimaryContainer,
),
),
),

View file

@ -116,6 +116,8 @@ class PresenceAvatar extends StatelessWidget {
return FutureBuilder<Profile>(
future: client.getProfileFromUserId(presence.userid),
builder: (context, snapshot) {
final theme = Theme.of(context);
final profile = snapshot.data;
final displayName = profile?.displayName ??
presence.userid.localpart ??
@ -123,9 +125,8 @@ class PresenceAvatar extends StatelessWidget {
final statusMsg = presence.statusMsg;
final statusMsgBubbleElevation =
Theme.of(context).appBarTheme.scrolledUnderElevation ?? 4;
final statusMsgBubbleShadowColor =
Theme.of(context).colorScheme.onSurface;
theme.appBarTheme.scrolledUnderElevation ?? 4;
final statusMsgBubbleShadowColor = theme.colorScheme.onSurface;
final statusMsgBubbleColor = Colors.white.withAlpha(245);
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 8.0),