0

I get this error: A value of type 'Future<Response>' can't be assigned to a variable of type 'Response'. Try changing the type of the variable, or casting the right-hand type to 'Response'.

    import 'package:flutter/material.dart';
    import 'package:http/http.dart' as http;
    
    class loadding extends StatefulWidget {
      @override
      _loaddingState createState() => _loaddingState();
    }
    
    class _loaddingState extends State<loadding> {
      void gateData() async {
        var url =
            Uri.parse('http://worldtimeapi.org/api/timezone/Africa/Addis_Ababa');

//here is The Error occur at http.get(url), 

        http.Response response = http.get(url);

      }
    
      @override
      Widget build(BuildContext context) {
        return Scaffold();
      }
    }
jamesdlin
  • 81,374
  • 13
  • 159
  • 204
solomon
  • 75
  • 1
  • 7

3 Answers3

0

I solved it by myself. when I add await keyword in front of HTTP.get the error is gone.

like this http.Response response = await http.get(url);

solomon
  • 75
  • 1
  • 7
0

I have edited your code so please you can try as well as this code.

  void gateData() async {
    var url =
        Uri.parse('http://worldtimeapi.org/api/timezone/Africa/Addis_Ababa');
  http.Response response =await http.get(url);

  }

You need to use async and await future type.

Harsh Chovatiya
  • 295
  • 2
  • 6
0

Try This

 void gateData() async {
        var url =
            Uri.parse('http://worldtimeapi.org/api/timezone/Africa/Addis_Ababa');

//here is The Error occur at http.get(url), 

        http.Response response = await http.get(url);

      }

Ottoman Coder
  • 362
  • 3
  • 15