Skip to content
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

Merged
merged 2 commits into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions app/lib/pages/settings/page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:friend_private/pages/plugins/page.dart';
import 'package:friend_private/pages/settings/calendar.dart';
import 'package:friend_private/pages/settings/developer.dart';
import 'package:friend_private/pages/settings/privacy.dart';
import 'package:friend_private/pages/settings/webview.dart';
import 'package:friend_private/pages/settings/widgets.dart';
import 'package:friend_private/pages/speaker_id/page.dart';
import 'package:friend_private/utils/analytics/mixpanel.dart';
Expand Down Expand Up @@ -168,6 +169,37 @@ class _SettingsPageState extends State<SettingsPage> {
await routeToPage(context, const DeveloperSettingsPage());
setState(() {});
}, icon: Icons.code, visibility: devModeEnabled),
const SizedBox(height: 32.0),
const Align(
alignment: Alignment.centerLeft,
child: Text(
'ABOUT US',
style: TextStyle(
color: Colors.white,
),
textAlign: TextAlign.start,
),
),
getItemAddOn('Privacy Policy', () {
Navigator.of(context).push(
MaterialPageRoute(
builder: (c) => const Webview(
url: 'https://basedhardware.com/pages/privacy',
title: 'Privacy Policy',
),
),
);
}, icon: Icons.privacy_tip_outlined, visibility: true),
getItemAddOn('Our Website', () {
Navigator.of(context).push(
MaterialPageRoute(
builder: (c) => const Webview(
url: 'https://basedhardware.com/',
title: 'Based Hardware',
),
),
);
}, icon: Icons.language_outlined, visibility: true),
Comment on lines +172 to +202
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Image description 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:

- url: 'https://basedhardware.com/pages/privacy',
+ url: Config.PRIVACY_POLICY_URL,

- url: 'https://basedhardware.com/',
+ url: Config.WEBSITE_URL,

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.

const SizedBox(height: 32),
Padding(
padding: const EdgeInsets.all(8),
Expand Down
63 changes: 63 additions & 0 deletions app/lib/pages/settings/webview.dart
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
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Image description Entelligence.AI

There are a few issues here.

First, the initState method should be marked as override because it's overriding the initState method from its superclass.

Second, you're creating a new instance of WebViewController without any parameters, but WebViewController requires at least one parameter which is initialUrl.

Third, you're using setJavaScriptMode, setBackgroundColor, setNavigationDelegate, and loadRequest methods on WebViewController instance, but these methods do not exist in the webview_flutter package. Instead, you should use the WebView widget and set these properties directly.

Fourth, you're not handling errors properly. You've left the onHttpError and onWebResourceError callbacks empty. It's important to handle these errors and provide feedback to the user if something goes wrong.

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
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Image description Entelligence.AI

In your build method, you're using a WebViewWidget which is not defined anywhere in this code. You should use the WebView widget from the webview_flutter package instead. Also, you're passing controller: webviewController to it, but WebView doesn't have a controller property. Instead, you should set the initialUrl, javascriptMode, and navigationDelegate properties directly on the WebView widget.

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 onWebResourceError callback to provide feedback to the user if something goes wrong.

1 change: 1 addition & 0 deletions app/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ dependencies:
docx_template: ^0.4.0
enum_to_string: ^2.0.1
visibility_detector: ^0.4.0+2
webview_flutter: ^4.8.0


dependency_overrides:
Expand Down
Loading