Search code examples
flutterdartflutter-dependenciesflutter-animation

WEB URI not opening the weblink in browser


I am trying to use web uri to open an in app brower. The code seems to be working fine but instead of opening the uri the app just shows a white\black screen with code the web link written on it the same is happening for another page aswell the code does not have any syntax errors but still is not working the way it should

class _forgotpassState extends State<forgotpass> {
  WebUri webUrl = WebUri.uri(UriData.fromString(
          'http://live.predictive-lab.com:88/accounts/password/reset/')
      .uri);
  InAppWebViewController? webViewController;
  bool isLoading = true;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        elevation: 0,
        backgroundColor: lightPurple,
        leading: Image.asset('assets/pa_logo_sm.png'),
        title: Text(
          'Forgot Password',
          style: btntxt,
        ),
        centerTitle: true,
        actions: [
          TextButton(
            child: Text(
              'LOGIN',
              style: btntxt,
            ),
            onPressed: () {
              Navigator.push(context,
                  MaterialPageRoute(builder: (context) => loginPage()));
            },
          ),
        ],
      ),
      body: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        crossAxisAlignment: CrossAxisAlignment.center,
        children: [
          // Using Expanded so that the widget covers all the available space!
          Expanded(
              child: Stack(
            //using stack to add place on widget over another
            children: [
              InAppWebView(
                initialUrlRequest: URLRequest(
                  url: webUrl,
                ),
                onWebViewCreated: (controller) {
                  webViewController = controller;
                },
                onLoadStart: (controller, url) {
                  setState(() {
                    isLoading = true;
                  });
                },
                onLoadStop: (controller, url) {
                  setState(() {
                    isLoading = false;
                  });
                },
              ),
              if (isLoading)
                Center(
                  child:
                      LoadingAnimationWidget.beat(color: purpleColor, size: 50),
                )


Solution

  • create your webUrl like this:

    final webUrl = WebUri("http://live.predictive-lab.com:88/accounts/password/reset/")