Syed Mujtaba Ali
Syed Mujtaba Ali

Reputation: 129

Uri Can't be assigned to webUri

import 'package:flutter/material.dart';
//this is the package which allows in app web browser view feature
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
import 'package:loading_animation_widget/loading_animation_widget.dart';
import 'package:project1_test/pages/loginPage.dart';
import 'package:project1_test/theme/Textstyle.dart';
import 'package:project1_test/theme/colors.dart';
class forgotpass extends StatefulWidget {
const forgotpass({super.key});
@override
State<forgotpass> createState() => _forgotpassState();}
class _forgotpassState extends State<forgotpass> {
InAppWebViewController? webViewController;
bool isLoading = true;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
elevation: 0,
backgroundColor: //use any color here,
title: Text( 'Forgot Password',style: Colors.white,),
centerTitle: true,
actions: [
TextButton(child: Text(
          'LOGIN',
          style:Colors.white,
        ),
 onPressed: () {Navigator.push(context,
              MaterialPageRoute(builder: (context) => loginPage()));
        },), ], ),
body: Column( mainAxisAlignment: MainAxisAlignment.center,
    crossAxisAlignment: CrossAxisAlignment.center,
children: [ Expanded( child: Stack(
children: [ InAppWebView(
initialUrlRequest: URLRequest(
//this is where i am getting the error
 url: Uri.parse('Any Url that will open in the inappwbview'),),
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),
)
],
 ))
],
),
);
} }

I'm encountering a type mismatch error in my Flutter app while using the InAppWebView widget. The specific error message is: The argument type 'UriData' can't be assigned to the parameter type 'WebUri?' the same code is working in a different application with a different url but its not working for me this code is suppose to open a in-app browser display the webpage enter image description here

if the error is fixed and once tapped on forgot password button... the app should take me to a password reset web page but in a in app web browser

Upvotes: 3

Views: 3412

Answers (4)

Richa Shah
Richa Shah

Reputation: 954

I faced the same issue. The problem I found is that when using the useShouldOverrideUrlLoading attribute, you need to define the shouldOverrideUrlLoading function.

shouldOverrideUrlLoading: (controller, action) async {
  return NavigationActionPolicy.ALLOW;
},
If you use the useShouldOverrideUrlLoading attribute, you must define this method.

Upvotes: 0

Priyansh jain
Priyansh jain

Reputation: 1422

All the above answers above seems not working for me. Instead, this worked:

WebUri webUrl =   WebUri("your url")

No need to pass any parse or uri function, that doesnt work in new android and flutter versions.

Upvotes: 1

Abd Olabi
Abd Olabi

Reputation: 24

The above solution worked for me, but I encountered the same issue again. White screen appears when I use the link I inserted.

I fixed it by doing the following (thanks to Joe's answer):

  WebUri webUrl =   WebUri.uri(Uri.parse("your url"))

Upvotes: -1

Joe Clarence
Joe Clarence

Reputation: 89

Assuming url is a string variable holding an url string, you can do something like this:

WebUri webUrl = WebUri.uri(UriData.fromString(url).uri);

Let me know if that works for you.

Upvotes: 1

Related Questions