Skip to content

Commit

Permalink
Fix withOpacity deprecation warnings (#1659)
Browse files Browse the repository at this point in the history
chore: mitigate opacity deprecation
  • Loading branch information
hjiangsu authored Jan 17, 2025
1 parent 6ee7d5e commit 6b8e789
Show file tree
Hide file tree
Showing 66 changed files with 263 additions and 252 deletions.
40 changes: 20 additions & 20 deletions lib/account/widgets/profile_modal_body.dart
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ class _ProfileSelectState extends State<ProfileSelect> {
child: Icon(
accounts![index].alive == true ? Icons.check_circle_rounded : Icons.remove_circle_rounded,
size: 10,
color: Color.alphaBlend(theme.colorScheme.primaryContainer.withOpacity(0.6), accounts![index].alive == true ? Colors.green : Colors.red),
color: Color.alphaBlend(theme.colorScheme.primaryContainer.withValues(alpha: 0.6), accounts![index].alive == true ? Colors.green : Colors.red),
),
),
),
Expand Down Expand Up @@ -336,14 +336,14 @@ class _ProfileSelectState extends State<ProfileSelect> {
Text(
'•',
style: TextStyle(
color: Theme.of(context).colorScheme.onPrimaryContainer.withOpacity(0.55),
color: Theme.of(context).colorScheme.onPrimaryContainer.withValues(alpha: 0.55),
),
),
const SizedBox(width: 5),
Text(
'v${accounts![index].version}',
style: TextStyle(
color: Theme.of(context).colorScheme.onPrimaryContainer.withOpacity(0.55),
color: Theme.of(context).colorScheme.onPrimaryContainer.withValues(alpha: 0.55),
),
),
],
Expand All @@ -360,14 +360,14 @@ class _ProfileSelectState extends State<ProfileSelect> {
Text(
'•',
style: TextStyle(
color: Theme.of(context).colorScheme.onPrimaryContainer.withOpacity(0.55),
color: Theme.of(context).colorScheme.onPrimaryContainer.withValues(alpha: 0.55),
),
),
const SizedBox(width: 5),
Text(
'${accounts![index].latency?.inMilliseconds}ms',
style: TextStyle(
color: Theme.of(context).colorScheme.onPrimaryContainer.withOpacity(0.55),
color: Theme.of(context).colorScheme.onPrimaryContainer.withValues(alpha: 0.55),
),
),
],
Expand Down Expand Up @@ -434,7 +434,7 @@ class _ProfileSelectState extends State<ProfileSelect> {
l10n.noAccountsAdded,
style: theme.textTheme.bodyMedium?.copyWith(
fontStyle: FontStyle.italic,
color: theme.textTheme.bodyMedium?.color?.withOpacity(0.5),
color: theme.textTheme.bodyMedium?.color?.withValues(alpha: 0.5),
),
),
),
Expand Down Expand Up @@ -551,7 +551,7 @@ class _ProfileSelectState extends State<ProfileSelect> {
child: Icon(
anonymousInstances![index].alive == true ? Icons.check_circle_rounded : Icons.remove_circle_rounded,
size: 10,
color: Color.alphaBlend(theme.colorScheme.primaryContainer.withOpacity(0.6), anonymousInstances![index].alive == true ? Colors.green : Colors.red),
color: Color.alphaBlend(theme.colorScheme.primaryContainer.withValues(alpha: 0.6), anonymousInstances![index].alive == true ? Colors.green : Colors.red),
),
),
),
Expand Down Expand Up @@ -584,14 +584,14 @@ class _ProfileSelectState extends State<ProfileSelect> {
Text(
'•',
style: TextStyle(
color: Theme.of(context).colorScheme.onPrimaryContainer.withOpacity(0.55),
color: Theme.of(context).colorScheme.onPrimaryContainer.withValues(alpha: 0.55),
),
),
const SizedBox(width: 5),
Text(
'v${anonymousInstances![index].version}',
style: TextStyle(
color: Theme.of(context).colorScheme.onPrimaryContainer.withOpacity(0.55),
color: Theme.of(context).colorScheme.onPrimaryContainer.withValues(alpha: 0.55),
),
),
],
Expand All @@ -608,14 +608,14 @@ class _ProfileSelectState extends State<ProfileSelect> {
Text(
'•',
style: TextStyle(
color: Theme.of(context).colorScheme.onPrimaryContainer.withOpacity(0.55),
color: Theme.of(context).colorScheme.onPrimaryContainer.withValues(alpha: 0.55),
),
),
const SizedBox(width: 5),
Text(
'${anonymousInstances![index].latency?.inMilliseconds}ms',
style: TextStyle(
color: Theme.of(context).colorScheme.onPrimaryContainer.withOpacity(0.55),
color: Theme.of(context).colorScheme.onPrimaryContainer.withValues(alpha: 0.55),
),
),
],
Expand Down Expand Up @@ -675,7 +675,7 @@ class _ProfileSelectState extends State<ProfileSelect> {
l10n.noAnonymousInstances,
style: theme.textTheme.bodyMedium?.copyWith(
fontStyle: FontStyle.italic,
color: theme.textTheme.bodyMedium?.color?.withOpacity(0.5),
color: theme.textTheme.bodyMedium?.color?.withValues(alpha: 0.5),
),
),
),
Expand Down Expand Up @@ -738,7 +738,7 @@ class _ProfileSelectState extends State<ProfileSelect> {
}

