1

I'm trying to check an url with the http package.

The code looks like this:

  Future<void> checkURl() async{
    final response =
        await http.get(
        Uri.parse('https://someurl.com'));
  }

The http package is imported, but somehow the IDE marks the 'http' invalid. This is the error message:

Error: The getter 'http' isn't defined for the class '_MyHomePageState'.
 - '_MyHomePageState' is from 'package:movies_app/screens/detail_screen.dart' ('lib/screens/detail_screen.dart'). Try correcting the name to the name of an existing getter, or defining a getter or field named 'http'.
    final response = await http.get(Uri.parse('https://someurl'));

How could I solve this?

2 Answers 2

3

As for the use case, you are using as prefix to import http, import like

import 'package:http/http.dart' as http;

To use like await http.get

Sign up to request clarification or add additional context in comments.

Comments

2

no need to do http.get, you can do

 import 'package:http/http.dart';

 Future<void> checkURl() async{
    final response =
        await get(Uri.parse('https://someurl.com'));
  }

if you want to do

await http.get(Uri.parse('https://someurl.com'));

then import the package as

import 'package:http/http.dart' as http;

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.