Skip to content

Commit

Permalink
Merge pull request #1521 from krille-chan/krille/fix-analyzer-warning…
Browse files Browse the repository at this point in the history
…s-new-flutter

refactor: Fix new lints coming with flutter 3.27
  • Loading branch information
krille-chan authored Dec 15, 2024
2 parents 21196a1 + dbe8c1b commit 73f448e
Show file tree
Hide file tree
Showing 20 changed files with 81 additions and 152 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/versions.env
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
FLUTTER_VERSION=3.24.5
FLUTTER_VERSION=3.27.0
JAVA_VERSION=17
4 changes: 3 additions & 1 deletion lib/pages/chat/chat.dart
Original file line number Diff line number Diff line change
Expand Up @@ -818,7 +818,9 @@ class ChatController extends State<ChatPageWithRoom>
for (final event in selectedEvents) {
if (!event.status.isSent) return false;
if (event.canRedact == false &&
!(clients!.any((cl) => event.senderId == cl!.userID))) return false;
!(clients!.any((cl) => event.senderId == cl!.userID))) {
return false;
}
}
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/pages/chat/chat_emoji_picker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class ChatEmojiPicker extends StatelessWidget {
categoryViewConfig: CategoryViewConfig(
backspaceColor: theme.colorScheme.primary,
iconColor:
theme.colorScheme.primary.withOpacity(0.5),
theme.colorScheme.primary.withAlpha(128),
iconColorSelected: theme.colorScheme.primary,
indicatorColor: theme.colorScheme.primary,
),
Expand Down
2 changes: 1 addition & 1 deletion lib/pages/chat/chat_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ class ChatView extends StatelessWidget {
),
if (controller.dragging)
Container(
color: theme.scaffoldBackgroundColor.withOpacity(0.9),
color: theme.scaffoldBackgroundColor.withAlpha(230),
alignment: Alignment.center,
child: const Icon(
Icons.upload_outlined,
Expand Down
37 changes: 0 additions & 37 deletions lib/pages/chat/events/html_message.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import 'package:flutter_highlighter/flutter_highlighter.dart';
import 'package:flutter_highlighter/themes/shades-of-purple.dart';
import 'package:flutter_html/flutter_html.dart';
import 'package:flutter_html_table/flutter_html_table.dart';
import 'package:flutter_math_fork/flutter_math.dart';
import 'package:html/dom.dart' as dom;
import 'package:linkify/linkify.dart';
import 'package:matrix/matrix.dart';
Expand Down Expand Up @@ -133,9 +132,6 @@ class HtmlMessage extends StatelessWidget {
extensions: [
RoomPillExtension(context, room, fontSize, linkColor),
CodeExtension(fontSize: fontSize),
MatrixMathExtension(
style: TextStyle(fontSize: fontSize, color: textColor),
),
const TableHtmlExtension(),
SpoilerExtension(textColor: textColor),
const ImageExtension(),
Expand Down Expand Up @@ -331,39 +327,6 @@ class SpoilerExtension extends HtmlExtension {
}
}

class MatrixMathExtension extends HtmlExtension {
final TextStyle? style;

MatrixMathExtension({this.style});
@override
Set<String> get supportedTags => {'div'};

@override
bool matches(ExtensionContext context) {
if (context.elementName != 'div') return false;
final mathData = context.element?.attributes['data-mx-maths'];
return mathData != null;
}

@override
InlineSpan build(ExtensionContext context) {
final data = context.element?.attributes['data-mx-maths'] ?? '';
return WidgetSpan(
child: Math.tex(
data,
textStyle: style,
onErrorFallback: (e) {
Logs().d('Flutter math parse error', e);
return Text(
data,
style: style,
);
},
),
);
}
}

class CodeExtension extends HtmlExtension {
final double fontSize;

Expand Down
2 changes: 1 addition & 1 deletion lib/pages/chat/events/reply_content.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class ReplyContent extends StatelessWidget {

return Material(
color: backgroundColor ??
theme.colorScheme.surface.withOpacity(ownMessage ? 0.2 : 0.33),
theme.colorScheme.surface.withAlpha(ownMessage ? 50 : 80),
borderRadius: borderRadius,
child: Row(
mainAxisSize: MainAxisSize.min,
Expand Down
2 changes: 1 addition & 1 deletion lib/pages/chat_list/status_msg_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ class PresenceAvatar extends StatelessWidget {

const statusMsgBubbleElevation = 6.0;
final statusMsgBubbleShadowColor = theme.colorScheme.surface;
final statusMsgBubbleColor = Colors.white.withOpacity(0.9);
final statusMsgBubbleColor = Colors.white.withAlpha(230);
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 8.0),
child: SizedBox(
Expand Down
4 changes: 3 additions & 1 deletion lib/pages/device_settings/device_settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ class DevicesSettingsController extends State<DevicesSettings> {
message: L10n.of(context).removeDevicesDescription,
isDestructive: true,
) ==
OkCancelResult.cancel) return;
OkCancelResult.cancel) {
return;
}
final matrix = Matrix.of(context);
final deviceIds = <String>[];
for (final userDevice in devices) {
Expand Down
2 changes: 0 additions & 2 deletions lib/pages/dialer/pip/pip_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -330,8 +330,6 @@ Map<PIPViewCorner, Offset> _calculateOffsets({
return Offset(left, bottom);
case PIPViewCorner.bottomRight:
return Offset(right, bottom);
default:
throw Exception('Not implemented.');
}
}

Expand Down
10 changes: 5 additions & 5 deletions lib/pages/image_viewer/image_viewer_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ class ImageViewerView extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.black.withOpacity(0.5),
backgroundColor: Colors.black.withAlpha(128),
extendBodyBehindAppBar: true,
appBar: AppBar(
elevation: 0,
leading: IconButton(
style: IconButton.styleFrom(
backgroundColor: Colors.black.withOpacity(0.5),
backgroundColor: Colors.black.withAlpha(128),
),
icon: const Icon(Icons.close),
onPressed: Navigator.of(context).pop,
Expand All @@ -31,7 +31,7 @@ class ImageViewerView extends StatelessWidget {
actions: [
IconButton(
style: IconButton.styleFrom(
backgroundColor: Colors.black.withOpacity(0.5),
backgroundColor: Colors.black.withAlpha(128),
),
icon: const Icon(Icons.reply_outlined),
onPressed: controller.forwardAction,
Expand All @@ -41,7 +41,7 @@ class ImageViewerView extends StatelessWidget {
const SizedBox(width: 8),
IconButton(
style: IconButton.styleFrom(
backgroundColor: Colors.black.withOpacity(0.5),
backgroundColor: Colors.black.withAlpha(128),
),
icon: const Icon(Icons.download_outlined),
onPressed: () => controller.saveFileAction(context),
Expand All @@ -56,7 +56,7 @@ class ImageViewerView extends StatelessWidget {
child: Builder(
builder: (context) => IconButton(
style: IconButton.styleFrom(
backgroundColor: Colors.black.withOpacity(0.5),
backgroundColor: Colors.black.withAlpha(128),
),
onPressed: () => controller.shareFileAction(context),
tooltip: L10n.of(context).share,
Expand Down
3 changes: 2 additions & 1 deletion lib/pages/settings_style/settings_style_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import 'package:fluffychat/config/setting_keys.dart';
import 'package:fluffychat/config/themes.dart';
import 'package:fluffychat/pages/chat/events/state_message.dart';
import 'package:fluffychat/utils/account_config.dart';
import 'package:fluffychat/utils/color_value.dart';
import 'package:fluffychat/widgets/avatar.dart';
import 'package:fluffychat/widgets/layouts/max_width_body.dart';
import 'package:fluffychat/widgets/matrix.dart';
Expand Down Expand Up @@ -100,7 +101,7 @@ class SettingsStyleView extends StatelessWidget {
child: Tooltip(
message: color == null
? L10n.of(context).systemTheme
: '#${color.value.toRadixString(16).toUpperCase()}',
: '#${color.hexValue.toRadixString(16).toUpperCase()}',
child: InkWell(
borderRadius: BorderRadius.circular(colorPickerSize),
onTap: () => controller.setChatColor(color),
Expand Down
14 changes: 14 additions & 0 deletions lib/utils/color_value.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import 'package:flutter/widgets.dart';

extension ColorValue on Color {
int get hexValue {
return _floatToInt8(a) << 24 |
_floatToInt8(r) << 16 |
_floatToInt8(g) << 8 |
_floatToInt8(b) << 0;
}

static int _floatToInt8(double x) {
return (x * 255.0).round() & 0xff;
}
}
2 changes: 1 addition & 1 deletion lib/utils/voip/video_renderer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class _VideoRendererState extends State<VideoRenderer> {
filterQuality: FilterQuality.medium,
objectFit: widget.fit,
placeholderBuilder: (_) =>
Container(color: Colors.white.withOpacity(0.18)),
Container(color: Colors.white.withAlpha(45)),
);
},
);
Expand Down
1 change: 0 additions & 1 deletion lib/widgets/connection_status_header.dart
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ extension on SyncStatusUpdate {
case SyncStatus.processing:
case SyncStatus.cleaningUp:
case SyncStatus.finished:
default:
return L10n.of(context).synchronizingPleaseWait;
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/widgets/error_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class _FluffyChatErrorWidgetState extends State<FluffyChatErrorWidget> {
child: Placeholder(
child: Center(
child: Material(
color: Colors.white.withOpacity(0.9),
color: Colors.white.withAlpha(230),
borderRadius: BorderRadius.circular(8),
),
),
Expand Down
1 change: 0 additions & 1 deletion lib/widgets/log_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ extension on LogEvent {
case Level.debug:
return Colors.white;
case Level.verbose:
default:
return Colors.grey;
}
}
Expand Down
8 changes: 4 additions & 4 deletions lib/widgets/qr_code_viewer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@ class QrCodeViewer extends StatelessWidget {
final theme = Theme.of(context);
final inviteLink = 'https://matrix.to/#/$content';
return Scaffold(
backgroundColor: Colors.black.withOpacity(0.5),
backgroundColor: Colors.black.withAlpha(128),
extendBodyBehindAppBar: true,
appBar: AppBar(
elevation: 0,
leading: IconButton(
style: IconButton.styleFrom(
backgroundColor: Colors.black.withOpacity(0.5),
backgroundColor: Colors.black.withAlpha(128),
),
icon: const Icon(Icons.close),
onPressed: Navigator.of(context).pop,
Expand All @@ -73,7 +73,7 @@ class QrCodeViewer extends StatelessWidget {
actions: [
IconButton(
style: IconButton.styleFrom(
backgroundColor: Colors.black.withOpacity(0.5),
backgroundColor: Colors.black.withAlpha(128),
),
icon: Icon(Icons.adaptive.share_outlined),
onPressed: () => FluffyShare.share(
Expand All @@ -86,7 +86,7 @@ class QrCodeViewer extends StatelessWidget {
const SizedBox(width: 8),
IconButton(
style: IconButton.styleFrom(
backgroundColor: Colors.black.withOpacity(0.5),
backgroundColor: Colors.black.withAlpha(128),
),
icon: const Icon(Icons.download_outlined),
onPressed: () => _save(context),
Expand Down
4 changes: 3 additions & 1 deletion lib/widgets/theme_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import 'package:dynamic_color/dynamic_color.dart';
import 'package:provider/provider.dart';
import 'package:shared_preferences/shared_preferences.dart';

import 'package:fluffychat/utils/color_value.dart';

class ThemeBuilder extends StatefulWidget {
final Widget Function(
BuildContext context,
Expand Down Expand Up @@ -72,7 +74,7 @@ class ThemeController extends State<ThemeBuilder> {
} else {
await preferences.setInt(
widget.primaryColorSettingsKey,
newPrimaryColor.value,
newPrimaryColor.hexValue,
);
}
setState(() {
Expand Down
Loading

0 comments on commit 73f448e

Please sign in to comment.