Skip to content

Commit

Permalink
Merge pull request #1261 from CodeThomnics/refactor/reduce_context_ca…
Browse files Browse the repository at this point in the history
…lls_theme

Refactor: Reduce .of(context) calls theme
  • Loading branch information
krille-chan authored Aug 9, 2024
2 parents 02430a9 + 5d2aaef commit 9731fb4
Show file tree
Hide file tree
Showing 69 changed files with 525 additions and 501 deletions.
23 changes: 10 additions & 13 deletions lib/pages/bootstrap/bootstrap_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ class BootstrapDialogState extends State<BootstrapDialog> {

@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
_wipe ??= widget.wipe;
final buttons = <Widget>[];
Widget body = const CircularProgressIndicator.adaptive();
Expand Down Expand Up @@ -119,7 +120,7 @@ class BootstrapDialogState extends State<BootstrapDialog> {
backgroundColor: Colors.transparent,
child: Icon(
Icons.info_outlined,
color: Theme.of(context).colorScheme.primary,
color: theme.colorScheme.primary,
),
),
subtitle: Text(L10n.of(context)!.chatBackupDescription),
Expand All @@ -144,7 +145,7 @@ class BootstrapDialogState extends State<BootstrapDialog> {
CheckboxListTile.adaptive(
contentPadding: const EdgeInsets.symmetric(horizontal: 8.0),
value: _storeInSecureStorage,
activeColor: Theme.of(context).colorScheme.primary,
activeColor: theme.colorScheme.primary,
onChanged: (b) {
setState(() {
_storeInSecureStorage = b;
Expand All @@ -158,7 +159,7 @@ class BootstrapDialogState extends State<BootstrapDialog> {
CheckboxListTile.adaptive(
contentPadding: const EdgeInsets.symmetric(horizontal: 8.0),
value: _recoveryKeyCopied,
activeColor: Theme.of(context).colorScheme.primary,
activeColor: theme.colorScheme.primary,
onChanged: (b) {
FluffyShare.share(key!, context);
setState(() => _recoveryKeyCopied = true);
Expand Down Expand Up @@ -241,7 +242,7 @@ class BootstrapDialogState extends State<BootstrapDialog> {
const EdgeInsets.symmetric(horizontal: 8.0),
trailing: Icon(
Icons.info_outlined,
color: Theme.of(context).colorScheme.primary,
color: theme.colorScheme.primary,
),
subtitle: Text(
L10n.of(context)!.pleaseEnterRecoveryKeyDescription,
Expand All @@ -261,8 +262,7 @@ class BootstrapDialogState extends State<BootstrapDialog> {
decoration: InputDecoration(
contentPadding: const EdgeInsets.all(16),
hintStyle: TextStyle(
fontFamily:
Theme.of(context).textTheme.bodyLarge?.fontFamily,
fontFamily: theme.textTheme.bodyLarge?.fontFamily,
),
hintText: L10n.of(context)!.recoveryKey,
errorText: _recoveryKeyInputError,
Expand All @@ -272,9 +272,8 @@ class BootstrapDialogState extends State<BootstrapDialog> {
const SizedBox(height: 16),
ElevatedButton.icon(
style: ElevatedButton.styleFrom(
foregroundColor:
Theme.of(context).colorScheme.onPrimary,
backgroundColor: Theme.of(context).colorScheme.primary,
foregroundColor: theme.colorScheme.onPrimary,
backgroundColor: theme.colorScheme.primary,
),
icon: _recoveryKeyInputLoading
? const CircularProgressIndicator.adaptive()
Expand Down Expand Up @@ -386,10 +385,8 @@ class BootstrapDialogState extends State<BootstrapDialog> {
const SizedBox(height: 16),
ElevatedButton.icon(
style: ElevatedButton.styleFrom(
backgroundColor:
Theme.of(context).colorScheme.errorContainer,
foregroundColor:
Theme.of(context).colorScheme.onErrorContainer,
backgroundColor: theme.colorScheme.errorContainer,
foregroundColor: theme.colorScheme.onErrorContainer,
),
icon: const Icon(Icons.delete_outlined),
label: Text(L10n.of(context)!.recoveryKeyLost),
Expand Down
81 changes: 42 additions & 39 deletions lib/pages/chat/chat.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1313,49 +1313,52 @@ class ChatController extends State<ChatPageWithRoom>
}

@override
Widget build(BuildContext context) => Row(
children: [
Expanded(
child: ChatView(this),
),
AnimatedSize(
duration: FluffyThemes.animationDuration,
curve: FluffyThemes.animationCurve,
child: ValueListenableBuilder(
valueListenable: _displayChatDetailsColumn,
builder: (context, displayChatDetailsColumn, _) {
if (!FluffyThemes.isThreeColumnMode(context) ||
room.membership != Membership.join ||
!displayChatDetailsColumn) {
return const SizedBox(
height: double.infinity,
width: 0,
);
}
return Container(
width: FluffyThemes.columnWidth,
clipBehavior: Clip.hardEdge,
decoration: BoxDecoration(
border: Border(
left: BorderSide(
width: 1,
color: Theme.of(context).dividerColor,
),
Widget build(BuildContext context) {
final theme = Theme.of(context);
return Row(
children: [
Expanded(
child: ChatView(this),
),
AnimatedSize(
duration: FluffyThemes.animationDuration,
curve: FluffyThemes.animationCurve,
child: ValueListenableBuilder(
valueListenable: _displayChatDetailsColumn,
builder: (context, displayChatDetailsColumn, _) {
if (!FluffyThemes.isThreeColumnMode(context) ||
room.membership != Membership.join ||
!displayChatDetailsColumn) {
return const SizedBox(
height: double.infinity,
width: 0,
);
}
return Container(
width: FluffyThemes.columnWidth,
clipBehavior: Clip.hardEdge,
decoration: BoxDecoration(
border: Border(
left: BorderSide(
width: 1,
color: theme.dividerColor,
),
),
child: ChatDetails(
roomId: roomId,
embeddedCloseButton: IconButton(
icon: const Icon(Icons.close),
onPressed: toggleDisplayChatDetailsColumn,
),
),
child: ChatDetails(
roomId: roomId,
embeddedCloseButton: IconButton(
icon: const Icon(Icons.close),
onPressed: toggleDisplayChatDetailsColumn,
),
);
},
),
),
);
},
),
],
);
),
],
);
}
}

enum EmojiPickerType { reaction, keyboard }
Expand Down
8 changes: 4 additions & 4 deletions lib/pages/chat/chat_app_bar_list_tile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class ChatAppBarListTile extends StatelessWidget {

@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
final leading = this.leading;
final trailing = this.trailing;
return SizedBox(
Expand All @@ -40,16 +41,15 @@ class ChatAppBarListTile extends StatelessWidget {
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(
color: Theme.of(context).colorScheme.onSurfaceVariant,
color: theme.colorScheme.onSurfaceVariant,
overflow: TextOverflow.ellipsis,
fontSize: 14,
),
linkStyle: TextStyle(
color: Theme.of(context).colorScheme.onSurfaceVariant,
color: theme.colorScheme.onSurfaceVariant,
fontSize: 14,
decoration: TextDecoration.underline,
decorationColor:
Theme.of(context).colorScheme.onSurfaceVariant,
decorationColor: theme.colorScheme.onSurfaceVariant,
),
onOpen: (url) => UrlLauncher(context, url.url).launchUrl(),
),
Expand Down
5 changes: 2 additions & 3 deletions lib/pages/chat/chat_emoji_picker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,8 @@ class ChatEmojiPicker extends StatelessWidget {
config: Config(
emojiViewConfig: EmojiViewConfig(
noRecents: const NoRecent(),
backgroundColor: Theme.of(context)
.colorScheme
.onInverseSurface,
backgroundColor:
theme.colorScheme.onInverseSurface,
),
bottomActionBarConfig: const BottomActionBarConfig(
enabled: false,
Expand Down
14 changes: 6 additions & 8 deletions lib/pages/chat/chat_input_row.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class ChatInputRow extends StatelessWidget {

@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
if (controller.showEmojiPicker &&
controller.emojiPickerType == EmojiPickerType.reaction) {
return const SizedBox.shrink();
Expand All @@ -37,7 +38,7 @@ class ChatInputRow extends StatelessWidget {
height: height,
child: TextButton(
style: TextButton.styleFrom(
foregroundColor: Theme.of(context).colorScheme.error,
foregroundColor: theme.colorScheme.error,
),
onPressed: controller.deleteErrorEventsAction,
child: Row(
Expand Down Expand Up @@ -278,9 +279,8 @@ class ChatInputRow extends StatelessWidget {
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(height),
),
backgroundColor: Theme.of(context).colorScheme.primary,
foregroundColor:
Theme.of(context).colorScheme.onPrimary,
backgroundColor: theme.colorScheme.primary,
foregroundColor: theme.colorScheme.onPrimary,
child: const Icon(Icons.mic_none_outlined),
)
: FloatingActionButton.small(
Expand All @@ -291,10 +291,8 @@ class ChatInputRow extends StatelessWidget {
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(height),
),
backgroundColor:
Theme.of(context).colorScheme.onPrimaryContainer,
foregroundColor:
Theme.of(context).colorScheme.onPrimary,
backgroundColor: theme.colorScheme.onPrimaryContainer,
foregroundColor: theme.colorScheme.onPrimary,
child: const Icon(Icons.send_outlined),
),
),
Expand Down
19 changes: 8 additions & 11 deletions lib/pages/chat/chat_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ class ChatView extends StatelessWidget {

@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
if (controller.room.membership == Membership.invite) {
showFutureLoadingDialog(
context: context,
Expand Down Expand Up @@ -173,14 +174,14 @@ class ChatView extends StatelessWidget {
actionsIconTheme: IconThemeData(
color: controller.selectedEvents.isEmpty
? null
: Theme.of(context).colorScheme.primary,
: theme.colorScheme.primary,
),
leading: controller.selectMode
? IconButton(
icon: const Icon(Icons.close),
onPressed: controller.clearSelectedEvents,
tooltip: L10n.of(context)!.close,
color: Theme.of(context).colorScheme.primary,
color: theme.colorScheme.primary,
)
: StreamBuilder<Object>(
stream: Matrix.of(context)
Expand Down Expand Up @@ -218,8 +219,7 @@ class ChatView extends StatelessWidget {
if (scrollUpBannerEventId != null)
ChatAppBarListTile(
leading: IconButton(
color:
Theme.of(context).colorScheme.onSurfaceVariant,
color: theme.colorScheme.onSurfaceVariant,
icon: const Icon(Icons.close),
tooltip: L10n.of(context)!.close,
onPressed: () {
Expand Down Expand Up @@ -308,7 +308,7 @@ class ChatView extends StatelessWidget {
alignment: Alignment.center,
child: Material(
clipBehavior: Clip.hardEdge,
color: Theme.of(context)
color: theme
.colorScheme
// ignore: deprecated_member_use
.surfaceVariant,
Expand All @@ -325,9 +325,8 @@ class ChatView extends StatelessWidget {
padding: const EdgeInsets.all(
16,
),
foregroundColor: Theme.of(context)
.colorScheme
.error,
foregroundColor:
theme.colorScheme.error,
),
icon: const Icon(
Icons.archive_outlined,
Expand Down Expand Up @@ -370,9 +369,7 @@ class ChatView extends StatelessWidget {
),
if (controller.dragging)
Container(
color: Theme.of(context)
.scaffoldBackgroundColor
.withOpacity(0.9),
color: theme.scaffoldBackgroundColor.withOpacity(0.9),
alignment: Alignment.center,
child: const Icon(
Icons.upload_outlined,
Expand Down
5 changes: 3 additions & 2 deletions lib/pages/chat/event_info_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class EventInfoDialog extends StatelessWidget {

@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
return Scaffold(
appBar: AppBar(
title: Text(L10n.of(context)!.messageInfo),
Expand Down Expand Up @@ -72,14 +73,14 @@ class EventInfoDialog extends StatelessWidget {
padding: const EdgeInsets.all(12.0),
child: Material(
borderRadius: BorderRadius.circular(AppConfig.borderRadius),
color: Theme.of(context).colorScheme.inverseSurface,
color: theme.colorScheme.inverseSurface,
child: SingleChildScrollView(
padding: const EdgeInsets.all(8),
scrollDirection: Axis.horizontal,
child: SelectableText(
prettyJson,
style: TextStyle(
color: Theme.of(context).colorScheme.onInverseSurface,
color: theme.colorScheme.onInverseSurface,
),
),
),
Expand Down
6 changes: 4 additions & 2 deletions lib/pages/chat/events/audio_player.dart
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,8 @@ class AudioPlayerState extends State<AudioPlayerWidget> {

@override
Widget build(BuildContext context) {
final theme = Theme.of(context);

final statusText = this.statusText ??= _durationString ?? '00:00';
final audioPlayer = this.audioPlayer;
return Padding(
Expand Down Expand Up @@ -304,8 +306,8 @@ class AudioPlayerState extends State<AudioPlayerWidget> {
: Text(
'${audioPlayer.speed.toString()}x',
),
backgroundColor: Theme.of(context).colorScheme.secondary,
textColor: Theme.of(context).colorScheme.onSecondary,
backgroundColor: theme.colorScheme.secondary,
textColor: theme.colorScheme.onSecondary,
child: InkWell(
splashColor: widget.color.withAlpha(128),
borderRadius: BorderRadius.circular(64),
Expand Down
4 changes: 3 additions & 1 deletion lib/pages/chat/events/image_bubble.dart
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ class ImageBubble extends StatelessWidget {

@override
Widget build(BuildContext context) {
final theme = Theme.of(context);

final borderRadius =
this.borderRadius ?? BorderRadius.circular(AppConfig.borderRadius);
return Material(
Expand All @@ -77,7 +79,7 @@ class ImageBubble extends StatelessWidget {
side: BorderSide(
color: event.messageType == MessageTypes.Sticker
? Colors.transparent
: Theme.of(context).dividerColor,
: theme.dividerColor,
),
),
child: InkWell(
Expand Down
Loading

0 comments on commit 9731fb4

Please sign in to comment.