I'm new to flutter. I am getting an error like this, can you help me?
I've been stuck in http for json for 5 days, the codes in the source don't work. :( L
It says list not entered but when I enter it does not accept it. I don't know on which line the problem is, but I got a warning like. "The following NoSuchMethodError was thrown building FutureBuilder(dirty, state: _FutureBuilderState#447cc):"
https://dosya.co/w8rxecrl44rz/Capture.JPG.html
https://dosya.co/vk6rd85o7zkx/Capture.JPG2.JPG.html - import 'dart:convert';
-
-
Post postFromJson(String str) => Post.fromJson(json.decode(str));
-
-
String postToJson(Post data) => json.encode(data.toJson());
-
-
class Post {
-
Post({
-
required this.userId,
-
required this.id,
-
required this.title,
-
required this.body,
-
});
-
-
int userId;
-
int id;
-
String title;
-
String body;
-
-
factory Post.fromJson(Map<String, dynamic> json) => Post(
-
userId: json["userId"],
-
id: json["id"],
-
title: json["title"],
-
body: json["body"],
-
);
-
-
Map<String, dynamic> toJson() => {
-
"userId": userId,
-
"id": id,
-
"title": title,
-
"body": body,
-
};
-
}
- import 'dart:convert';
-
-
-
import 'package:flutter/material.dart';
-
import 'package:http/http.dart' as http;
-
import 'package:json_http_place_holder/post.dart';
-
-
void main() {
-
runApp(const MyApp());
-
}
-
-
class MyApp extends StatefulWidget {
-
const MyApp({Key? key}) : super(key: key);
-
-
@override
-
State<MyApp> createState() => _MyAppState();
-
}
-
-
class _MyAppState extends State<MyApp> {
-
Future getData = Future(() => null);
-
var con = Uri.parse("https://jsonplaceholder.typicode.com/posts");
-
-
Future<List<Post>> fetchPost() async {
-
List<Post> result = <Post>[];
-
final response = await http.get(con);
-
if (response.statusCode == 200) {
-
List listPost = jsonDecode(response.body);
-
for (int i = 0; i < listPost.length; i++) {
-
Post item = Post.fromJson(listPost[i]);
-
result.add(item);
-
}
-
}
-
return result;
-
}
-
-
@override
-
void initState() {
-
// TODO: implement initState
-
super.initState();
-
getData = fetchPost();
-
}
-
-
@override
-
Widget build(BuildContext context) {
-
return MaterialApp(
-
title: 'Flutter HTTP json',
-
theme: ThemeData(
-
primarySwatch: Colors.blue,
-
),
-
home: Scaffold(
-
body: FutureBuilder(
-
future: getData,
-
builder: (BuildContext context, AsyncSnapshot<dynamic> snapshot) {
-
if (snapshot.connectionState == ConnectionState.waiting) {
-
return const Center(
-
child: CircularProgressIndicator(),
-
);
-
} else if (snapshot.connectionState == ConnectionState.none) {
-
return const Center(
-
child: Text("Bir hata meydana geldi"),
-
);
-
} else if (snapshot.connectionState == ConnectionState.done) {
-
return ListView.separated(itemBuilder: (context,index){
-
return ListTile(
-
leading: Icon(Icons.local_post_office),
-
title: Text(snapshot.data[index].title),
-
subtitle: Text(snapshot.data[index].body),
-
);
-
},separatorBuilder: (context,index)=>Divider(),
-
itemCount: snapshot.data.lenght,
-
);
-
}
-
//var d =jsonDecode(snapshot.data.body);
-
return Container();
-
},
-
),
-
),
-
);
-
}
-
}
Flutter 'List<Post>' has no instance getter 'lenght'
Did you try length?
1 9220
Flutter 'List<Post>' has no instance getter 'lenght'
Did you try length?
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Kiwi |
last post by:
Hello.
I know a getter can return other thing than a field.
I know a setter can do more things than setting a field.
I know there are "setter only" cases and "getter only" cases.
I do use...
|
by: Jean-Michel POURE |
last post by:
Dear friends,
I studying the possibility to port Compiere CRM from Oracle to PostgreSQL. As
Compiere evolves nearly everyday in CVS, I would like to run the Oracle code
without (too much)...
|
by: Tim Marshall |
last post by:
Text boxes that are not grouped with a data control seem to cause my
screen to flutter when the mouse passes over it. Does anyone know why
this might be?
--
Tim -...
|
by: Jimbo |
last post by:
I am sort of new to C#. Currently have a private property called
"_name" in a class. I have written a public getter and setter routine
for it called "Name".
Currently, the getter for the...
|
by: Peter Franks |
last post by:
Is it possible to deserialize a class that has a public property w/ a
setter, but no getter?
I'm not finding anything that would allow this --
Presuming that is is NOT possible, what are the...
|
by: Andrey Koptyaev |
last post by:
What does it mean "fieldRequired.lenght" in php 4.1 ?
I know "fieldRequired->lenght" but don't know "fieldRequired.lenght"
Please help to understand.
Thank you!
|
by: Martin Pöpping |
last post by:
Hello,
I´m coming from the Java World. Here Programmers often use (like in
C++?) getter and setter methods.
F.e.:
class Mirror{
private int width_;
|
by: Andy B |
last post by:
I am trying to figure out how to make an object instance available for all
methods of a class. I tried to do something like this:
public class test {
TheObject Instance = new TheObject();...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |