-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from dacher996/main
Smaller WebView fixes
- Loading branch information
Showing
4 changed files
with
106 additions
and
53 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
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,51 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:webview_flutter/webview_flutter.dart'; | ||
|
||
/// [TakoPlayWebView] is a webview specifically tailored for the needs of the | ||
/// Tako Play app. Rather than always creating a webview and assigning it same | ||
/// values each time, this widget can be instantiated without going though that | ||
/// hassle. | ||
class TakoPlayWebView extends StatefulWidget { | ||
const TakoPlayWebView({ | ||
required this.initialUrl, | ||
this.onLoadingFinished, | ||
Key? key, | ||
}) : super(key: key); | ||
|
||
/// Initial url of the web view | ||
final String initialUrl; | ||
|
||
/// Callback triggered once the page has finished loading | ||
final Function(WebViewController)? onLoadingFinished; | ||
|
||
@override | ||
State<TakoPlayWebView> createState() => _TakoPlayWebViewState(); | ||
} | ||
|
||
class _TakoPlayWebViewState extends State<TakoPlayWebView> { | ||
WebViewController? _webViewController; | ||
|
||
@override | ||
Widget build(BuildContext context) => WebView( | ||
initialUrl: widget.initialUrl, | ||
javascriptMode: JavascriptMode.unrestricted, | ||
allowsInlineMediaPlayback: true, | ||
backgroundColor: const Color(0x00000000), | ||
onWebViewCreated: (controller) async { | ||
_webViewController = controller; | ||
}, | ||
onPageFinished: (_) async { | ||
if (_webViewController == null) return; | ||
widget.onLoadingFinished?.call(_webViewController!); | ||
}, | ||
navigationDelegate: (NavigationRequest request) { | ||
// If we are navigating to the destination url, allow it. | ||
if (request.url == widget.initialUrl) { | ||
return NavigationDecision.navigate; | ||
} | ||
|
||
// Otherwise, reject any navigation to other web urls | ||
return NavigationDecision.prevent; | ||
}, | ||
); | ||
} |