fix: Better authwebview

This commit is contained in:
Christian Pauly 2021-01-16 15:18:32 +01:00
parent d76df0ae4a
commit 5a1085ad0c
2 changed files with 12 additions and 4 deletions

View File

@ -6,17 +6,23 @@ import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:url_launcher/url_launcher.dart'; import 'package:url_launcher/url_launcher.dart';
import 'package:webview_flutter/webview_flutter.dart'; import 'package:webview_flutter/webview_flutter.dart';
class AuthWebView extends StatelessWidget { class AuthWebView extends StatefulWidget {
final String authType; final String authType;
final String session; final String session;
final Function onAuthDone; final Function onAuthDone;
const AuthWebView(this.authType, this.session, this.onAuthDone); const AuthWebView(this.authType, this.session, this.onAuthDone);
@override
_AuthWebViewState createState() => _AuthWebViewState();
}
class _AuthWebViewState extends State<AuthWebView> {
bool _isLoading = true;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final url = Matrix.of(context).client.homeserver.toString() + final url = Matrix.of(context).client.homeserver.toString() +
'/_matrix/client/r0/auth/$authType/fallback/web?session=$session'; '/_matrix/client/r0/auth/${widget.authType}/fallback/web?session=${widget.session}';
if (kIsWeb) launch(url); if (kIsWeb) launch(url);
return Scaffold( return Scaffold(
appBar: AppBar( appBar: AppBar(
@ -25,17 +31,18 @@ class AuthWebView extends StatelessWidget {
icon: Icon(Icons.close), icon: Icon(Icons.close),
onPressed: () { onPressed: () {
AdaptivePageLayout.of(context).pop(); AdaptivePageLayout.of(context).pop();
onAuthDone(); widget.onAuthDone();
}, },
), ),
), ),
body: Column( body: Column(
children: <Widget>[ children: <Widget>[
LinearProgressIndicator(), if (_isLoading) LinearProgressIndicator(),
Expanded( Expanded(
child: kIsWeb child: kIsWeb
? Center(child: Icon(Icons.link_outlined)) ? Center(child: Icon(Icons.link_outlined))
: WebView( : WebView(
onPageFinished: (_) => setState(() => _isLoading = false),
initialUrl: url, initialUrl: url,
javascriptMode: JavascriptMode.unrestricted, javascriptMode: JavascriptMode.unrestricted,
), ),

View File

@ -68,6 +68,7 @@ class _SignUpPasswordState extends State<SignUpPassword> {
); );
} else { } else {
if (_lastAuthWebViewStage == currentStage) { if (_lastAuthWebViewStage == currentStage) {
_lastAuthWebViewStage = null;
setState( setState(
() => passwordError = L10n.of(context).oopsSomethingWentWrong); () => passwordError = L10n.of(context).oopsSomethingWentWrong);
return setState(() => loading = false); return setState(() => loading = false);