Instance of list flutter

class Sale { int employeeId; double price; Sale[this.employeeId, this.price]; } class Employee { int id; List sales; Employee [this.id, this.sales]; } void main[] { //Create a list of employees and their respective sales List employees = new List[]; employees.add[new Employee[1, [new Sale[1, 100.50], new Sale[1, 300.25]]]]; employees.add[new Employee[2, [new Sale[2, 300.00], new Sale[2, 50.25], new Sale[2, 150.00]]]]; employees.add[new Employee[3, [new Sale[2, 400.00], new Sale[2, 30.75], new Sale[3, 50.00]]]]; //Sort so that the employee with the most sales is on top and so on... employees.sort[[a, b] => [b.sales.fold[0, [prev, element] => prev + element.price]].compareTo[a.sales.fold[0, [prev, element] => prev + element.price]]]; log[employees]; //prints Employee #2, followed by Employee #3, then ending with Employee #1 } void log[var lst] { lst.forEach[[l] => print["Employee #${l.id} has ${l.sales.length} sales totaling ${l.sales.fold[0, [prev, element] => prev + element.price]} dollars!"]]; }

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]:" //dosya.co/w8rxecrl44rz/Capture.JPG.html //dosya.co/vk6rd85o7zkx/Capture.JPG2.JPG.html

  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 json] => Post[
  21.     userId: json["userId"],
  22.     id: json["id"],
  23.     title: json["title"],
  24.     body: json["body"],
  25.   ];
  26.  
  27.   Map toJson[] => {
  28.     "userId": userId,
  29.     "id": id,
  30.     "title": title,
  31.     "body": body,
  32.   };
  33. }

  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 createState[] => _MyAppState[];
  17. }
  18.  
  19. class _MyAppState extends State {
  20.   Future getData = Future[[] => null];
  21.   var con = Uri.parse["//jsonplaceholder.typicode.com/posts"];
  22.  
  23.   Future fetchPost[] async {
  24.     List result = [];
  25.     final response = await http.get[con];
  26.     if [response.statusCode == 200] {
  27.       List listPost = jsonDecode[response.body];
  28.       for [int i = 0; i Divider[],
  29.                 itemCount: snapshot.data.lenght,
  30.               ];
  31.             }
  32.             //var d =jsonDecode[snapshot.data.body];
  33.             return Container[];
  34.           },
  35.         ],
  36.       ],
  37.     ];
  38.   }
  39. }

Video liên quan

Chủ Đề