error: The argument type 'String' can't be assigned to the parameter type 'Uri'. usingJsonPlaceHolder

Issue

error image
I am trying to run this code but getting errors, can anyone help? I have tried making strings, but still, I get the same error.

error: The argument type ‘String’ can’t be assigned to the parameter type ‘Uri’. (argument_type_not_assignable at [world_time] lib\pages\loading.dart:17)enter image description here

import 'package:flutter/material.dart';
import 'package:http/http.dart';
import 'dart:convert';
import 'dart:core';

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

class _LoadingState extends State<Loading> {


  void getData() async {
    Response response = await get(
        'https://jsonplaceholder.typicode.com/todos/1');
    print(response.body);
  }

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

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Text('loading screen'),
    );
  }?
}

Solution

You can solve the problem by using this:

Uri.parse('https://jsonplaceholder.typicode.com/todos/1')

Answered By – Kanak Joshi

Answer Checked By – Mary Flores (FlutterFixes Volunteer)

Leave a Reply

Your email address will not be published.