Future<void> fetchInstanceInfo(List<AccountExtended> accountsExtended) async {
accountsExtended.forEach((account) async {
for (final account in accountsExtended) {
final GetInstanceInfoResponse instanceinfoResponse = await getInstanceInfo(account.instance).timeout(
const Duration(seconds: 5),
onTimeout: () => const GetInstanceInfoResponse(success: false),
Expand All @@ -748,11 +748,11 @@ class _ProfileSelectState extends State<ProfileSelect> {
account.version = instanceinfoResponse.version;
account.alive = instanceinfoResponse.success;
});
});
}
}

Future<void> pingInstances(List<AccountExtended> accountsExtended) async {
accountsExtended.forEach((account) async {
for (final account in accountsExtended) {
if (account.instance != null) {
PingData pingData = await Ping(
account.instance!,
Expand All @@ -761,7 +761,7 @@ class _ProfileSelectState extends State<ProfileSelect> {
).stream.first;
setState(() => account.latency = pingData.response?.time);
}
});
}
}

Future<void> getUnreadCounts(List<AccountExtended> accountsExtended) async {
Expand All @@ -788,7 +788,7 @@ class _ProfileSelectState extends State<ProfileSelect> {
}

Future<void> fetchAnonymousInstanceInfo(List<AnonymousInstanceExtended> anonymousInstancesExtended) async {
anonymousInstancesExtended.forEach((anonymousInstanceExtended) async {
for (final anonymousInstanceExtended in anonymousInstancesExtended) {
final GetInstanceInfoResponse instanceInfoResponse = await getInstanceInfo(anonymousInstanceExtended.anonymousInstance.instance).timeout(
const Duration(seconds: 5),
onTimeout: () => const GetInstanceInfoResponse(success: false),
Expand All @@ -798,18 +798,18 @@ class _ProfileSelectState extends State<ProfileSelect> {
anonymousInstanceExtended.version = instanceInfoResponse.version;
anonymousInstanceExtended.alive = instanceInfoResponse.success;
});
});
}
}

Future<void> pingAnonymousInstances(List<AnonymousInstanceExtended> anonymousInstancesExtended) async {
anonymousInstancesExtended.forEach((anonymousInstanceExtended) async {
for (final anonymousInstanceExtended in anonymousInstancesExtended) {
PingData pingData = await Ping(
anonymousInstanceExtended.anonymousInstance.instance,
count: 1,
timeout: 5,
).stream.first;
setState(() => anonymousInstanceExtended.latency = pingData.response?.time);
});
}
}

/// Recalculates the indices of all accounts and anonymous instances in the database, given the current order in the UI.
Expand Down
8 changes: 4 additions & 4 deletions lib/comment/widgets/comment_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ class _CommentCardState extends State<CommentCard> with SingleTickerProviderStat
? AnimatedContainer(
alignment: Alignment.centerLeft,
color: swipeAction == null
? state.leftPrimaryCommentGesture.getColor(context).withOpacity(dismissThreshold / firstActionThreshold)
? state.leftPrimaryCommentGesture.getColor(context).withValues(alpha: dismissThreshold / firstActionThreshold)
: (swipeAction ?? SwipeAction.none).getColor(context),
duration: const Duration(milliseconds: 200),
child: SizedBox(
Expand All @@ -257,7 +257,7 @@ class _CommentCardState extends State<CommentCard> with SingleTickerProviderStat
: AnimatedContainer(
alignment: Alignment.centerRight,
color: swipeAction == null
? (state.rightPrimaryCommentGesture).getColor(context).withOpacity(dismissThreshold / firstActionThreshold)
? (state.rightPrimaryCommentGesture).getColor(context).withValues(alpha: dismissThreshold / firstActionThreshold)
: (swipeAction ?? SwipeAction.none).getColor(context),
duration: const Duration(milliseconds: 200),
child: SizedBox(
Expand All @@ -276,7 +276,7 @@ class _CommentCardState extends State<CommentCard> with SingleTickerProviderStat
? theme.colorScheme.surface
: nestedCommentIndicatorColor == NestedCommentIndicatorColor.colorful
? getCommentLevelColor(context, (widget.level - 1) % 6)
: theme.hintColor.withOpacity(0.25),
: theme.hintColor.withValues(alpha: 0.25),
),
)
: Border(
Expand Down Expand Up @@ -455,7 +455,7 @@ class _AdditionalCommentCardState extends State<AdditionalCommentCard> {
widget.replies == 1 ? l10n.loadMoreSingular(widget.replies) : l10n.loadMorePlural(widget.replies),
fontScale: state.commentFontSizeScale,
style: theme.textTheme.bodyMedium?.copyWith(
color: theme.textTheme.bodyMedium?.color?.withOpacity(0.5),
color: theme.textTheme.bodyMedium?.color?.withValues(alpha: 0.5),
),
),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ class _CommentCommentActionBottomSheetState extends State<CommentCommentActionBo
// child: Icon(
// Thunder.shield_crown,
// size: 20,
// color: Color.alphaBlend(theme.colorScheme.primary.withOpacity(0.4), Colors.red),
// color: Color.alphaBlend(theme.colorScheme.primary.withValues(alpha: 0.4), Colors.red),
// ),
// ),
// title: postPostAction.name,
Expand Down
8 changes: 4 additions & 4 deletions lib/community/widgets/community_drawer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class _CommunityDrawerState extends State<CommunityDrawer> {
style: TextButton.styleFrom(
alignment: Alignment.centerLeft,
minimumSize: const Size.fromHeight(50),
backgroundColor: isCommunitySelected ? theme.colorScheme.primaryContainer.withOpacity(0.25) : Colors.transparent,
backgroundColor: isCommunitySelected ? theme.colorScheme.primaryContainer.withValues(alpha: 0.25) : Colors.transparent,
),
onPressed: () {
Navigator.of(context).pop();
Expand Down Expand Up @@ -324,7 +324,7 @@ class FavoriteCommunities extends StatelessWidget {
style: TextButton.styleFrom(
alignment: Alignment.centerLeft,
minimumSize: const Size.fromHeight(50),
backgroundColor: isCommunitySelected ? theme.colorScheme.primaryContainer.withOpacity(0.25) : Colors.transparent,
backgroundColor: isCommunitySelected ? theme.colorScheme.primaryContainer.withValues(alpha: 0.25) : Colors.transparent,
),
onPressed: () {
Navigator.of(context).pop();
Expand Down Expand Up @@ -386,7 +386,7 @@ class ModeratedCommunities extends StatelessWidget {
style: TextButton.styleFrom(
alignment: Alignment.centerLeft,
minimumSize: const Size.fromHeight(50),
backgroundColor: isCommunitySelected ? theme.colorScheme.primaryContainer.withOpacity(0.25) : Colors.transparent,
backgroundColor: isCommunitySelected ? theme.colorScheme.primaryContainer.withValues(alpha: 0.25) : Colors.transparent,
),
onPressed: () {
Navigator.of(context).pop();
Expand Down Expand Up @@ -453,7 +453,7 @@ class DrawerItem extends StatelessWidget {
child: SizedBox(
height: 56.0,
child: Material(
color: isSelected ? theme.colorScheme.primaryContainer.withOpacity(0.25) : Colors.transparent,
color: isSelected ? theme.colorScheme.primaryContainer.withValues(alpha: 0.25) : Colors.transparent,
shape: const StadiumBorder(),
child: InkWell(
splashColor: disabled ? Colors.transparent : null,
Expand Down
6 changes: 3 additions & 3 deletions lib/community/widgets/community_header.dart
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ class _CommunityHeaderState extends State<CommunityHeader> {
colors: [
theme.colorScheme.surface,
theme.colorScheme.surface,
theme.colorScheme.surface.withOpacity(0.9),
theme.colorScheme.surface.withOpacity(0.6),
theme.colorScheme.surface.withOpacity(0.3),
theme.colorScheme.surface.withValues(alpha: 0.9),
theme.colorScheme.surface.withValues(alpha: 0.6),
theme.colorScheme.surface.withValues(alpha: 0.3),
],
),
),
Expand Down
6 changes: 3 additions & 3 deletions lib/community/widgets/community_sidebar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ class CommunityModeratorList extends StatelessWidget {
textStyle: const TextStyle(
fontSize: 13,
),
transformColor: (color) => color?.withOpacity(0.6),
transformColor: (color) => color?.withValues(alpha: 0.6),
// Override because we're showing display name above
useDisplayName: false,
),
Expand Down Expand Up @@ -465,12 +465,12 @@ class SidebarStat extends StatelessWidget {
child: Icon(
icon,
size: 18,
color: theme.colorScheme.onSurface.withOpacity(0.65),
color: theme.colorScheme.onSurface.withValues(alpha: 0.65),
),
),
Text(
value,
style: TextStyle(color: theme.textTheme.titleSmall?.color?.withOpacity(0.65)),
style: TextStyle(color: theme.textTheme.titleSmall?.color?.withValues(alpha: 0.65)),
),
],
);
Expand Down
7 changes: 4 additions & 3 deletions lib/community/widgets/post_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,9 @@ class _PostCardState extends State<PostCard> {
background: dismissDirection == DismissDirection.startToEnd
? AnimatedContainer(
alignment: Alignment.centerLeft,
color:
swipeAction == null ? state.leftPrimaryPostGesture.getColor(context).withOpacity(dismissThreshold / firstActionThreshold) : (swipeAction ?? SwipeAction.none).getColor(context),
color: swipeAction == null
? state.leftPrimaryPostGesture.getColor(context).withValues(alpha: dismissThreshold / firstActionThreshold)
: (swipeAction ?? SwipeAction.none).getColor(context),
duration: const Duration(milliseconds: 200),
child: SizedBox(
width: MediaQuery.of(context).size.width * (state.tabletMode ? 0.5 : 1) * dismissThreshold,
Expand All @@ -230,7 +231,7 @@ class _PostCardState extends State<PostCard> {
: AnimatedContainer(
alignment: Alignment.centerRight,
color: swipeAction == null
? state.rightPrimaryPostGesture.getColor(context).withOpacity(dismissThreshold / firstActionThreshold)
? state.rightPrimaryPostGesture.getColor(context).withValues(alpha: dismissThreshold / firstActionThreshold)
: (swipeAction ?? SwipeAction.none).getColor(context),
duration: const Duration(milliseconds: 200),
child: SizedBox(
Expand Down
Loading

0 comments on commit 6b8e789

Please sign in to comment.