Home > Software design >  Hosted Page in Flutter
Hosted Page in Flutter

Time:12-15

I'm working to host the Flutter Web app on GitHub, following below link:

How to Host your Flutter Web app on GitHub Pages

That is working successfully for me. But now need to Hosting Web Page with WebView

such as :

return WebView(
  initialUrl: 'https://my-proj.io/pagename',
),

instead use _loadHtmlFromAssets

CodePudding user response:

If you are looking to load from your assets directory, I'd recommend using the webview_flutter package:

import 'package:webview_flutter/webview_flutter.dart';

class WebViewExample extends StatefulWidget {

  const WebViewExample({
    Key? key,
  }) : super(key: key);

  @override
  State<WebViewExample> createState() => _WebViewExampleState();
}

class _WebViewExampleState extends State<WebViewExample> {
  late WebViewController _controller;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text('Index')),
      body: WebView(
        initialUrl: 'about:blank',
        onWebViewCreated: (WebViewController webViewController) {
          _controller = webViewController;
          _loadHtmlFromAssets();
        },
      ),
    );
  }

  _loadHtmlFromAssets() async => _controller.loadFlutterAsset('assets/data/index.html');
}

CodePudding user response:

You can use webviewx package to render a webview in android|ios|web.

Example:

WebViewX(
initialContent: '<h2> Hello, world! 
</h2>',
initialSourceType: SourceType.HTML,
onWebViewCreated: (controller) => 
webviewController = controller,
...
... other options
);

You can also interact with the controller.

webviewController.loadContent(
'https://flutter.dev',
SourceType.url,
);
webviewController.goBack();

webviewController.goForward();
...
...
  • Related