-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ad8c771
commit 5b7736a
Showing
5 changed files
with
125 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:go_router/go_router.dart'; | ||
import 'package:style/buttons/action_button.dart'; | ||
import 'package:style/extensions/context_extensions.dart'; | ||
import 'package:style/indicators/circular_progress_indicator.dart'; | ||
import 'package:webview_flutter/webview_flutter.dart'; | ||
|
||
import 'app_page.dart'; | ||
|
||
void showWebView(BuildContext context, String url) { | ||
Navigator.of(context, rootNavigator: true).push( | ||
MaterialPageRoute( | ||
fullscreenDialog: true, | ||
builder: (BuildContext context) => WebViewScreen(url: url), | ||
), | ||
); | ||
} | ||
|
||
class WebViewScreen extends StatefulWidget { | ||
final String url; | ||
|
||
const WebViewScreen({super.key, required this.url}); | ||
|
||
@override | ||
State<WebViewScreen> createState() => _WebViewScreenState(); | ||
} | ||
|
||
class _WebViewScreenState extends State<WebViewScreen> { | ||
late WebViewController _controller; | ||
|
||
bool _loading = true; | ||
|
||
@override | ||
void initState() { | ||
_controller = WebViewController() | ||
..setJavaScriptMode(JavaScriptMode.unrestricted) | ||
..setNavigationDelegate( | ||
NavigationDelegate( | ||
onNavigationRequest: (request) { | ||
if(request.url.startsWith("https://canopas.github.io/cloud-gallery/") | ||
&& request.url != "https://canopas.github.io/cloud-gallery/"){ | ||
return NavigationDecision.navigate; | ||
} | ||
return NavigationDecision.prevent; | ||
}, | ||
onPageFinished: (_) => setState(() { | ||
_loading = false; | ||
}), | ||
), | ||
) | ||
..loadRequest(Uri.parse(widget.url)); | ||
|
||
super.initState(); | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return AppPage( | ||
title: '', | ||
automaticallyImplyLeading: false, | ||
leading: ActionButton( | ||
onPressed: () => context.pop(), | ||
icon: Icon( | ||
Icons.close, | ||
color: context.colorScheme.textSecondary, | ||
), | ||
), | ||
body: Builder( | ||
builder: (context) { | ||
return Padding( | ||
padding: context.systemPadding, | ||
child: Stack( | ||
children: [ | ||
WebViewWidget(controller: _controller), | ||
if (_loading) const Center(child: AppCircularProgressIndicator()), | ||
], | ||
), | ||
); | ||
} | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters