-
Notifications
You must be signed in to change notification settings - Fork 471
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add About Us section in Settings #561
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:webview_flutter/webview_flutter.dart'; | ||
|
||
class Webview extends StatefulWidget { | ||
final String url; | ||
final String title; | ||
const Webview({super.key, required this.url, required this.title}); | ||
|
||
@override | ||
State<Webview> createState() => _WebviewState(); | ||
} | ||
|
||
class _WebviewState extends State<Webview> { | ||
late WebViewController webviewController; | ||
int progress = 0; | ||
|
||
@override | ||
initState() { | ||
webviewController = WebViewController() | ||
..setJavaScriptMode(JavaScriptMode.unrestricted) | ||
..setBackgroundColor(const Color(0x00000000)) | ||
..setNavigationDelegate( | ||
NavigationDelegate( | ||
onProgress: (int p) { | ||
setState(() { | ||
progress = p; | ||
print("Progress: $progress"); | ||
}); | ||
}, | ||
onPageStarted: (String url) {}, | ||
onPageFinished: (String url) {}, | ||
onHttpError: (HttpResponseError error) {}, | ||
onWebResourceError: (WebResourceError error) {}, | ||
onNavigationRequest: (NavigationRequest request) { | ||
if (request.url != widget.url) { | ||
print("Redirecting to ${request.url}"); | ||
return NavigationDecision.prevent; | ||
} | ||
return NavigationDecision.navigate; | ||
}, | ||
), | ||
) | ||
..loadRequest(Uri.parse(widget.url)); | ||
super.initState(); | ||
Comment on lines
+17
to
+44
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are a few issues here. First, the Second, you're creating a new instance of Third, you're using Fourth, you're not handling errors properly. You've left the Here's how you can fix these issues: - initState() {
- webviewController = WebViewController()
- ..setJavaScriptMode(JavaScriptMode.unrestricted)
- ..setBackgroundColor(const Color(0x00000000))
- ..setNavigationDelegate(
- NavigationDelegate(
- onProgress: (int p) {
- setState(() {
- progress = p;
- print("Progress: $progress");
- });
- },
- onPageStarted: (String url) {},
- onPageFinished: (String url) {},
- onHttpError: (HttpResponseError error) {},
- onWebResourceError: (WebResourceError error) {},
- onNavigationRequest: (NavigationRequest request) {
- if (request.url != widget.url) {
- print("Redirecting to ${request.url}");
- return NavigationDecision.prevent;
- }
- return NavigationDecision.navigate;
- },
- ),
- )
- ..loadRequest(Uri.parse(widget.url));
- super.initState();
- }
+ @override
+ void initState() {
+ super.initState();
+ // Initialize the webview controller here if needed.
+ } |
||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Scaffold( | ||
appBar: AppBar( | ||
title: Text(widget.title), | ||
backgroundColor: Theme.of(context).colorScheme.primary, | ||
), | ||
body: progress != 100 | ||
? Center( | ||
child: CircularProgressIndicator( | ||
color: Colors.white, | ||
), | ||
) | ||
: WebViewWidget(controller: webviewController), | ||
); | ||
} | ||
} | ||
Comment on lines
+45
to
+63
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In your Here's how you can fix these issues: - body: progress != 100
- ? Center(
- child: CircularProgressIndicator(
- color: Colors.white,
- ),
- )
- : WebViewWidget(controller: webviewController),
+ body: progress != 100
+ ? Center(
+ child: CircularProgressIndicator(),
+ )
+ : WebView(
+ initialUrl: widget.url,
+ javascriptMode: JavascriptMode.unrestricted,
+ navigationDelegate: (NavigationRequest request) {
+ if (request.url != widget.url) {
+ print("Redirecting to ${request.url}");
+ return NavigationDecision.prevent;
+ }
+ return NavigationDecision.navigate;
+ },
+ onPageStarted: (String url) {},
+ onPageFinished: (String url) {},
+ onWebResourceError: (WebResourceError error) {},
+ ), Please note that you'll need to handle the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Entelligence.AI
The code looks good overall, but there's a potential issue with hardcoding URLs directly into the application. This could lead to problems if the URL changes in the future, as you would need to update and redeploy the app. It would be better to store these URLs in a configuration file or fetch them from a server.
Here's an example of how you might refactor this:
In this case,
Config
is a class that holds your configuration data. You can populate it from a local file, remote server, or environment variables depending on your needs.