-
Notifications
You must be signed in to change notification settings - Fork 131
feat: Add button to open circuit in browser from ProjectDetailsView #343
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
Conversation
WalkthroughThe pull request adds a new method Changes
Possibly related PRs
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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.
Actionable comments posted: 2
🧹 Nitpick comments (2)
lib/ui/views/projects/project_details_view.dart (2)
35-43: Add documentation for the new method.The method lacks documentation explaining its purpose and parameters.
Consider adding documentation:
+ /// Launches the project URL in the device's default browser. + /// + /// [url] The URL to launch, expected to be a valid URL. void _launchProjectURL(String url) async { final uri = Uri.parse(url); if (await canLaunchUrl(uri)) { await launchUrl(uri, mode: LaunchMode.externalApplication); } else { // Optional: Display a snackbar or toast instead print('Could not launch $url'); } }
35-43: Add URL format validation.The method assumes the URL is always valid but doesn't validate the URL format before parsing.
Consider adding URL validation:
void _launchProjectURL(String url) async { + // Basic URL validation + if (url.isEmpty || !url.startsWith('http')) { + SnackBarUtils.showDark('Error', 'Invalid URL format'); + return; + } final uri = Uri.parse(url); if (await canLaunchUrl(uri)) { await launchUrl(uri, mode: LaunchMode.externalApplication); } else { // Optional: Display a snackbar or toast instead print('Could not launch $url'); } }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
lib/ui/views/projects/project_details_view.dart(2 hunks)
🔇 Additional comments (1)
lib/ui/views/projects/project_details_view.dart (1)
1-1: Good choice of package import.The
url_launcherpackage is appropriate for opening URLs in external applications.
| void _launchProjectURL(String url) async { | ||
| final uri = Uri.parse(url); | ||
| if (await canLaunchUrl(uri)) { | ||
| await launchUrl(uri, mode: LaunchMode.externalApplication); | ||
| } else { | ||
| // Optional: Display a snackbar or toast instead | ||
| print('Could not launch $url'); | ||
| } | ||
| } |
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.
🛠️ Refactor suggestion
Implementation complete but missing error handling UI.
The _launchProjectURL method is correctly implemented with proper URL validation using canLaunchUrl. However, the error case only logs to console instead of providing user feedback.
Consider replacing the print statement with a SnackBar notification:
void _launchProjectURL(String url) async {
final uri = Uri.parse(url);
if (await canLaunchUrl(uri)) {
await launchUrl(uri, mode: LaunchMode.externalApplication);
} else {
// Optional: Display a snackbar or toast instead
- print('Could not launch $url');
+ SnackBarUtils.showDark('Error', 'Could not open the project in browser');
}
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| void _launchProjectURL(String url) async { | |
| final uri = Uri.parse(url); | |
| if (await canLaunchUrl(uri)) { | |
| await launchUrl(uri, mode: LaunchMode.externalApplication); | |
| } else { | |
| // Optional: Display a snackbar or toast instead | |
| print('Could not launch $url'); | |
| } | |
| } | |
| void _launchProjectURL(String url) async { | |
| final uri = Uri.parse(url); | |
| if (await canLaunchUrl(uri)) { | |
| await launchUrl(uri, mode: LaunchMode.externalApplication); | |
| } else { | |
| // Optional: Display a snackbar or toast instead | |
| SnackBarUtils.showDark('Error', 'Could not open the project in browser'); | |
| } | |
| } |
Missing button UI implementation.
The PR objective is to add an "Open in Browser" button to the ProjectDetailsView, but while the URL launching functionality is implemented, there's no button added to the UI that calls this method.
Add a button implementation and integrate it within the UI, possibly in the action buttons section. Based on the project structure, you could add:
// Add this method to the class
Widget _buildOpenInBrowserButton() {
return InkWell(
onTap: () => _launchProjectURL('https://circuitverse.org/simulator/edit/${_recievedProject.id}'),
child: Container(
padding: const EdgeInsets.symmetric(vertical: 4, horizontal: 12),
decoration: BoxDecoration(
border: Border.all(color: CVTheme.primaryColorDark),
borderRadius: BorderRadius.circular(4),
),
child: Row(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
const Icon(Icons.open_in_browser, size: 16),
const SizedBox(width: 4),
Text('Open in Browser', style: Theme.of(context).textTheme.titleMedium),
],
),
),
);
}
// Then in the Wrap widget around line 654-661, add:
Wrap(
spacing: 8,
children: <Widget>[
_buildEditButton(),
_buildDeleteButton(),
+ _buildOpenInBrowserButton(),
],
),📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| void _launchProjectURL(String url) async { | |
| final uri = Uri.parse(url); | |
| if (await canLaunchUrl(uri)) { | |
| await launchUrl(uri, mode: LaunchMode.externalApplication); | |
| } else { | |
| // Optional: Display a snackbar or toast instead | |
| print('Could not launch $url'); | |
| } | |
| } | |
| void _launchProjectURL(String url) async { | |
| final uri = Uri.parse(url); | |
| if (await canLaunchUrl(uri)) { | |
| await launchUrl(uri, mode: LaunchMode.externalApplication); | |
| } else { | |
| // Optional: Display a snackbar or toast instead | |
| print('Could not launch $url'); | |
| } | |
| } | |
| // Added method to build the "Open in Browser" button as per the review comment. | |
| Widget _buildOpenInBrowserButton() { | |
| return InkWell( | |
| onTap: () => _launchProjectURL('https://circuitverse.org/simulator/edit/${_recievedProject.id}'), | |
| child: Container( | |
| padding: const EdgeInsets.symmetric(vertical: 4, horizontal: 12), | |
| decoration: BoxDecoration( | |
| border: Border.all(color: CVTheme.primaryColorDark), | |
| borderRadius: BorderRadius.circular(4), | |
| ), | |
| child: Row( | |
| mainAxisSize: MainAxisSize.min, | |
| children: <Widget>[ | |
| const Icon(Icons.open_in_browser, size: 16), | |
| const SizedBox(width: 4), | |
| Text('Open in Browser', style: Theme.of(context).textTheme.titleMedium), | |
| ], | |
| ), | |
| ), | |
| ); | |
| } | |
| // Example integration snippet: inserting the new button into the Wrap widget | |
| Wrap( | |
| spacing: 8, | |
| children: <Widget>[ | |
| _buildEditButton(), | |
| _buildDeleteButton(), | |
| _buildOpenInBrowserButton(), // Added new button for launching URL in browser | |
| ], | |
| ), |
Fixes #
Describe the changes you have made in this PR -Added a new "Open in Browser" button to the ProjectDetailsView screen in the CircuitVerse mobile app.
This button uses the url_launcher package to open the corresponding circuit in the default browser with the URL:
https://circuitverse.org/simulator/edit/{project.id}
Screenshots of the changes (If any) -
Not available as Flutter environment is not set up locally.
Note: Please check Allow edits from maintainers. if you would like us to assist in the PR.
Summary by CodeRabbit