Приложение позволяет пользователям входить в систему, отправляя на главной странице только свой адрес электронной почты. Они получают ссылку для входа по электронной почте, которая выглядит следующим образом:
https://newtestwebsiteofmine.com/?uid=1 ... f454a89b51
Когда они нажимают ссылку, приложение должно открыться по глубокой ссылке и войти в систему. Это отлично работает в браузере, но когда приложение открывается по глубокой ссылке, WebView по-прежнему показывает сообщение «проверьте свой почтовый ящик для входа в систему». URL-адрес» и не обновляет и не загружает URL-адрес входа с параметрами.
Вопрос:
Как я могу прослушивать глубокую ссылку в Flutter WebView или принудительно WebView для загрузки URL-адреса с параметрами входа, чтобы пользователь мог войти в систему?
Вот что я сделал до сих пор:
- добавлена поддержка глубоких ссылок в AndroinManifest.xml
Код: Выделить всё
- main.dart
Код: Выделить всё
import 'package:flutter/material.dart'; import 'package:webview_flutter/webview_flutter.dart'; import 'package:go_router/go_router.dart'; void main() { runApp(const newtestwebsiteofmineCOMM()); } class newtestwebsiteofmineCOMM extends StatefulWidget { const newtestwebsiteofmineCOMM({super.key}); @override State createState() => _newtestwebsiteofmineCOMMState(); } class _newtestwebsiteofmineCOMMState extends State { late final WebViewController _controller; bool _isLoading = true; bool _isError = false; @override void initState() { super.initState(); _controller = WebViewController() ..setJavaScriptMode(JavaScriptMode.unrestricted) ..setNavigationDelegate( NavigationDelegate( onPageStarted: (String url) { setState(() { _isLoading = true; _isError = false; }); _getCookies(); // Fetch cookies when a page starts loading }, onPageFinished: (String url) { setState(() { _isLoading = false; }); }, onWebResourceError: (WebResourceError error) { setState(() { _isLoading = false; _isError = true; }); }, ), ); // Load the initial URL here _controller.loadRequest(Uri.parse('https://newtestwebsiteofmine.com/')); } // Method to get cookies using JavaScript void _getCookies() async { await _controller.runJavaScriptReturningResult('document.cookie'); } // Reload page and reset error state void _reloadPage() { _controller.loadRequest(Uri.parse('https://newtestwebsiteofmine.com/')); setState(() { _isError = false; }); } @override Widget build(BuildContext context) { return MaterialApp.router( title: 'My New Site', theme: ThemeData( useMaterial3: true, ), routerConfig: _buildRouter(), ); } // Custom error screen widget Widget _buildErrorScreen() { return Container( color: Colors.white, child: Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ Icon(Icons.error_outline, size: 64, color: Colors.red), SizedBox(height: 16), Text( 'Ooops hata\nOoops error\nOoops Fehler', style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold), ), SizedBox(height: 8), Text( 'İnternetizi kontrol edin\nCheck your internet\nInternet überprüfen', textAlign: TextAlign.center, style: TextStyle(fontSize: 16), ), SizedBox(height: 24), ElevatedButton( onPressed: () { _reloadPage(); // Correctly calling _reloadPage }, child: Text('Yeniden Yükle\nReload Page\nNeu laden'), ), ], ), ), ); } // Use a method to build the router GoRouter _buildRouter() { return GoRouter( initialLocation: '/', routes: [ GoRoute( path: '/', builder: (context, state) => Scaffold( body: Stack( children: [ if (_isError) _buildErrorScreen() else Container( color: Color(0xFF212121), padding: const EdgeInsets.only(top: 52), child: WebViewWidget(controller: _controller), ), if (_isLoading && !_isError) Center( child: SizedBox( width: 64, height: 64, child: CircularProgressIndicator( strokeWidth: 5, valueColor: AlwaysStoppedAnimation(Color(0xFFdf0000)), ), ), ), ], ), ), ), GoRoute( path: '/details', builder: (context, state) => Scaffold( appBar: AppBar(title: Text('Details Screen')), body: Center(child: Text('Details Page')), ), ), ], ); } }
Подробнее здесь: https://stackoverflow.com/questions/791 ... nk-click-f