Git Product home page Git Product logo

asset_webview's Introduction

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.

In-App Navigation Links

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.

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

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.

asset_webview's People

Contributors

greensopinion avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

fleoparra njm64

asset_webview's Issues

iOS build is not created

i make build using "flutter build ios --release" and it is show me error

fatal error: module 'asset_webview' not found
@import asset_webview;
~~~~~~~^~~~~~~~~~~~~
1 error generated.
note: Using new build system
note: Planning
note: Build preparation complete
note: Building targets in parallel

Result bundle written to path:
    /var/folders/wk/smm6mfxn6dd6rcv8vjtj49qr0000gn/T/flutter_tools.bL005N/flutter_ios_build_temp_dirAuCAgn/temporary_xcresult_bundle

Parse Issue (Xcode): Module 'asset_webview' not found

Build fails when using android plugin version 8+

When building a project with asset_webview as a subproject the build fails with android gradle plugin version 8 or higher.

This is the error:
Setting the namespace via the package attribute in the source AndroidManifest.xml is no longer supported.

Solution:
Please remove package name from AndroidManifest.xml and add namespace to the build.gradle file.

Flutter 3 support

After upgrading to Flutter 3, I'm seeing the following errors when building for Android:

e: /usr/local/flutter/.pub-cache/git/asset_webview-bf8778433647fd59cd78552e44721f0f06d92091/android/src/main/kotlin/com/greensopinion/flutter/asset_webview/AssetWebview.kt: (23, 7): Redeclaration: AssetWebviewFactory
e: /usr/local/flutter/.pub-cache/git/asset_webview-bf8778433647fd59cd78552e44721f0f06d92091/android/src/main/kotlin/com/greensopinion/flutter/asset_webview/AssetWebview.kt: (33, 15): Redeclaration: AssetWebview
e: /usr/local/flutter/.pub-cache/git/asset_webview-bf8778433647fd59cd78552e44721f0f06d92091/android/src/main/kotlin/com/greensopinion/flutter/asset_webview/AssetWebview.kt: (66, 15): Redeclaration: AssetWebviewClient
e: /usr/local/flutter/.pub-cache/hosted/pub.dartlang.org/asset_webview-0.0.5/android/src/main/kotlin/com/greensopinion/flutter/asset_webview/AssetWebview.kt: (23, 1): Class 'AssetWebviewFactory' is not abstract and does not implement abstract base class member public abstract fun create(p0: Context?, p1: Int, p2: Any?): PlatformView defined in io.flutter.plugin.platform.PlatformViewFactory
e: /usr/local/flutter/.pub-cache/hosted/pub.dartlang.org/asset_webview-0.0.5/android/src/main/kotlin/com/greensopinion/flutter/asset_webview/AssetWebview.kt: (23, 7): Redeclaration: AssetWebviewFactory
e: /usr/local/flutter/.pub-cache/hosted/pub.dartlang.org/asset_webview-0.0.5/android/src/main/kotlin/com/greensopinion/flutter/asset_webview/AssetWebview.kt: (27, 5): 'create' overrides nothing
e: /usr/local/flutter/.pub-cache/hosted/pub.dartlang.org/asset_webview-0.0.5/android/src/main/kotlin/com/greensopinion/flutter/asset_webview/AssetWebview.kt: (28, 16): Cannot access 'AssetWebview': it is private in file
e: /usr/local/flutter/.pub-cache/hosted/pub.dartlang.org/asset_webview-0.0.5/android/src/main/kotlin/com/greensopinion/flutter/asset_webview/AssetWebview.kt: (32, 15): Redeclaration: AssetWebview
e: /usr/local/flutter/.pub-cache/hosted/pub.dartlang.org/asset_webview-0.0.5/android/src/main/kotlin/com/greensopinion/flutter/asset_webview/AssetWebview.kt: (46, 31): Cannot access 'AssetWebviewClient': it is private in file
e: /usr/local/flutter/.pub-cache/hosted/pub.dartlang.org/asset_webview-0.0.5/android/src/main/kotlin/com/greensopinion/flutter/asset_webview/AssetWebview.kt: (65, 15): Redeclaration: AssetWebviewClient
e: /usr/local/flutter/.pub-cache/hosted/pub.dartlang.org/asset_webview-0.0.5/android/src/main/kotlin/com/greensopinion/flutter/asset_webview/AssetWebview.kt: (98, 21): Object is not abstract and does not implement abstract member public abstract fun error(p0: String, p1: String?, p2: Any?): Unit defined in io.flutter.plugin.common.MethodChannel.Result
e: /usr/local/flutter/.pub-cache/hosted/pub.dartlang.org/asset_webview-0.0.5/android/src/main/kotlin/com/greensopinion/flutter/asset_webview/AssetWebview.kt: (106, 25): 'error' overrides nothing

It looks like there have been a couple of interface changes to PlatformViewFactory and MethodChannel.Result. I've got it working locally with the change below, but not sure how you would handle a null context on the PlatformViewFactory create method?

main...njm64:main

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.