473,377 Members | 1,151 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,377 software developers and data experts.

Flutter 'List<Post>' has no instance getter 'lenght'

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



Expand|Select|Wrap|Line Numbers
  1. import 'dart:convert';
  2.  
  3. Post postFromJson(String str) => Post.fromJson(json.decode(str));
  4.  
  5. String postToJson(Post data) => json.encode(data.toJson());
  6.  
  7. class Post {
  8.   Post({
  9.     required this.userId,
  10.     required this.id,
  11.     required this.title,
  12.     required this.body,
  13.   });
  14.  
  15.   int userId;
  16.   int id;
  17.   String title;
  18.   String body;
  19.  
  20.   factory Post.fromJson(Map<String, dynamic> json) => Post(
  21.     userId: json["userId"],
  22.     id: json["id"],
  23.     title: json["title"],
  24.     body: json["body"],
  25.   );
  26.  
  27.   Map<String, dynamic> toJson() => {
  28.     "userId": userId,
  29.     "id": id,
  30.     "title": title,
  31.     "body": body,
  32.   };
  33. }
Expand|Select|Wrap|Line Numbers
  1. import 'dart:convert';
  2.  
  3.  
  4. import 'package:flutter/material.dart';
  5. import 'package:http/http.dart' as http;
  6. import 'package:json_http_place_holder/post.dart';
  7.  
  8. void main() {
  9.   runApp(const MyApp());
  10. }
  11.  
  12. class MyApp extends StatefulWidget {
  13.   const MyApp({Key? key}) : super(key: key);
  14.  
  15.   @override
  16.   State<MyApp> createState() => _MyAppState();
  17. }
  18.  
  19. class _MyAppState extends State<MyApp> {
  20.   Future getData = Future(() => null);
  21.   var con = Uri.parse("https://jsonplaceholder.typicode.com/posts");
  22.  
  23.   Future<List<Post>> fetchPost() async {
  24.     List<Post> result = <Post>[];
  25.     final response = await http.get(con);
  26.     if (response.statusCode == 200) {
  27.       List listPost = jsonDecode(response.body);
  28.       for (int i = 0; i < listPost.length; i++) {
  29.         Post item = Post.fromJson(listPost[i]);
  30.         result.add(item);
  31.       }
  32.     }
  33.     return result;
  34.   }
  35.  
  36.   @override
  37.   void initState() {
  38.     // TODO: implement initState
  39.     super.initState();
  40.     getData = fetchPost();
  41.   }
  42.  
  43.   @override
  44.   Widget build(BuildContext context) {
  45.     return MaterialApp(
  46.       title: 'Flutter HTTP json',
  47.       theme: ThemeData(
  48.         primarySwatch: Colors.blue,
  49.       ),
  50.       home: Scaffold(
  51.         body: FutureBuilder(
  52.           future: getData,
  53.           builder: (BuildContext context,  AsyncSnapshot<dynamic> snapshot) {
  54.             if (snapshot.connectionState == ConnectionState.waiting) {
  55.               return const Center(
  56.                 child: CircularProgressIndicator(),
  57.               );
  58.             } else if (snapshot.connectionState == ConnectionState.none) {
  59.               return const Center(
  60.                 child: Text("Bir hata meydana geldi"),
  61.               );
  62.             } else if (snapshot.connectionState == ConnectionState.done) {
  63.               return ListView.separated(itemBuilder: (context,index){
  64.                 return ListTile(
  65.                   leading: Icon(Icons.local_post_office),
  66.                   title: Text(snapshot.data[index].title),
  67.                   subtitle: Text(snapshot.data[index].body),
  68.                 );
  69.               },separatorBuilder: (context,index)=>Divider(),
  70.                 itemCount: snapshot.data.lenght,
  71.               );
  72.             }
  73.             //var d =jsonDecode(snapshot.data.body);
  74.             return Container();
  75.           },
  76.         ),
  77.       ),
  78.     );
  79.   }
  80. }
Sep 13 '21 #1

✓ answered by dev7060

Flutter 'List<Post>' has no instance getter 'lenght'
Did you try length?‎‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎

1 9198
dev7060
636 Expert 512MB
Flutter 'List<Post>' has no instance getter 'lenght'
Did you try length?‎‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎
Sep 14 '21 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
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...
0
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)...
7
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 -...
4
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...
6
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...
9
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!
3
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_;
5
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();...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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 using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.