I wrote a flutter project which working fine and I was able to build it properly, but when I added retrofit_generator the build getting failed, If i remove the generator the code runs fine and the build also succeeds. here is the error,
Unsupported operation: Cannot resolve file:///C:/Users/User/AndroidStudioProjects/digigad/lib/resources/network/reposi tory.dart; only "package" and "asset" schemes supported [SEVERE] retrofit_generator:retrofit on lib/ui/login/login_view.dart:
here is my code of login_view.dart
class LoginView extends StatefulWidget {
@override
_LoginViewState createState() => _LoginViewState();
}
class _LoginViewState extends State<LoginView> {
LoginViewModel _loginViewModel;
@override
void initState() {
super.initState();
_loginViewModel = locator<LoginViewModel>();
}
@override
Widget build(BuildContext context) {
return ViewModelBuilder<LoginViewModel>.nonReactive(
builder: (context, model, child) {
return Scaffold(
backgroundColor: Colors.white,
body: SafeArea(
child: Padding(
padding: const EdgeInsets.all(30.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
Container(
child: Center(
child: Container(
child: Image.asset('images/iv_logo.png'),
width: 100,
height: 100,
),
),
),
Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
_socialButton(
image: 'icons/ic_facebook.png',
title: 'Facebook'),
SizedBox(
width: 30,
),
_socialButton(
image: 'icons/ic_google.png', title: 'Google'),
],
),
SizedBox(
height: 30,
),
Text(
'or',
style: TextStyle(
fontSize: 15, color: AppConstants.colorHint),
),
SizedBox(
height: 20,
),
StreamBuilder<String>(
stream: model.phoneStream,
builder: (context, snapshot) {
return Column(
children: <Widget>[
AppFunctions.getTextInputField(
hintText: 'Mobile Number',
maxLength: 10,
inputType: TextInputType.phone,
onChanged: model.onPhoneChanged,
errorText: snapshot.error),
AppFunctions.getStandardDivider(),
AppFunctions.getBigButton(
title: 'Login',
color: snapshot.hasData
? AppConstants.colorPrimary
: AppConstants.colorHint,
onClick: snapshot.hasData
? () => _loginViewModel
.onLoginClicked(snapshot.data)
: () => () {},
)
],
);
}),
],
),
Center(
child: Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text('Made with '),
Icon(
Icons.favorite,
color: Colors.red,
),
Text(' in Flutter'),
],
),
),
],
),
),
),
);
},
viewModelBuilder: () => _loginViewModel);
}
Expanded _socialButton({String image, String title}) {
return Expanded(
child: Container(
height: 40,
child: RaisedButton(
onPressed: () {},
color: Colors.white,
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Image.asset(
image,
width: 16,
height: 16,
),
SizedBox(
width: 10,
),
Text(title)
],
),
),
),
);
}
}
I also faced the same error and got to know that there is some direct import statement in my project file.
that import statement was login_page.dart
import 'file:///D:/Major_Project/connect/lib/api/api.dart';
in this case, the same error was thrown in build Log
so find that statement in the project and change it with the normal import statement
login_page.dart
import 'package:connect/api/api.dart';
So as the first answer points out, this error is because you have an unsupported import somewhere in your code.
import 'file:///D:/Major_Project/connect/lib/api/api.dart';
The easiest solution is to delete that import. A better solution is to add the following line to your analysis_options.yaml page so that every weird import like this get's linted:
analyzer:
errors:
invalid_uri: error
You can read more about this lint here. If you have a giant project or you find yourself constantly refactoring your folder structure, this will save you a ton of time.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With