feat: One page login
This commit is contained in:
parent
535ee062dd
commit
a6000ddf60
7 changed files with 258 additions and 331 deletions
|
|
@ -1,3 +1,7 @@
|
|||
import 'package:cached_network_image/cached_network_image.dart';
|
||||
import 'package:fluffychat/widgets/matrix.dart';
|
||||
import 'package:vrouter/vrouter.dart';
|
||||
|
||||
import '../homeserver_picker.dart';
|
||||
import 'package:fluffychat/widgets/default_app_bar_search_field.dart';
|
||||
import 'package:fluffychat/widgets/fluffy_banner.dart';
|
||||
|
|
@ -9,6 +13,9 @@ import 'package:flutter/foundation.dart';
|
|||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
import '../../utils/localized_exception_extension.dart';
|
||||
|
||||
import 'package:famedlysdk/famedlysdk.dart';
|
||||
|
||||
class HomeserverPickerView extends StatelessWidget {
|
||||
final HomeserverPickerController controller;
|
||||
|
|
@ -27,79 +34,159 @@ class HomeserverPickerView extends StatelessWidget {
|
|||
searchController: controller.homeserverController,
|
||||
suffix: Icon(Icons.edit_outlined),
|
||||
padding: EdgeInsets.zero,
|
||||
onChanged: (s) => controller.domain = s,
|
||||
onChanged: controller.setDomain,
|
||||
readOnly: !AppConfig.allowOtherHomeservers,
|
||||
onSubmit: (_) => controller.checkHomeserverAction(),
|
||||
unfocusOnClear: false,
|
||||
),
|
||||
elevation: 0,
|
||||
),
|
||||
body: SafeArea(
|
||||
child: ListView(
|
||||
body: ListView(children: [
|
||||
Hero(
|
||||
tag: 'loginBanner',
|
||||
child: FluffyBanner(),
|
||||
),
|
||||
controller.isLoading
|
||||
? Center(child: CircularProgressIndicator())
|
||||
: controller.error != null
|
||||
? Center(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(12.0),
|
||||
child: Text(
|
||||
controller.error,
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(
|
||||
fontSize: 18,
|
||||
color: Colors.red[900],
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
: FutureBuilder(
|
||||
future: controller.getLoginTypes(),
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.hasError) {
|
||||
return Center(
|
||||
child: Text(
|
||||
snapshot.error.toLocalizedString(context),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
);
|
||||
}
|
||||
if (!snapshot.hasData) {
|
||||
return Center(child: CircularProgressIndicator());
|
||||
}
|
||||
return Padding(
|
||||
padding: const EdgeInsets.all(12.0),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
if (controller.ssoLoginSupported) ...{
|
||||
for (final identityProvider
|
||||
in controller.identityProviders)
|
||||
OutlinedButton.icon(
|
||||
onPressed: () => controller
|
||||
.ssoLoginAction(identityProvider.id),
|
||||
icon: identityProvider.icon == null
|
||||
? Icon(Icons.web_outlined)
|
||||
: CachedNetworkImage(
|
||||
imageUrl: Uri.parse(
|
||||
identityProvider.icon)
|
||||
.getDownloadLink(
|
||||
Matrix.of(context).client)
|
||||
.toString(),
|
||||
width: 24,
|
||||
height: 24,
|
||||
),
|
||||
label: Text(L10n.of(context).loginWith(
|
||||
identityProvider.brand ??
|
||||
identityProvider.name ??
|
||||
L10n.of(context).singlesignon)),
|
||||
),
|
||||
if (controller.registrationSupported ||
|
||||
controller.passwordLoginSupported)
|
||||
Row(children: [
|
||||
Expanded(child: Divider()),
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(12.0),
|
||||
child: Text(L10n.of(context).or),
|
||||
),
|
||||
Expanded(child: Divider()),
|
||||
]),
|
||||
},
|
||||
Row(
|
||||
children: [
|
||||
if (controller.passwordLoginSupported)
|
||||
Expanded(
|
||||
child: Container(
|
||||
height: 64,
|
||||
child: OutlinedButton.icon(
|
||||
onPressed: () => VRouter.of(context)
|
||||
.push('/login'),
|
||||
icon: Icon(Icons.login_outlined),
|
||||
label: Text(L10n.of(context).login),
|
||||
),
|
||||
),
|
||||
),
|
||||
if (controller.registrationSupported &&
|
||||
controller.passwordLoginSupported)
|
||||
SizedBox(width: 12),
|
||||
if (controller.registrationSupported)
|
||||
Expanded(
|
||||
child: Container(
|
||||
height: 64,
|
||||
child: OutlinedButton.icon(
|
||||
onPressed: controller.signUpAction,
|
||||
icon: Icon(Icons.add_box_outlined),
|
||||
label:
|
||||
Text(L10n.of(context).register),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
]
|
||||
.map(
|
||||
(widget) => Container(
|
||||
height: 64,
|
||||
padding: EdgeInsets.only(bottom: 12),
|
||||
child: widget),
|
||||
)
|
||||
.toList(),
|
||||
),
|
||||
);
|
||||
}),
|
||||
]),
|
||||
bottomNavigationBar: Material(
|
||||
elevation: 7,
|
||||
color: Theme.of(context).scaffoldBackgroundColor,
|
||||
child: Wrap(
|
||||
alignment: WrapAlignment.center,
|
||||
children: [
|
||||
Hero(
|
||||
tag: 'loginBanner',
|
||||
child: FluffyBanner(),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
TextButton(
|
||||
onPressed: () => launch(AppConfig.privacyUrl),
|
||||
child: Text(
|
||||
AppConfig.applicationWelcomeMessage ??
|
||||
L10n.of(context).welcomeText,
|
||||
textAlign: TextAlign.center,
|
||||
L10n.of(context).privacy,
|
||||
style: TextStyle(
|
||||
fontSize: 22,
|
||||
decoration: TextDecoration.underline,
|
||||
color: Colors.blueGrey,
|
||||
),
|
||||
),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () => PlatformInfos.showDialog(context),
|
||||
child: Text(
|
||||
L10n.of(context).about,
|
||||
style: TextStyle(
|
||||
decoration: TextDecoration.underline,
|
||||
color: Colors.blueGrey,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
bottomNavigationBar: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Hero(
|
||||
tag: 'loginButton',
|
||||
child: Container(
|
||||
width: double.infinity,
|
||||
padding: EdgeInsets.symmetric(horizontal: 12),
|
||||
child: ElevatedButton(
|
||||
onPressed: controller.isLoading
|
||||
? null
|
||||
: controller.checkHomeserverAction,
|
||||
child: controller.isLoading
|
||||
? LinearProgressIndicator()
|
||||
: Text(L10n.of(context).connect),
|
||||
),
|
||||
),
|
||||
),
|
||||
Wrap(
|
||||
alignment: WrapAlignment.center,
|
||||
children: [
|
||||
TextButton(
|
||||
onPressed: () => launch(AppConfig.privacyUrl),
|
||||
child: Text(
|
||||
L10n.of(context).privacy,
|
||||
style: TextStyle(
|
||||
decoration: TextDecoration.underline,
|
||||
color: Colors.blueGrey,
|
||||
),
|
||||
),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () => PlatformInfos.showDialog(context),
|
||||
child: Text(
|
||||
L10n.of(context).about,
|
||||
style: TextStyle(
|
||||
decoration: TextDecoration.underline,
|
||||
color: Colors.blueGrey,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,136 +0,0 @@
|
|||
import 'package:cached_network_image/cached_network_image.dart';
|
||||
import 'package:vrouter/vrouter.dart';
|
||||
import 'package:fluffychat/pages/sign_up.dart';
|
||||
import 'package:fluffychat/widgets/fluffy_banner.dart';
|
||||
|
||||
import 'package:fluffychat/widgets/matrix.dart';
|
||||
import 'package:fluffychat/widgets/layouts/one_page_card.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
import '../../utils/localized_exception_extension.dart';
|
||||
|
||||
import 'package:famedlysdk/famedlysdk.dart';
|
||||
|
||||
class SignUpView extends StatelessWidget {
|
||||
final SignUpController controller;
|
||||
|
||||
const SignUpView(this.controller, {Key key}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return OnePageCard(
|
||||
child: Scaffold(
|
||||
appBar: AppBar(
|
||||
elevation: 0,
|
||||
title: Text(
|
||||
Matrix.of(context)
|
||||
.client
|
||||
.homeserver
|
||||
.toString()
|
||||
.replaceFirst('https://', ''),
|
||||
),
|
||||
),
|
||||
body: FutureBuilder(
|
||||
future: controller.getLoginTypes(),
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.hasError) {
|
||||
return Center(
|
||||
child: Text(
|
||||
snapshot.error.toLocalizedString(context),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
);
|
||||
}
|
||||
if (!snapshot.hasData) {
|
||||
return Center(child: CircularProgressIndicator());
|
||||
}
|
||||
return ListView(children: <Widget>[
|
||||
Hero(
|
||||
tag: 'loginBanner',
|
||||
child: FluffyBanner(),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(12.0),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
if (controller.ssoLoginSupported) ...{
|
||||
for (final identityProvider
|
||||
in controller.identityProviders)
|
||||
OutlinedButton.icon(
|
||||
onPressed: () =>
|
||||
controller.ssoLoginAction(identityProvider.id),
|
||||
icon: identityProvider.icon == null
|
||||
? Icon(Icons.web_outlined)
|
||||
: CachedNetworkImage(
|
||||
imageUrl: Uri.parse(identityProvider.icon)
|
||||
.getDownloadLink(
|
||||
Matrix.of(context).client)
|
||||
.toString(),
|
||||
width: 24,
|
||||
height: 24,
|
||||
),
|
||||
label: Text(L10n.of(context).loginWith(
|
||||
identityProvider.brand ??
|
||||
identityProvider.name ??
|
||||
L10n.of(context).singlesignon)),
|
||||
),
|
||||
if (controller.registrationSupported ||
|
||||
controller.passwordLoginSupported)
|
||||
Row(children: [
|
||||
Expanded(child: Divider()),
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(12.0),
|
||||
child: Text(L10n.of(context).or),
|
||||
),
|
||||
Expanded(child: Divider()),
|
||||
]),
|
||||
},
|
||||
Row(
|
||||
children: [
|
||||
if (controller.passwordLoginSupported)
|
||||
Expanded(
|
||||
child: Container(
|
||||
height: 64,
|
||||
child: OutlinedButton.icon(
|
||||
onPressed: () =>
|
||||
context.vRouter.push('/login'),
|
||||
icon: Icon(Icons.login_outlined),
|
||||
label: Text(L10n.of(context).login),
|
||||
),
|
||||
),
|
||||
),
|
||||
if (controller.registrationSupported &&
|
||||
controller.passwordLoginSupported)
|
||||
SizedBox(width: 12),
|
||||
if (controller.registrationSupported)
|
||||
Expanded(
|
||||
child: Container(
|
||||
height: 64,
|
||||
child: OutlinedButton.icon(
|
||||
onPressed: controller.signUpAction,
|
||||
icon: Icon(Icons.add_box_outlined),
|
||||
label: Text(L10n.of(context).register),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
]
|
||||
.map(
|
||||
(widget) => Container(
|
||||
height: 64,
|
||||
padding: EdgeInsets.only(bottom: 12),
|
||||
child: widget),
|
||||
)
|
||||
.toList(),
|
||||
),
|
||||
),
|
||||
]);
|
||||
}),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue