FurryChat/lib/views/auth_web_view.dart

48 lines
1.3 KiB
Dart
Raw Normal View History

2020-02-17 13:07:57 +00:00
import 'package:flutter/foundation.dart';
2020-01-14 14:53:35 +00:00
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart';
2020-02-17 13:07:57 +00:00
import 'package:url_launcher/url_launcher.dart';
2020-01-14 14:53:35 +00:00
import 'package:webview_flutter/webview_flutter.dart';
2020-10-15 13:51:24 +00:00
import '../components/matrix.dart';
2020-01-14 14:53:35 +00:00
class AuthWebView extends StatelessWidget {
final String authType;
final String session;
final Function onAuthDone;
const AuthWebView(this.authType, this.session, this.onAuthDone);
@override
Widget build(BuildContext context) {
2020-08-16 10:54:43 +00:00
final url = Matrix.of(context).client.homeserver.toString() +
2020-06-10 08:07:01 +00:00
'/_matrix/client/r0/auth/$authType/fallback/web?session=$session';
2020-02-17 13:07:57 +00:00
if (kIsWeb) launch(url);
2020-01-14 14:53:35 +00:00
return Scaffold(
appBar: AppBar(
2020-05-07 05:52:40 +00:00
title: Text(L10n.of(context).authentication),
2020-01-14 14:53:35 +00:00
leading: IconButton(
2020-02-16 07:35:35 +00:00
icon: Icon(Icons.close),
2020-01-14 14:53:35 +00:00
onPressed: () {
Navigator.of(context).pop();
2020-02-16 07:35:35 +00:00
onAuthDone();
2020-01-14 14:53:35 +00:00
},
),
),
2020-02-16 07:35:35 +00:00
body: Column(
children: <Widget>[
LinearProgressIndicator(),
Expanded(
2020-02-17 13:07:57 +00:00
child: kIsWeb
? Center(child: Icon(Icons.link))
: WebView(
initialUrl: url,
javascriptMode: JavascriptMode.unrestricted,
),
2020-02-16 07:35:35 +00:00
),
],
2020-01-14 14:53:35 +00:00
),
);
}
}