From d426d4866ad09c788af3f0102af2d8ba701d8846 Mon Sep 17 00:00:00 2001 From: zypherift Date: Thu, 22 Aug 2024 20:57:56 +0200 Subject: [PATCH] fix this --- .../lib/screens/login/kreten_login.dart | 133 +++++++----------- 1 file changed, 53 insertions(+), 80 deletions(-) diff --git a/refilc_mobile_ui/lib/screens/login/kreten_login.dart b/refilc_mobile_ui/lib/screens/login/kreten_login.dart index 0073216..d13b68b 100644 --- a/refilc_mobile_ui/lib/screens/login/kreten_login.dart +++ b/refilc_mobile_ui/lib/screens/login/kreten_login.dart @@ -3,17 +3,17 @@ import 'package:flutter/material.dart'; import 'package:webview_flutter/webview_flutter.dart'; -class KretenLoginScreen extends StatefulWidget { - const KretenLoginScreen({super.key, required this.onLogin}); +class KretenLoginWidget extends StatefulWidget { + const KretenLoginWidget({super.key, required this.onLogin}); // final String selectedSchool; final void Function(String code) onLogin; @override - State createState() => _KretenLoginScreenState(); + State createState() => _KretenLoginWidgetState(); } -class _KretenLoginScreenState extends State { +class _KretenLoginWidgetState extends State { late final WebViewController controller; var loadingPercentage = 0; var currentUrl = ''; @@ -24,71 +24,35 @@ class _KretenLoginScreenState extends State { controller = WebViewController() ..setJavaScriptMode(JavaScriptMode.unrestricted) ..setNavigationDelegate(NavigationDelegate( - onNavigationRequest: (n) async { - if (n.url.startsWith('https://mobil.e-kreta.hu')) { - setState(() { - loadingPercentage = 0; - currentUrl = n.url; - }); - - // final String instituteCode = widget.selectedSchool; - // if (!n.url.startsWith( - // 'https://mobil.e-kreta.hu/ellenorzo-student/prod/oauthredirect?code=')) { - // return; - // } - - List requiredThings = n.url - .replaceAll( - 'https://mobil.e-kreta.hu/ellenorzo-student/prod/oauthredirect?code=', - '') - .replaceAll( - '&scope=openid%20email%20offline_access%20kreta-ellenorzo-webapi.public%20kreta-eugyintezes-webapi.public%20kreta-fileservice-webapi.public%20kreta-mobile-global-webapi.public%20kreta-dkt-webapi.public%20kreta-ier-webapi.public&state=refilc_student_mobile&session_state=', - ':') - .split(':'); - - String code = requiredThings[0]; - // String sessionState = requiredThings[1]; - - widget.onLogin(code); - // Future.delayed(const Duration(milliseconds: 500), () { - // Navigator.of(context).pop(); - // }); - // Navigator.of(context).pop(); - - return NavigationDecision.prevent; - } else { - return NavigationDecision.navigate; - } - }, onPageStarted: (url) async { - // setState(() { - // loadingPercentage = 0; - // currentUrl = url; + setState(() { + loadingPercentage = 0; + currentUrl = url; + }); + + // final String instituteCode = widget.selectedSchool; + if (!url.startsWith( + 'https://mobil.e-kreta.hu/ellenorzo-student/prod/oauthredirect?code=')) { + return; + } + + List requiredThings = url + .replaceAll( + 'https://mobil.e-kreta.hu/ellenorzo-student/prod/oauthredirect?code=', + '') + .replaceAll( + '&scope=openid%20email%20offline_access%20kreta-ellenorzo-webapi.public%20kreta-eugyintezes-webapi.public%20kreta-fileservice-webapi.public%20kreta-mobile-global-webapi.public%20kreta-dkt-webapi.public%20kreta-ier-webapi.public&state=refilc_student_mobile&session_state=', + ':') + .split(':'); + + String code = requiredThings[0]; + // String sessionState = requiredThings[1]; + + widget.onLogin(code); + // Future.delayed(const Duration(milliseconds: 500), () { + // Navigator.of(context).pop(); // }); - - // // final String instituteCode = widget.selectedSchool; - // if (!url.startsWith( - // 'https://mobil.e-kreta.hu/ellenorzo-student/prod/oauthredirect?code=')) { - // return; - // } - - // List requiredThings = url - // .replaceAll( - // 'https://mobil.e-kreta.hu/ellenorzo-student/prod/oauthredirect?code=', - // '') - // .replaceAll( - // '&scope=openid%20email%20offline_access%20kreta-ellenorzo-webapi.public%20kreta-eugyintezes-webapi.public%20kreta-fileservice-webapi.public%20kreta-mobile-global-webapi.public%20kreta-dkt-webapi.public%20kreta-ier-webapi.public&state=refilc_student_mobile&session_state=', - // ':') - // .split(':'); - - // String code = requiredThings[0]; - // // String sessionState = requiredThings[1]; - - // widget.onLogin(code); - // // Future.delayed(const Duration(milliseconds: 500), () { - // // Navigator.of(context).pop(); - // // }); - // // Navigator.of(context).pop(); + // Navigator.of(context).pop(); }, onProgress: (progress) { setState(() { @@ -107,6 +71,7 @@ class _KretenLoginScreenState extends State { ); } + // Future loadLoginUrl() async { // String nonceStr = await Provider.of(context, listen: false) // .getAPI(KretaAPI.nonce, json: false); @@ -115,22 +80,30 @@ class _KretenLoginScreenState extends State { @override Widget build(BuildContext context) { - return Scaffold( - appBar: AppBar( - leading: const BackButton(), - title: const Text('e-KRÉTA Bejelentkezés'), - ), - body: Stack( - children: [ - WebViewWidget( + return Stack( + children: [ + // WebView that will only be visible when the loading is 100% + Visibility( + visible: loadingPercentage == 100, + maintainState: true, // Keep the WebView running in the background + child: WebViewWidget( controller: controller, ), - if (loadingPercentage < 100) - LinearProgressIndicator( - value: loadingPercentage / 100.0, + ), + // Show the CircularProgressIndicator while loading is not 100% + if (loadingPercentage < 100) + Center( + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + CircularProgressIndicator( + value: loadingPercentage / + 100.0, // Shows progress as a percentage + ), + ], ), - ], - ), + ), + ], ); } }