refactor: Avoid redundant async

This commit is contained in:
Christian Kußowski 2026-02-19 08:47:10 +01:00
parent 9d007815df
commit d08364688e
No known key found for this signature in database
GPG key ID: E067ECD60F1A0652
15 changed files with 169 additions and 182 deletions

View file

@ -23,3 +23,4 @@ analyzer:
dart_code_linter: dart_code_linter:
rules: rules:
- avoid-dynamic - avoid-dynamic
- avoid-redundant-async

View file

@ -17,38 +17,26 @@ import 'users.dart';
void main() { void main() {
IntegrationTestWidgetsFlutterBinding.ensureInitialized(); IntegrationTestWidgetsFlutterBinding.ensureInitialized();
group( group('Integration Test', () {
'Integration Test', setUpAll(() {
() {
setUpAll(
() async {
// this random dialog popping up is super hard to cover in tests // this random dialog popping up is super hard to cover in tests
SharedPreferences.setMockInitialValues({ SharedPreferences.setMockInitialValues({
'chat.fluffy.show_no_google': false, 'chat.fluffy.show_no_google': false,
}); });
}, });
);
testWidgets( testWidgets('Start app, login and logout', (WidgetTester tester) async {
'Start app, login and logout',
(WidgetTester tester) async {
app.main(); app.main();
await tester.ensureAppStartedHomescreen(); await tester.ensureAppStartedHomescreen();
await tester.ensureLoggedOut(); await tester.ensureLoggedOut();
}, });
);
testWidgets( testWidgets('Login again', (WidgetTester tester) async {
'Login again',
(WidgetTester tester) async {
app.main(); app.main();
await tester.ensureAppStartedHomescreen(); await tester.ensureAppStartedHomescreen();
}, });
);
testWidgets( testWidgets('Start chat and send message', (WidgetTester tester) async {
'Start chat and send message',
(WidgetTester tester) async {
app.main(); app.main();
await tester.ensureAppStartedHomescreen(); await tester.ensureAppStartedHomescreen();
await tester.waitFor(find.byType(TextField)); await tester.waitFor(find.byType(TextField));
@ -109,8 +97,7 @@ void main() {
await tester.pumpAndSettle(); await tester.pumpAndSettle();
await tester.waitFor(find.text('Test')); await tester.waitFor(find.text('Test'));
await tester.pumpAndSettle(); await tester.pumpAndSettle();
}, });
);
testWidgets('Spaces', (tester) async { testWidgets('Spaces', (tester) async {
app.main(); app.main();
@ -182,6 +169,5 @@ void main() {
expect(find.text(Users.user2.name), findsOneWidget); expect(find.text(Users.user2.name), findsOneWidget);
}); });
}, });
);
} }

View file

@ -90,7 +90,7 @@ class BootstrapDialogState extends State<BootstrapDialog> {
context.canPop() ? context.pop(success) : context.go('/rooms'); context.canPop() ? context.pop(success) : context.go('/rooms');
} }
void _decryptLastEvents() async { void _decryptLastEvents() {
for (final room in client.rooms) { for (final room in client.rooms) {
final event = room.lastEvent; final event = room.lastEvent;
if (event != null && if (event != null &&

View file

@ -257,7 +257,7 @@ class ChatController extends State<ChatPageWithRoom>
} }
} }
void _loadDraft() async { void _loadDraft() {
final prefs = Matrix.of(context).store; final prefs = Matrix.of(context).store;
final draft = prefs.getString('draft_$roomId'); final draft = prefs.getString('draft_$roomId');
if (draft != null && draft.isNotEmpty) { if (draft != null && draft.isNotEmpty) {

View file

@ -27,11 +27,7 @@ class PollWidget extends StatelessWidget {
void _endPoll(BuildContext context) => void _endPoll(BuildContext context) =>
showFutureLoadingDialog(context: context, future: () => event.endPoll()); showFutureLoadingDialog(context: context, future: () => event.endPoll());
void _toggleVote( void _toggleVote(BuildContext context, String answerId, int maxSelection) {
BuildContext context,
String answerId,
int maxSelection,
) async {
final userId = event.room.client.userID!; final userId = event.room.client.userID!;
final answerIds = event.getPollResponses(timeline)[userId] ?? {}; final answerIds = event.getPollResponses(timeline)[userId] ?? {};
if (!answerIds.remove(answerId)) { if (!answerIds.remove(answerId)) {

View file

@ -372,7 +372,7 @@ class ChatListController extends State<ChatList>
scrollController.addListener(_onScroll); scrollController.addListener(_onScroll);
_waitForFirstSync(); _waitForFirstSync();
_hackyWebRTCFixForWeb(); _hackyWebRTCFixForWeb();
WidgetsBinding.instance.addPostFrameCallback((_) async { WidgetsBinding.instance.addPostFrameCallback((_) {
if (mounted) { if (mounted) {
searchServer = Matrix.of( searchServer = Matrix.of(
context, context,

View file

@ -189,7 +189,7 @@ class MyCallingPage extends State<Calling> {
_playCallSound(); _playCallSound();
} }
void initialize() async { void initialize() {
final call = this.call; final call = this.call;
call.onCallStateChanged.stream.listen(_handleCallState); call.onCallStateChanged.stream.listen(_handleCallState);
call.onCallEventChanged.stream.listen((event) { call.onCallEventChanged.stream.listen((event) {
@ -282,7 +282,7 @@ class MyCallingPage extends State<Calling> {
}); });
} }
void _screenSharing() async { void _screenSharing() {
if (PlatformInfos.isAndroid) { if (PlatformInfos.isAndroid) {
if (!call.screensharingEnabled) { if (!call.screensharingEnabled) {
FlutterForegroundTask.init( FlutterForegroundTask.init(

View file

@ -66,7 +66,7 @@ class InvitationSelectionController extends State<InvitationSelection> {
} }
} }
void searchUserWithCoolDown(String text) async { void searchUserWithCoolDown(String text) {
coolDown?.cancel(); coolDown?.cancel();
coolDown = Timer( coolDown = Timer(
const Duration(milliseconds: 500), const Duration(milliseconds: 500),

View file

@ -94,7 +94,7 @@ class LoginController extends State<Login> {
Timer? _coolDown; Timer? _coolDown;
void checkWellKnownWithCoolDown(String userId) async { void checkWellKnownWithCoolDown(String userId) {
_coolDown?.cancel(); _coolDown?.cancel();
_coolDown = Timer( _coolDown = Timer(
const Duration(seconds: 1), const Duration(seconds: 1),

View file

@ -19,7 +19,7 @@ class SettingsStyle extends StatefulWidget {
} }
class SettingsStyleController extends State<SettingsStyle> { class SettingsStyleController extends State<SettingsStyle> {
void setChatColor(Color? color) async { void setChatColor(Color? color) {
AppSettings.colorSchemeSeedInt.setItem( AppSettings.colorSchemeSeedInt.setItem(
color?.toARGB32() ?? AppSettings.colorSchemeSeedInt.defaultValue, color?.toARGB32() ?? AppSettings.colorSchemeSeedInt.defaultValue,
); );

View file

@ -1 +1,2 @@
Future<void> applyWorkaroundToOpenSqlCipherOnOldAndroidVersions() async {} Future<void> applyWorkaroundToOpenSqlCipherOnOldAndroidVersions() =>
Future.value();

View file

@ -27,7 +27,7 @@ class QrCodeViewer extends StatelessWidget {
void _save(BuildContext context) async { void _save(BuildContext context) async {
final imageResult = await showFutureLoadingDialog( final imageResult = await showFutureLoadingDialog(
context: context, context: context,
future: () async { future: () {
final inviteLink = 'https://matrix.to/#/$content'; final inviteLink = 'https://matrix.to/#/$content';
final image = QRImage(inviteLink, size: 256, radius: 1).generate(); final image = QRImage(inviteLink, size: 256, radius: 1).generate();
return compute(encodePng, image); return compute(encodePng, image);

View file

@ -6,5 +6,6 @@ void main() {
testWidget: Archive(), testWidget: Archive(),
testClient: await testClient(loggedIn: true), testClient: await testClient(loggedIn: true),
));*/ ));*/
return;
}); });
} }

View file

@ -13,5 +13,6 @@ void main() {
testWidget: HomeserverPicker(), testWidget: HomeserverPicker(),
), ),
);*/ );*/
return;
}); });
} }

View file

@ -16,5 +16,6 @@ void main() {
/* await tester.pumpWidget(FluffyChatApp( /* await tester.pumpWidget(FluffyChatApp(
client: await prepareTestClient(), client: await prepareTestClient(),
));*/ ));*/
return;
}); });
} }