0

When I am trying to get data from the internet to use it in my app via the get method provided by the flutter http package it throws this error - The argument type 'String' can't be assigned to the parameter type 'Uri'. This is my code

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



class Loading extends StatefulWidget {
  @override
  _LoadingState createState() => _LoadingState();
}

class _LoadingState extends State<Loading> {
  @override
  void getData() async {
   http.get("https://jsonplaceholder.typicode.com/todos/1")
  }

  void initState() {
    super.initState();
    getData();
  }

  Widget build(BuildContext context) {
    return Scaffold(
      body: Text("some text"),
    );
  }
}
2

1 Answer 1

2

First argument of http package request method is Uri type, So you have to change your code to this:

  void getData() async {
    final requestUrl = Uri.parse("https://jsonplaceholder.typicode.com/todos/1");
    http.get(requestUrl)
  }
Sign up to request clarification or add additional context in comments.

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.