Search code examples
flutterdarthttpflutter-http

Flutter http request issue


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?


Solution

  • 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