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
- 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 json] => Post[
- userId: json["userId"],
- id: json["id"],
- title: json["title"],
- body: json["body"],
- ];
- Map 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 createState[] => _MyAppState[];
- }
- class _MyAppState extends State {
- Future getData = Future[[] => null];
- var con = Uri.parse["//jsonplaceholder.typicode.com/posts"];
- Future fetchPost[] async {
- List result = [];
- final response = await http.get[con];
- if [response.statusCode == 200] {
- List listPost = jsonDecode[response.body];
- for [int i = 0; i Divider[],
- itemCount: snapshot.data.lenght,
- ];
- }
- //var d =jsonDecode[snapshot.data.body];
- return Container[];
- },
- ],
- ],
- ];
- }
- }