🐛 Fix platform specific captcha solution cause build failed.
This commit is contained in:
parent
9311bfc3b5
commit
6bcb658d44
@ -7,7 +7,7 @@ import 'package:material_symbols_icons/symbols.dart';
|
|||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
import 'package:styled_widget/styled_widget.dart';
|
import 'package:styled_widget/styled_widget.dart';
|
||||||
import 'package:surface/providers/sn_network.dart';
|
import 'package:surface/providers/sn_network.dart';
|
||||||
import 'package:surface/screens/captcha.dart';
|
import 'package:surface/screens/captcha/captcha.dart';
|
||||||
import 'package:surface/widgets/dialog.dart';
|
import 'package:surface/widgets/dialog.dart';
|
||||||
import 'package:surface/widgets/navigation/app_scaffold.dart';
|
import 'package:surface/widgets/navigation/app_scaffold.dart';
|
||||||
import 'package:url_launcher/url_launcher_string.dart';
|
import 'package:url_launcher/url_launcher_string.dart';
|
||||||
|
3
lib/screens/captcha/captcha.dart
Normal file
3
lib/screens/captcha/captcha.dart
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
import 'package:flutter/foundation.dart' show kIsWeb;
|
||||||
|
|
||||||
|
export 'captcha_native.dart' if (kIsWeb) 'captcha_web.dart';
|
37
lib/screens/captcha/captcha_native.dart
Normal file
37
lib/screens/captcha/captcha_native.dart
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
import 'package:easy_localization/easy_localization.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
|
||||||
|
import 'package:provider/provider.dart';
|
||||||
|
import 'package:surface/providers/config.dart';
|
||||||
|
import 'package:surface/widgets/navigation/app_scaffold.dart';
|
||||||
|
|
||||||
|
class CaptchaScreen extends StatefulWidget {
|
||||||
|
const CaptchaScreen({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<CaptchaScreen> createState() => _CaptchaScreenState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _CaptchaScreenState extends State<CaptchaScreen> {
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final cfg = context.read<ConfigProvider>();
|
||||||
|
|
||||||
|
return AppScaffold(
|
||||||
|
appBar: AppBar(title: Text("reCaptcha").tr()),
|
||||||
|
body: InAppWebView(
|
||||||
|
initialUrlRequest: URLRequest(
|
||||||
|
url: WebUri('${cfg.serverUrl}/captcha?redirect_uri=solink://captcha'),
|
||||||
|
),
|
||||||
|
shouldOverrideUrlLoading: (controller, navigationAction) async {
|
||||||
|
Uri? url = navigationAction.request.url;
|
||||||
|
if (url != null && url.queryParameters.containsKey('captcha_tk')) {
|
||||||
|
Navigator.pop(context, url.queryParameters['captcha_tk']!);
|
||||||
|
return NavigationActionPolicy.CANCEL;
|
||||||
|
}
|
||||||
|
return NavigationActionPolicy.ALLOW;
|
||||||
|
},
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -1,17 +1,13 @@
|
|||||||
import 'dart:html' as html;
|
import 'dart:html' as html;
|
||||||
import 'dart:ui_web' as ui;
|
import 'dart:ui_web' as ui;
|
||||||
import 'package:easy_localization/easy_localization.dart';
|
import 'package:easy_localization/easy_localization.dart';
|
||||||
import 'package:flutter/foundation.dart' show kIsWeb;
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
|
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
import 'package:surface/providers/config.dart';
|
import 'package:surface/providers/config.dart';
|
||||||
import 'package:surface/widgets/navigation/app_scaffold.dart';
|
import 'package:surface/widgets/navigation/app_scaffold.dart';
|
||||||
|
|
||||||
class CaptchaScreen extends StatefulWidget {
|
class CaptchaScreen extends StatefulWidget {
|
||||||
const CaptchaScreen({
|
const CaptchaScreen({super.key});
|
||||||
super.key,
|
|
||||||
});
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<CaptchaScreen> createState() => _CaptchaScreenState();
|
State<CaptchaScreen> createState() => _CaptchaScreenState();
|
||||||
@ -21,9 +17,7 @@ class _CaptchaScreenState extends State<CaptchaScreen> {
|
|||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
if (kIsWeb) {
|
_setupWebListener();
|
||||||
_setupWebListener();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void _setupWebListener() {
|
void _setupWebListener() {
|
||||||
@ -37,9 +31,8 @@ class _CaptchaScreenState extends State<CaptchaScreen> {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Create an iframe for the captcha page
|
|
||||||
final iframe = html.IFrameElement()
|
final iframe = html.IFrameElement()
|
||||||
..src = '${context.read<ConfigProvider>().serverUrl}/captcha?redirect_uri=solink://captcha'
|
..src = '${context.read<ConfigProvider>().serverUrl}/captcha?redirect_uri=web'
|
||||||
..style.border = 'none'
|
..style.border = 'none'
|
||||||
..width = '100%'
|
..width = '100%'
|
||||||
..height = '100%';
|
..height = '100%';
|
||||||
@ -47,36 +40,15 @@ class _CaptchaScreenState extends State<CaptchaScreen> {
|
|||||||
html.document.body!.append(iframe);
|
html.document.body!.append(iframe);
|
||||||
ui.platformViewRegistry.registerViewFactory(
|
ui.platformViewRegistry.registerViewFactory(
|
||||||
'captcha-iframe',
|
'captcha-iframe',
|
||||||
(int viewId) => iframe,
|
(int viewId) => iframe,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final cfg = context.read<ConfigProvider>();
|
|
||||||
|
|
||||||
if (kIsWeb) {
|
|
||||||
return AppScaffold(
|
|
||||||
appBar: AppBar(title: Text("reCaptcha").tr()),
|
|
||||||
body: HtmlElementView(viewType: 'captcha-iframe'),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return AppScaffold(
|
return AppScaffold(
|
||||||
appBar: AppBar(title: Text("reCaptcha").tr()),
|
appBar: AppBar(title: Text("reCaptcha").tr()),
|
||||||
body: InAppWebView(
|
body: HtmlElementView(viewType: 'captcha-iframe'),
|
||||||
initialUrlRequest: URLRequest(
|
|
||||||
url: WebUri('${cfg.serverUrl}/captcha?redirect_uri=solink://captcha'),
|
|
||||||
),
|
|
||||||
shouldOverrideUrlLoading: (controller, navigationAction) async {
|
|
||||||
Uri? url = navigationAction.request.url;
|
|
||||||
if (url != null && url.queryParameters.containsKey('captcha_tk')) {
|
|
||||||
Navigator.pop(context, url.queryParameters['captcha_tk']!);
|
|
||||||
return NavigationActionPolicy.CANCEL;
|
|
||||||
}
|
|
||||||
return NavigationActionPolicy.ALLOW;
|
|
||||||
},
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -18,7 +18,7 @@ import 'package:surface/providers/sn_network.dart';
|
|||||||
import 'package:surface/providers/special_day.dart';
|
import 'package:surface/providers/special_day.dart';
|
||||||
import 'package:surface/providers/userinfo.dart';
|
import 'package:surface/providers/userinfo.dart';
|
||||||
import 'package:surface/providers/widget.dart';
|
import 'package:surface/providers/widget.dart';
|
||||||
import 'package:surface/screens/captcha.dart';
|
import 'package:surface/screens/captcha/captcha.dart';
|
||||||
import 'package:surface/types/check_in.dart';
|
import 'package:surface/types/check_in.dart';
|
||||||
import 'package:surface/types/post.dart';
|
import 'package:surface/types/post.dart';
|
||||||
import 'package:surface/widgets/app_bar_leading.dart';
|
import 'package:surface/widgets/app_bar_leading.dart';
|
||||||
|
Loading…
x
Reference in New Issue
Block a user