Skip to content

Commit

Permalink
Refactor flutter auth if block to switch expr
Browse files Browse the repository at this point in the history
  • Loading branch information
dhzdhd committed Jun 27, 2023
1 parent 1863d0e commit edbf770
Showing 1 changed file with 24 additions and 28 deletions.
52 changes: 24 additions & 28 deletions lib/src/accounts/services/auth_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,18 @@ final class DropBoxAuth implements AuthService {
},
);

late final String result;
if (Platform.isAndroid) {
result = await FlutterWebAuth2.authenticate(
url: codeUri.toString(),
callbackUrlScheme: 'https',
preferEphemeral: true,
);
} else {
result = await FlutterWebAuth2WindowsPlugin().authenticate(
url: codeUri.toString(),
callbackUrlScheme: callbackUrlScheme,
preferEphemeral: true,
);
}
final result = switch (Platform.isAndroid) {
true => await FlutterWebAuth2.authenticate(
url: codeUri.toString(),
callbackUrlScheme: 'https',
preferEphemeral: true,
),
false => await FlutterWebAuth2WindowsPlugin().authenticate(
url: codeUri.toString(),
callbackUrlScheme: callbackUrlScheme,
preferEphemeral: true,
),
};

final code = Uri.parse(result).queryParameters['code'];
final tokenUri = Uri.https(
Expand Down Expand Up @@ -209,20 +207,18 @@ final class OneDriveAuth implements AuthService {
},
);

late final String result;
if (Platform.isAndroid) {
result = await FlutterWebAuth2.authenticate(
url: codeUri.toString(),
callbackUrlScheme: 'msauth',
preferEphemeral: true,
);
} else {
result = await FlutterWebAuth2WindowsPlugin().authenticate(
url: codeUri.toString(),
callbackUrlScheme: callbackUrlScheme,
preferEphemeral: true,
);
}
final result = switch (Platform.isAndroid) {
true => await FlutterWebAuth2.authenticate(
url: codeUri.toString(),
callbackUrlScheme: 'msauth',
preferEphemeral: true,
),
false => await FlutterWebAuth2WindowsPlugin().authenticate(
url: codeUri.toString(),
callbackUrlScheme: callbackUrlScheme,
preferEphemeral: true,
)
};

final code = Uri.parse(result).queryParameters['code'];
final tokenUri = Uri.https(
Expand Down

0 comments on commit edbf770

Please sign in to comment.