signIn method
Pushes a page onto the top of the Navigator stack containing a WebView holding the Spotify sign-in flow. Users must have a valid Spotify account and be signed in for Spotify nowplaying details to be available
Implementation
Future<bool?> signIn(context) {
final _controller = WebViewController()
..setJavaScriptMode(JavaScriptMode.unrestricted)
..setBackgroundColor(Colors.white)
..setNavigationDelegate(
NavigationDelegate(
onNavigationRequest: (navReq) {
if (navReq.url.startsWith(_redirectUri)) {
this._spotifyApi =
SpotifyApi.fromAuthCodeGrant(this._grant, navReq.url);
_saveCredentials();
Navigator.of(context).pop(true);
return NavigationDecision.prevent;
}
return NavigationDecision.navigate;
},
),
)
..loadRequest(_authUri);
return Navigator.of(context).push<bool>(
MaterialPageRoute(
builder: (context) => WebViewWidget(controller: _controller),
),
);
}