2021-01-16 12:46:38 +01:00
|
|
|
import 'package:adaptive_page_layout/adaptive_page_layout.dart';
|
2020-01-14 15:53:35 +01:00
|
|
|
import 'package:fluffychat/components/matrix.dart';
|
2020-02-17 14:07:57 +01:00
|
|
|
import 'package:flutter/foundation.dart';
|
2020-01-14 15:53:35 +01:00
|
|
|
import 'package:flutter/material.dart';
|
2020-10-03 13:11:07 +02:00
|
|
|
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
2020-02-17 14:07:57 +01:00
|
|
|
import 'package:url_launcher/url_launcher.dart';
|
2020-01-14 15:53:35 +01:00
|
|
|
import 'package:webview_flutter/webview_flutter.dart';
|
|
|
|
|
2021-01-16 15:18:32 +01:00
|
|
|
class AuthWebView extends StatefulWidget {
|
2020-01-14 15:53:35 +01:00
|
|
|
final String authType;
|
|
|
|
final String session;
|
|
|
|
final Function onAuthDone;
|
|
|
|
|
|
|
|
const AuthWebView(this.authType, this.session, this.onAuthDone);
|
|
|
|
|
2021-01-16 15:18:32 +01:00
|
|
|
@override
|
|
|
|
_AuthWebViewState createState() => _AuthWebViewState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _AuthWebViewState extends State<AuthWebView> {
|
|
|
|
bool _isLoading = true;
|
2020-01-14 15:53:35 +01:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2020-08-16 12:54:43 +02:00
|
|
|
final url = Matrix.of(context).client.homeserver.toString() +
|
2021-01-16 15:18:32 +01:00
|
|
|
'/_matrix/client/r0/auth/${widget.authType}/fallback/web?session=${widget.session}';
|
2020-02-17 14:07:57 +01:00
|
|
|
if (kIsWeb) launch(url);
|
2020-01-14 15:53:35 +01:00
|
|
|
return Scaffold(
|
|
|
|
appBar: AppBar(
|
2020-05-07 07:52:40 +02:00
|
|
|
title: Text(L10n.of(context).authentication),
|
2020-01-14 15:53:35 +01:00
|
|
|
leading: IconButton(
|
2020-02-16 08:35:35 +01:00
|
|
|
icon: Icon(Icons.close),
|
2020-01-14 15:53:35 +01:00
|
|
|
onPressed: () {
|
2021-01-16 12:46:38 +01:00
|
|
|
AdaptivePageLayout.of(context).pop();
|
2021-01-16 15:18:32 +01:00
|
|
|
widget.onAuthDone();
|
2020-01-14 15:53:35 +01:00
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
2020-02-16 08:35:35 +01:00
|
|
|
body: Column(
|
|
|
|
children: <Widget>[
|
2021-01-16 15:18:32 +01:00
|
|
|
if (_isLoading) LinearProgressIndicator(),
|
2020-02-16 08:35:35 +01:00
|
|
|
Expanded(
|
2020-02-17 14:07:57 +01:00
|
|
|
child: kIsWeb
|
2020-12-06 10:31:35 +01:00
|
|
|
? Center(child: Icon(Icons.link_outlined))
|
2020-02-17 14:07:57 +01:00
|
|
|
: WebView(
|
2021-01-16 15:18:32 +01:00
|
|
|
onPageFinished: (_) => setState(() => _isLoading = false),
|
2020-02-17 14:07:57 +01:00
|
|
|
initialUrl: url,
|
|
|
|
javascriptMode: JavascriptMode.unrestricted,
|
|
|
|
),
|
2020-02-16 08:35:35 +01:00
|
|
|
),
|
|
|
|
],
|
2020-01-14 15:53:35 +01:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|