1

I have this on my webView...

Widget myPlayer(String url) {
    print('WebView con: $url');
    return new InAppWebView(
      initialUrl: url,
      initialHeaders: {},
      initialOptions: InAppWebViewGroupOptions(
        crossPlatform: InAppWebViewOptions(
          debuggingEnabled: true,
        ),
      ),
      onWebViewCreated: (InAppWebViewController controller) {
          webView = controller;
      },
      onLoadStart: (InAppWebViewController controller, String url) {
        status = false;
      },
      onLoadStop: (InAppWebViewController controller, String url) {
        status = true;
      },
      onWindowFocus: (controller) => {

      },
    );
  }

But when the widget loads, the page that I see is the "previous" one, no the String url...

Also, I can see someting like this on console

W/ContentCatcher(30360): Failed to notify a WebView
W/System  (30360): A resource failed to call release.
D/        (30360): PlayerBase::PlayerBase()
D/        (30360): TrackPlayerBase::TrackPlayerBase()

1 Answer 1

1

You can copy paste run full code below
When InAppWebView load finish. you can directly call webView.loadUrl to change url
code snippet

InAppWebViewController webView;

onWebViewCreated: (InAppWebViewController controller) {
        webView = controller;
      },

webView.loadUrl(url: "https://flutter.dev/");

working demo

enter image description here

full code

import 'package:flutter/material.dart';
import 'package:flutter_inappwebview/flutter_inappwebview.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
        visualDensity: VisualDensity.adaptivePlatformDensity,
      ),
      home: MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);

  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  InAppWebViewController webView;
  bool status;

  _changeUrl() {
    webView.loadUrl(url: "https://flutter.dev/");
  }

  Widget myPlayer(String url) {
    print('WebView con: $url');
    return InAppWebView(
      initialUrl: url,
      initialHeaders: {},
      initialOptions: InAppWebViewGroupOptions(
        crossPlatform: InAppWebViewOptions(
          debuggingEnabled: true,
        ),
      ),
      onWebViewCreated: (InAppWebViewController controller) {
        webView = controller;
      },
      onLoadStart: (InAppWebViewController controller, String url) {
        status = false;
      },
      onLoadStop: (InAppWebViewController controller, String url) {
        status = true;
      },
      onWindowFocus: (controller) => {},
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: myPlayer("https://pub.dev/"),
      floatingActionButton: FloatingActionButton(
        onPressed: _changeUrl,
        tooltip: 'Increment',
        child: Icon(Icons.add),
      ),
    );
  }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.