improve login

This commit is contained in:
wgh19
2024-06-12 17:03:45 +08:00
parent b14c2682a7
commit 70da478044
3 changed files with 76 additions and 28 deletions

View File

@@ -167,7 +167,11 @@
"Failed to register URL scheme.": "注册URL协议失败", "Failed to register URL scheme.": "注册URL协议失败",
"Retry": "重试", "Retry": "重试",
"Network": "网络", "Network": "网络",
"Save to gallery": "保存到相册" "Save to gallery": "保存到相册",
"Choose a way to login": "选择登录方式",
"Use Webview: you cannot sign in with Google.": "使用Webview: 无法使用Google登录",
"Use an external browser: You can sign in using Google. However, some browsers may not be compatible with the application": "使用外部浏览器: 可以使用Google登录. 但是, 一些浏览器可能与应用程序不兼容",
"External browser": "外部浏览器"
}, },
"zh_TW": { "zh_TW": {
"Search": "搜索", "Search": "搜索",
@@ -337,6 +341,10 @@
"Failed to register URL scheme.": "註冊URL協議失敗", "Failed to register URL scheme.": "註冊URL協議失敗",
"Retry": "重試", "Retry": "重試",
"Network": "網絡", "Network": "網絡",
"Save to gallery": "保存到相冊" "Save to gallery": "保存到相冊",
"Choose a way to login": "選擇登錄方式",
"Use Webview: you cannot sign in with Google.": "使用Webview: 無法使用Google登錄",
"Use an external browser: You can sign in using Google. However, some browsers may not be compatible with the application": "使用外部瀏覽器: 可以使用Google登錄. 但是, 一些瀏覽器可能與應用程序不兼容",
"External browser": "外部瀏覽器"
} }
} }

View File

@@ -42,13 +42,13 @@ class FluentButton extends BaseButton {
final double? width; final double? width;
static const _kFluentButtonPadding = 24; static const _kFluentButtonPadding = 12.0;
@override @override
Widget buildNormal(BuildContext context) { Widget buildNormal(BuildContext context) {
Widget child = this.child; Widget child = this.child;
if (width != null) { if (width != null) {
child = child.fixWidth(width! - _kFluentButtonPadding); child = child.fixWidth(width! - _kFluentButtonPadding * 2);
} }
return FilledButton( return FilledButton(
onPressed: onPressed, onPressed: onPressed,
@@ -59,15 +59,18 @@ class FluentButton extends BaseButton {
@override @override
Widget buildLoading(BuildContext context) { Widget buildLoading(BuildContext context) {
Widget child = Center( Widget child = Center(
widthFactor: 1,
heightFactor: 1,
child: const ProgressRing( child: const ProgressRing(
strokeWidth: 1.6, strokeWidth: 1.6,
).fixWidth(14).fixHeight(14), ).fixWidth(14).fixHeight(14),
); );
if (width != null) { if (width != null) {
child = child.fixWidth(width!); child = child.fixWidth(width! - _kFluentButtonPadding * 2);
} }
return Container( return Container(
height: 26, padding: const EdgeInsets.symmetric(
horizontal: _kFluentButtonPadding, vertical: 6.5),
decoration: BoxDecoration( decoration: BoxDecoration(
color: FluentTheme.of(context).inactiveBackgroundColor, color: FluentTheme.of(context).inactiveBackgroundColor,
borderRadius: BorderRadius.circular(4)), borderRadius: BorderRadius.circular(4)),
@@ -78,19 +81,20 @@ class FluentButton extends BaseButton {
@override @override
Widget buildDisabled(BuildContext context) { Widget buildDisabled(BuildContext context) {
Widget child = Center( Widget child = Center(
widthFactor: 1,
heightFactor: 1,
child: this.child, child: this.child,
); );
if (width != null) { if (width != null) {
child = child.fixWidth(width!); child = child.fixWidth(width! - _kFluentButtonPadding * 2);
} }
return Center( return Container(
child: Container( padding: const EdgeInsets.symmetric(
height: 26, horizontal: _kFluentButtonPadding, vertical: 6.5),
decoration: BoxDecoration( decoration: BoxDecoration(
color: FluentTheme.of(context).inactiveBackgroundColor, color: FluentTheme.of(context).inactiveBackgroundColor,
borderRadius: BorderRadius.circular(4)), borderRadius: BorderRadius.circular(4)),
child: child, child: child,
),
); );
} }
} }

View File

@@ -25,7 +25,7 @@ class _LoginPageState extends State<LoginPage> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
if(isLogging) { if (isLogging) {
return buildLoading(context); return buildLoading(context);
} else if (!waitingForAuth) { } else if (!waitingForAuth) {
return buildLogin(context); return buildLogin(context);
@@ -62,7 +62,7 @@ class _LoginPageState extends State<LoginPage> {
enabled: checked, enabled: checked,
width: 96, width: 96,
child: Text("Continue".tl), child: Text("Continue".tl),
), ),
const SizedBox( const SizedBox(
height: 16, height: 16,
), ),
@@ -176,6 +176,39 @@ class _LoginPageState extends State<LoginPage> {
} }
void onContinue() async { void onContinue() async {
bool? useExternal;
if (App.isMobile) {
await showDialog(
context: context,
barrierDismissible: true,
builder: (context) => ContentDialog(
title: Text("Choose a way to login".tl),
content: Text("${"Use Webview: you cannot sign in with Google.".tl}"
"\n\n"
"${"Use an external browser: You can sign in using Google. However, some browsers may not be compatible with the application".tl}"),
actions: [
Button(
child: Text("Webview".tl),
onPressed: () {
useExternal = false;
App.rootNavigatorKey.currentState!.pop();
},
),
Button(
child: Text("External browser".tl),
onPressed: () {
useExternal = true;
App.rootNavigatorKey.currentState!.pop();
},
)
]),
);
} else {
useExternal = true;
}
if (useExternal == null) {
return;
}
var url = await Network().generateWebviewUrl(); var url = await Network().generateWebviewUrl();
onLink = (uri) { onLink = (uri) {
if (uri.scheme == "pixiv") { if (uri.scheme == "pixiv") {
@@ -188,15 +221,18 @@ class _LoginPageState extends State<LoginPage> {
setState(() { setState(() {
waitingForAuth = true; waitingForAuth = true;
}); });
if(App.isMobile && mounted) { if (!useExternal! && mounted) {
context.to(() => WebviewPage(url, onNavigation: (req) { context.to(() => WebviewPage(
if(req.url.startsWith("pixiv://")) { url,
App.rootNavigatorKey.currentState!.pop(); onNavigation: (req) {
onLink?.call(Uri.parse(req.url)); if (req.url.startsWith("pixiv://")) {
return false; App.rootNavigatorKey.currentState!.pop();
} onLink?.call(Uri.parse(req.url));
return true; return false;
},)); }
return true;
},
));
} else { } else {
launchUrlString(url); launchUrlString(url);
} }
@@ -209,7 +245,7 @@ class _LoginPageState extends State<LoginPage> {
}); });
var res = await Network().loginWithCode(code); var res = await Network().loginWithCode(code);
if (res.error) { if (res.error) {
if(mounted) { if (mounted) {
context.showToast(message: res.errorMessage!); context.showToast(message: res.errorMessage!);
} }
setState(() { setState(() {