Last updated:
0 purchases
asset webview
asset_webview #
A Flutter plug-in providing a native web view that loads Flutter assets.
Useful for embdding HTML content in your application, for example to display
help content.
Usage #
Usage involves the following steps:
Add HTML assets to your application including CSS and images as needed.
A pubspec.yaml entry might look as follows:
flutter:
assets:
- help/
copied to clipboard
example: example/pubspec.yaml
Add web content to your application assets.
example: example/help
Add the AssetWebview widget to your application.
Create a page as follows:
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Example Usage of asset_webview'),
),
body: SafeArea(
child: Column(children: [
Expanded(
child: AssetWebview(initialUrl: 'asset://local/help/index.html'))
])),
),
);
copied to clipboard
example: example/lib/main.dart
See the sample application for a complete application.
In-App Navigation Links #
To link from web content to a named route in the app, do the following:
Create a function that can provide a BuildContext
BuildContext _currentContext() => _navigatorKey.currentContext!;
final _navigatorKey = GlobalKey<NavigatorState>();
copied to clipboard
Pass a NavigationAssetWebviewController to the AssetWebview
AssetWebview(
initialUrl: 'asset://local/help/index.html',
controller: NavigationAssetWebviewController(_currentContext)
)
copied to clipboard
Provide named routes in the application
MaterialApp(
navigatorKey: _navigatorKey,
...
routes: {"about": (context) => AboutPage()},
);
copied to clipboard
Place navigation links in the html content:
<a href="navigation://about">About</a>
copied to clipboard
See the sample application for a complete application.
Troubleshooting #
My assets aren't showing up (not found)
Check the pubspec.yaml indentation. assets must be indented one level under flutter.
Maintaining #
Editing Android Plugin Files #
Per Flutter docs when opening in IntelliJ
open example/android/build.gradle
Commands #
publishing: flutter pub publish
License #
Copyright 2021 David Green
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
copied to clipboard
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
For personal and professional use. You cannot resell or redistribute these repositories in their original state.
There are no reviews.