asset_webview 0.0.5 copy "asset_webview: ^0.0.5" to clipboard
asset_webview: ^0.0.5 copied to clipboard

PlatformAndroidiOS
outdated

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.

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:

  1. Add HTML assets to your application including CSS and images as needed.

    A pubspec.yaml entry might look as follows:

    flutter:
      assets:
        - help/
    

    example: example/pubspec.yaml

  2. Add web content to your application assets.

    example: example/help

  3. 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'))
         ])),
       ),
     );
    

    example: example/lib/main.dart

See the sample application for a complete application.

To link from web content to a named route in the app, do the following:

  1. Create a function that can provide a BuildContext

    BuildContext _currentContext() => _navigatorKey.currentContext!;
    final _navigatorKey = GlobalKey<NavigatorState>();
    
  2. Pass a NavigationAssetWebviewController to the AssetWebview

    AssetWebview(
      initialUrl: 'asset://local/help/index.html',
      controller: NavigationAssetWebviewController(_currentContext)
    )
    
  3. Provide named routes in the application

    MaterialApp(
      navigatorKey: _navigatorKey,
      ...
      routes: {"about": (context) => AboutPage()},
    );
    
  4. Place navigation links in the html content:

    <a href="navigation://about">About</a>
    

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.

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

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.

16
likes
140
pub points
78%
popularity

Publisher

verified publishergreensopinion.com

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.

Repository (GitHub)
View/report issues

Documentation

API reference

License

Apache-2.0 (license)

Dependencies

flutter

More

Packages that depend on asset_webview