login method
Logs the user in.
If the user has a native Twitter client installed, this will present a native login screen. Otherwise a WebView is used.
The "Callback URL" field must be configured to a valid address in your app's "Settings" tab. When using the Twitter login only on mobile devices, an example of a valid callback url would be http://127.0.0.1:4000.
Use TwitterAuthResult.status for determining if the login was successful or not. For example:
final TwitterAuthResult result = await twitterAuth.login();
switch (result.status) {
case TwitterLoginStatus.loggedIn:
var session = result.session;
_sendTokenAndSecretToServer(session.token, session.secret);
break;
case TwitterLoginStatus.cancelled:
_showCancelMessage();
break;
}
See the TwitterAuthResult class for more documentation.
Implementation
Future<TwitterAuthResult> login({bool requestEmail = false}) async {
final Map<dynamic, dynamic>? result =
await _channel.invokeMethod(_kMethodLogin, [requestEmail]);
if (result != null) {
if (result['status'] != 'failed') {
return TwitterAuthResult._(result.cast<String, dynamic>());
}
throw _parseException(result.cast<String, dynamic>());
}
return TwitterAuthResult.unknwon();
}