Flutter: Populate listview with headers and items from complex list - flutter

I have following List:
[
{
"ID": "1",
"ParentID": "0",
"CategoryName": "FourWheeler",
"Children": [
{
"ID": "9",
"ParentID": "1",
"CategoryName": "Jeep",
"ParentCategoryName": "FourWheeler"
},
{
"ID": "10",
"ParentID": "1",
"CategoryName": "Taxi",
"ParentCategoryName": "FourWheeler"
},
{
"ID": "11",
"ParentID": "1",
"CategoryName": "Car",
"ParentCategoryName": "FourWheeler"
},
{
"ID": "12",
"ParentID": "1",
"CategoryName": "Van",
"ParentCategoryName": "FourWheeler"
},
{
"ID": "13",
"ParentID": "1",
"CategoryName": "Other",
"ParentCategoryName": "FourWheeler"
}]
},
{
"ID": "2",
"ParentID": "0",
"CategoryName": "Boat",
"Children": [
{
"ID": "14",
"ParentID": "2",
"CategoryName": "Motorboat",
"ParentCategoryName": "Boat"
},
{
"ID": "15",
"ParentID": "2",
"CategoryName": "Sailingboat",
"ParentCategoryName": "Boat"
},
{
"ID": "16",
"ParentID": "2",
"CategoryName": "SteamBoat",
"ParentCategoryName": "Boat"
},
{
"ID": "17",
"ParentID": "2",
"CategoryName": "Other",
"ParentCategoryName": "Boat"
}]
}
]
I need to populate ListView on the basis of this list. We should have listview populated such a way that there are headers and each headers will have their respective items.
For Example, ListView should look something like,
**FourWheeler**
Jeep
Taxi
Car
Van
Other
**Boat**
Motorboat
Sailingboat
Steamboat
Other
For simple list like this:
List Fruits = ['Apple','Orange','Kiwi','Avocado'];
I would have done like this
Fruits.map<Widget>((fruit)=>Container(child: Text(fruit))).toList();
But I don't know how to deal with the scenario I have. Any help will be appreciated. Thanks

This is one way you can populate a ListView as you have described:
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: ListView(
children: [
for (final header in data) ...[
ListTile(title: Text('**${header['CategoryName']}**')),
for (final item in header['Children'] ?? [])
ListTile(title: Text(' ${item['CategoryName']}')),
],
],
),
),
);
}
}
const List<Map<String, dynamic>> data = [
{
"ID": "1",
"ParentID": "0",
"CategoryName": "FourWheeler",
"Children": [
{
"ID": "9",
"ParentID": "1",
"CategoryName": "Jeep",
"ParentCategoryName": "FourWheeler"
},
{
"ID": "10",
"ParentID": "1",
"CategoryName": "Taxi",
"ParentCategoryName": "FourWheeler"
},
{
"ID": "11",
"ParentID": "1",
"CategoryName": "Car",
"ParentCategoryName": "FourWheeler"
},
{
"ID": "12",
"ParentID": "1",
"CategoryName": "Van",
"ParentCategoryName": "FourWheeler"
},
{
"ID": "13",
"ParentID": "1",
"CategoryName": "Other",
"ParentCategoryName": "FourWheeler"
}
]
},
{
"ID": "2",
"ParentID": "0",
"CategoryName": "Boat",
"Children": [
{
"ID": "14",
"ParentID": "2",
"CategoryName": "Motorboat",
"ParentCategoryName": "Boat"
},
{
"ID": "15",
"ParentID": "2",
"CategoryName": "Sailingboat",
"ParentCategoryName": "Boat"
},
{
"ID": "16",
"ParentID": "2",
"CategoryName": "SteamBoat",
"ParentCategoryName": "Boat"
},
{
"ID": "17",
"ParentID": "2",
"CategoryName": "Other",
"ParentCategoryName": "Boat"
}
]
}
];
You could also group each header with something like an ExpansionTile:
ListView(
children: [
for (final header in data)
ExpansionTile(
title: Text('**${header['CategoryName']}**'),
children: [
for (final item in header['Children'] ?? [])
ListTile(title: Text(' ${item['CategoryName']}')),
],
),
],
),

Related

MongoDB aggregation re-group deep nested array of objects

Good day all,
I need some help figuring out this aggregation issue. I have a document with nested arrays where I want to perform lookups on the nested array's values after which I want to restore the document to its original structure. see below:
[
{
"_id": "63c7fec2fe9afea23afdbcef",
"primary_language": "en",
"image_link": "avatar_image_linl",
"description": ["Some description text here"],
"source": "community",
"standard": "imperial",
"gender": "male",
"base_a": 47,
"base_w": 220,
"base_h": 71.65,
"status": "draft",
"date_created": "2023-01-18T14:14:26.201Z",
"product_plan": {
"p_len": 4,
"p_fre": 1,
"p_qua": 4,
"avg_len": 3583,
"total_wor": 16,
"total_exe": 128,
"plan": {
"field_we": 1,
"field_da": 1,
"field_ti": 1,
"field_rest_we": false,
"field_rest_da": false,
"product": {
"name": "W111",
"comment": {
"en": ""
},
"pro_diff": [
{
"itemID": 2,
"description": "Intermediate"
}
],
"pro_int": [
{
"itemID": 2,
"description": "Moderate"
}
],
"pro_dur": 3736,
"nbr_exe": 8,
"target_mus": [
{
"itemID": 1,
"description": "Adominorus"
},
{
"itemID": 16,
"description": "Tricerus"
},
{
"itemID": 5,
"description": "Chiwawak"
}
],
"target_are": [
{
"itemID": 1,
"description": "Adominorus"
},
{
"itemID": 4,
"description": "Chiwawak"
},
{
"itemID": 2,
"description": "Amanus"
}
],
"items": {
"itemid": 44,
"target_are": [
{
"itemID": 4,
"description": "Chiwawak"
}
],
"target_mus": [
{
"itemID": 5,
"description": "Chiwawak"
}
],
"nbr_ref": 4,
"int_rec": "06~10",
"type_rec": [
{
"itemID": 14,
"description": "Straight Set"
}
],
"tempo": "1-1-1-1",
"rest_time": 90,
"note": "",
"order": null,
"pro_dur": 520,
"_id": "63ca9b798d47745ae5589906",
"status": 0,
"pct_complete": 0,
"set": []
},
"isCustomName": false,
"status": 0,
"pct_complete": 0
},
"_id": "63ca95368d47745ae558985e"
},
"_id": "63c7fec2fe9afea23afdbcf0"
},
"title": "Short Title text here",
"itemID": "bodyfyme882212-1674051266.214",
"__v": 32
},
{
"_id": "63c7fec2fe9afea23afdbcef",
"primary_language": "en",
"image_link": "avatar_image_linl",
"description": ["Some description text here"],
"source": "community",
"standard": "imperial",
"gender": "male",
"base_a": 47,
"base_w": 220,
"base_h": 71.65,
"status": "draft",
"date_created": "2023-01-18T14:14:26.201Z",
"product_plan": {
"p_len": 4,
"p_fre": 1,
"p_qua": 4,
"avg_len": 3583,
"total_wor": 16,
"total_exe": 128,
"plan": {
"field_we": 1,
"field_da": 1,
"field_ti": 1,
"field_rest_we": false,
"field_rest_da": false,
"product": {
"name": "W111",
"comment": {
"en": ""
},
"pro_diff": [
{
"itemID": 2,
"description": "Intermediate"
}
],
"pro_int": [
{
"itemID": 2,
"description": "Moderate"
}
],
"pro_dur": 3736,
"nbr_exe": 8,
"target_mus": [
{
"itemID": 1,
"description": "Adominorus"
},
{
"itemID": 16,
"description": "Tricerus"
},
{
"itemID": 5,
"description": "Chiwawak"
}
],
"target_are": [
{
"itemID": 1,
"description": "Adominorus"
},
{
"itemID": 4,
"description": "Chiwawak"
},
{
"itemID": 2,
"description": "Amanus"
}
],
"items": {
"itemid": 339,
"target_are": [
{
"itemID": 4,
"description": "Chiwawak"
}
],
"target_mus": [
{
"itemID": 5,
"description": "Chiwawak"
}
],
"nbr_ref": 3,
"int_rec": "06~10",
"type_rec": [
{
"itemID": 14,
"description": "Straight Set"
}
],
"tempo": "1-1-1-1",
"rest_time": 90,
"note": "",
"order": null,
"pro_dur": 390,
"_id": "63ca9b798d47745ae5589907",
"status": 0,
"pct_complete": 0,
"set": []
},
"isCustomName": false,
"status": 0,
"pct_complete": 0
},
"_id": "63ca95368d47745ae558985e"
},
"_id": "63c7fec2fe9afea23afdbcf0"
},
"title": "Short Title text here",
"itemID": "bodyfyme882212-1674051266.214",
"__v": 32
},
{
"_id": "63c7fec2fe9afea23afdbcef",
"primary_language": "en",
"image_link": "avatar_image_linl",
"description": ["Some description text here"],
"source": "community",
"standard": "imperial",
"gender": "male",
"base_a": 47,
"base_w": 220,
"base_h": 71.65,
"status": "draft",
"date_created": "2023-01-18T14:14:26.201Z",
"product_plan": {
"p_len": 4,
"p_fre": 1,
"p_qua": 4,
"avg_len": 3583,
"total_wor": 16,
"total_exe": 128,
"plan": {
"field_we": 1,
"field_da": 2,
"field_ti": 1,
"field_rest_we": false,
"field_rest_da": false,
"product": {
"name": "W121",
"comment": {
"en": ""
},
"pro_diff": [
{
"itemID": 2,
"description": "Intermediate"
}
],
"pro_int": [
{
"itemID": 2,
"description": "Moderate"
}
],
"pro_dur": 2674,
"nbr_exe": 6,
"target_mus": [
{
"itemID": 9,
"description": "Lats"
},
{
"itemID": 10,
"description": "Lower Back"
},
{
"itemID": 11,
"description": "Middle Back"
}
],
"target_are": [
{
"itemID": 3,
"description": "Back"
}
],
"items": {
"itemid": 47,
"target_are": [
{
"itemID": 3,
"description": "Back"
}
],
"target_mus": [
{
"itemID": 10,
"description": "Lower Back"
}
],
"nbr_ref": 4,
"int_rec": "06~10",
"type_rec": [
{
"itemID": 14,
"description": "Straight Set"
}
],
"tempo": "1-1-1-1",
"rest_time": 90,
"note": "",
"order": null,
"pro_dur": 520,
"_id": "63caa1568d47745ae5589b25",
"status": 0,
"pct_complete": 0,
"set": []
},
"isCustomName": false,
"status": 0,
"pct_complete": 0
},
"_id": "63ca9b8e8d47745ae558994b"
},
"_id": "63c7fec2fe9afea23afdbcf0"
},
"title": "Short Title text here",
"itemID": "bodyfyme882212-1674051266.214",
"__v": 32
},
{
"_id": "63c7fec2fe9afea23afdbcef",
"primary_language": "en",
"image_link": "avatar_image_linl",
"description": ["Some description text here"],
"source": "community",
"standard": "imperial",
"gender": "male",
"base_a": 47,
"base_w": 220,
"base_h": 71.65,
"status": "draft",
"date_created": "2023-01-18T14:14:26.201Z",
"product_plan": {
"p_len": 4,
"p_fre": 1,
"p_qua": 4,
"avg_len": 3583,
"total_wor": 16,
"total_exe": 128,
"plan": {
"field_we": 1,
"field_da": 2,
"field_ti": 1,
"field_rest_we": false,
"field_rest_da": false,
"product": {
"name": "W121",
"comment": {
"en": ""
},
"pro_diff": [
{
"itemID": 2,
"description": "Intermediate"
}
],
"pro_int": [
{
"itemID": 2,
"description": "Moderate"
}
],
"pro_dur": 2674,
"nbr_exe": 6,
"target_mus": [
{
"itemID": 9,
"description": "Lats"
},
{
"itemID": 10,
"description": "Lower Back"
},
{
"itemID": 11,
"description": "Middle Back"
}
],
"target_are": [
{
"itemID": 3,
"description": "Back"
}
],
"items": {
"itemid": 495,
"target_are": [
{
"itemID": 3,
"description": "Back"
}
],
"target_mus": [
{
"itemID": 11,
"description": "Middle Back"
}
],
"nbr_ref": 3,
"int_rec": "10~12",
"type_rec": [
{
"itemID": 14,
"description": "Straight Set"
}
],
"tempo": "1-1-1-1",
"rest_time": 90,
"note": "",
"order": null,
"pro_dur": 414,
"_id": "63caa1568d47745ae5589b26",
"status": 0,
"pct_complete": 0,
"set": []
},
"isCustomName": false,
"status": 0,
"pct_complete": 0
},
"_id": "63ca9b8e8d47745ae558994b"
},
"_id": "63c7fec2fe9afea23afdbcf0"
},
"title": "Short Title text here",
"itemID": "bodyfyme882212-1674051266.214",
"__v": 32
},
{
......
}
]
Now i want to get the document back to this structure using aggregation.
{
"_id": "63c7fec2fe9afea23afdbcef",
"primary_language": "en",
"image_link": "avatar_image_linl",
"description": ["Some description text here"],
"source": "community",
"standard": "imperial",
"gender": "male",
"base_a": 47,
"base_w": 220,
"base_h": 71.65,
"status": "draft",
"date_created": "2023-01-18T14:14:26.201Z",
"product_plan": {
"p_len": 4,
"p_fre": 1,
"p_qua": 4,
"avg_len": 3583,
"total_wor": 16,
"total_exe": 128,
// Group plan here by product_plan._id
"plan": [
{
"field_we": 1,
"field_da": 1,
"field_ti": 1,
"field_rest_we": false,
"field_rest_da": false,
"product": {
"name": "W111",
"comment": {
"en": ""
},
"pro_diff": [
{
"itemID": 2,
"description": "Intermediate"
}
],
"pro_int": [
{
"itemID": 2,
"description": "Moderate"
}
],
"pro_dur": 3736,
"nbr_exe": 8,
"target_mus": [
{
"itemID": 1,
"description": "Adominorus"
},
{
"itemID": 16,
"description": "Tricerus"
},
{
"itemID": 5,
"description": "Chiwawak"
}
],
"target_are": [
{
"itemID": 1,
"description": "Adominorus"
},
{
"itemID": 4,
"description": "Chiwawak"
},
{
"itemID": 2,
"description": "Amanus"
}
],
// group items by plan._id
"items": [
{
"itemid": 44,
"target_are": [
{
"itemID": 4,
"description": "Chiwawak"
}
],
"target_mus": [
{
"itemID": 5,
"description": "Chiwawak"
}
],
"nbr_ref": 4,
"int_rec": "06~10",
"type_rec": [
{
"itemID": 14,
"description": "Straight Set"
}
],
"tempo": "1-1-1-1",
"rest_time": 90,
"note": "",
"order": null,
"pro_dur": 520,
"_id": "63ca9b798d47745ae5589906",
"status": 0,
"pct_complete": 0,
"set": []
},
{
"itemid": 339,
"target_are": [
{
"itemID": 4,
"description": "Chiwawak"
}
],
"target_mus": [
{
"itemID": 5,
"description": "Chiwawak"
}
],
"nbr_ref": 3,
"int_rec": "06~10",
"type_rec": [
{
"itemID": 14,
"description": "Straight Set"
}
],
"tempo": "1-1-1-1",
"rest_time": 90,
"note": "",
"order": null,
"pro_dur": 390,
"_id": "63ca9b798d47745ae5589907",
"status": 0,
"pct_complete": 0,
"set": []
},
],
"isCustomName": false,
"status": 0,
"pct_complete": 0
},
"_id": "63ca95368d47745ae558985e"
},
{
"field_we": 1,
"field_da": 2,
"field_ti": 1,
"field_rest_we": false,
"field_rest_da": false,
"product": {
"name": "W121",
"comment": {
"en": ""
},
"pro_diff": [
{
"itemID": 2,
"description": "Intermediate"
}
],
"pro_int": [
{
"itemID": 2,
"description": "Moderate"
}
],
"pro_dur": 2674,
"nbr_exe": 6,
"target_mus": [
{
"itemID": 9,
"description": "Lats"
},
{
"itemID": 10,
"description": "Lower Back"
},
{
"itemID": 11,
"description": "Middle Back"
}
],
"target_are": [
{
"itemID": 3,
"description": "Back"
}
],
// group items by plan._id
"items": [
{
"itemid": 47,
"target_are": [
{
"itemID": 3,
"description": "Back"
}
],
"target_mus": [
{
"itemID": 10,
"description": "Lower Back"
}
],
"nbr_ref": 4,
"int_rec": "06~10",
"type_rec": [
{
"itemID": 14,
"description": "Straight Set"
}
],
"tempo": "1-1-1-1",
"rest_time": 90,
"note": "",
"order": null,
"pro_dur": 520,
"_id": "63caa1568d47745ae5589b25",
"status": 0,
"pct_complete": 0,
"set": []
},
{
"itemid": 495,
"target_are": [
{
"itemID": 3,
"description": "Back"
}
],
"target_mus": [
{
"itemID": 11,
"description": "Middle Back"
}
],
"nbr_ref": 3,
"int_rec": "10~12",
"type_rec": [
{
"itemID": 14,
"description": "Straight Set"
}
],
"tempo": "1-1-1-1",
"rest_time": 90,
"note": "",
"order": null,
"pro_dur": 414,
"_id": "63caa1568d47745ae5589b26",
"status": 0,
"pct_complete": 0,
"set": []
}
],
"isCustomName": false,
"status": 0,
"pct_complete": 0
},
"_id": "63ca9b8e8d47745ae558994b"
}
],
"_id": "63c7fec2fe9afea23afdbcf0"
},
"title": "Short Title text here",
"itemID": "bodyfyme882212-1674051266.214",
"__v": 32
}
Any help would be greatly appreciated

access array of object data in flutter

I am getting an array of object from my rest API and try to access in flutter but I can not access.I want to access posts,comments,like and status.
The error code is The getter 'data' isn't defined for the type 'List'.
Try importing the library that defines 'data', correcting the name to the name of an existing getter, or defining a getter or field named 'data
and error is given by line snapshot.data!.data[index].posts[postPosition].url and snapshot.data!.data[index].status
The data from API:
[
{
"_id": "6304e73ecdc5d350cc33e902",
"userId": "6304e42231ef2e7a4dec924d",
"posts": [
{
"postType": "image",
"post": "https://www.theskinnybeep.com/wp-content/uploads/2019/01/Versace-Man-2019.jpg",
"_id": "6304e73ecdc5d350cc33e903"
},
{
"postType": "image",
"post": "https://www.theskinnybeep.com/wp-content/uploads/2019/01/Versace-Man-2019.jpg",
"_id": "6304e73ecdc5d350cc33e904"
}
],
"status": "testing status",
"comments": [
{
"commentText": "Testing comment",
"commentAt": "2022-08-23T14:41:55.646Z",
"commentReplys": [
{
"userId": "6304e02d481e08d44e618d41",
"replyText": "Testing comment",
"replyAt": "2022-08-23T14:41:55.646Z",
"replyLikes": [
{
"userId": "6304e02d481e08d44e618d41",
"_id": "6304e73ecdc5d350cc33e907",
"isNotified": true
},
{
"userId": "6304e42231ef2e7a4dec924d",
"isNotified": true,
"_id": "6305f8d07d513ce62b9c099f"
}
],
"_id": "6304e73ecdc5d350cc33e906"
},
{
"userId": "6304e02d481e08d44e618d41",
"replyText": "reply text testing",
"replyAt": "2022-08-23T15:57:51.259Z",
"_id": "6304f90191c32e0deac663b8",
"replyLikes": [
{
"userId": "6304e42231ef2e7a4dec924d",
"isNotified": true,
"_id": "6305f8d07d513ce62b9c099f"
}
]
}
],
"commentLikes": [
{
"userId": "6304e42231ef2e7a4dec924d",
"isNotified": true,
"_id": "6305f8f67d513ce62b9c09a2"
}
],
"commentId": "bc174de0-22f1-11ed-9c5d-23d89a83ff32",
"_id": "6304e73ecdc5d350cc33e905"
},
{
"commentText": "Testing comment",
"commentAt": "2022-08-23T15:02:11.123Z",
"commentId": "90928740-22f4-11ed-b912-e99836187b6d",
"_id": "6304ec67825b5926f0f074cf",
"commentReplys": [
{
"userId": "6304e02d481e08d44e618d41",
"replyText": "reply text testing",
"replyAt": "2022-08-23T15:57:51.259Z",
"_id": "6304f90191c32e0deac663b8",
"replyLikes": [
{
"userId": "6304e42231ef2e7a4dec924d",
"isNotified": true,
"_id": "6305f8d07d513ce62b9c099f"
}
]
}
],
"commentLikes": [
{
"userId": "6304e42231ef2e7a4dec924d",
"isNotified": true,
"_id": "6305f8f67d513ce62b9c09a2"
}
]
},
{
"commentText": "Testing comment",
"commentAt": "2022-08-23T15:02:11.123Z",
"commentId": "90928740-22f4-11ed-b912-e99836187b6d",
"_id": "6304ec81825b5926f0f074d1",
"commentReplys": [
{
"userId": "6304e02d481e08d44e618d41",
"replyText": "reply text testing",
"replyAt": "2022-08-23T15:57:51.259Z",
"_id": "6304f90191c32e0deac663b8",
"replyLikes": [
{
"userId": "6304e42231ef2e7a4dec924d",
"isNotified": true,
"_id": "6305f8d07d513ce62b9c099f"
}
]
}
],
"commentLikes": [
{
"userId": "6304e42231ef2e7a4dec924d",
"isNotified": true,
"_id": "6305f8f67d513ce62b9c09a2"
}
]
}
],
"likes": [
{
"userId": "6304e42231ef2e7a4dec924d",
"_id": "63052dc7a1728d463769681b"
}
],
"__v": 0
},
{
"_id": "63070a03584ed0febe5b5a5f",
"status": "testing",
"posts": [],
"comments": [],
"likes": []
}
]
Flutter code:
Widget build(BuildContext context) {
return SizedBox(
height: 600,
child: FutureBuilder<List<Posts>>(
future: fetchPost(),
builder: ((context, snapshot) {
if (snapshot.hasData) {
return ListView.builder(
scrollDirection: Axis.vertical,
shrinkWrap: true,
itemCount: snapshot.data!.length,
itemBuilder: (context, index) {
return ListView.builder(
scrollDirection: Axis.vertical,
shrinkWrap: true,
itemCount: snapshot.data!.data[index].posts!.length,
itemBuilder: (context, postPosition) {
return Column(
children: [
Text(snapshot.data!.data[index].status),
ListView.builder(itemCount:snapshot.data!.data[index].posts.length,itemBuilder: (context, postPosition) {
return Column(children: [
Image.network(snapshot.data!.data[index].posts[postPosition].url)
],);
})
],
);
}
}
);
} else
return CircularProgressIndicator();
}),
),
);
}
The Posts class:
List<Posts> postsFromJson(String str) => List<Posts>.from(json.decode(str).map((x) => Posts.fromJson(x)));
String postsToJson(List<Posts> data) => json.encode(List<dynamic>.from(data.map((x) => x.toJson())));
class Posts {
Posts({
this.id,
this.userId,
required this.posts,
this.status,
this.comments,
this.likes,
});
String? id;
String? userId;
List<Post> posts;
String? status;
List<Comment>? comments;
List<Like>? likes;
factory Posts.fromJson(Map<String, dynamic> json) => Posts(
id: json["_id"],
userId: json["userId"],
posts: List<Post>.from(json["posts"].map((x) => Post.fromJson(x))),
status: json["status"],
comments: List<Comment>.from(json["comments"].map((x) => Comment.fromJson(x))),
likes: List<Like>.from(json["likes"].map((x) => Like.fromJson(x))),
);
get length => null;
get data => null;
Map<String, dynamic> toJson() => {
"_id": id,
"userId": userId,
"posts": List<dynamic>.from(posts.map((x) => x.toJson())),
"status": status,
"comments": List<dynamic>.from(comments!.map((x) => x.toJson())),
"likes": List<dynamic>.from(likes!.map((x) => x.toJson())),
};
}
I am not sure how your IDE lets you compile the code while you added type in FutureBuilder.
The problem seems here. After snapshot.data you should not add another data variable. snapshot.data!.data should not be added.
itemCount: snapshot.data![index].posts!.length,
itemBuilder: (context, postPosition) {
return Column(
children: [
Text(snapshot.data![index].status),
ListView.builder(itemCount:snapshot.data![index].posts.length,itemBuilder: (context, postPosition) {
return Column(children: [
Image.network(snapshot.data![index].posts[postPosition].url)
],);
from your api response and you named it as "class:Post" it not a list. but Post.post is a list. Try to delete the list just like this, and print the result. you may have other error when casting it to your widget because the code will be a bit different. you can ask more if you face other difficulties
example:
PostModel postModelFromJson(String str) =>
postModel.fromJson(json.decode(str));
String postModelToJson(PostModel data) =>
json.encode(data.toJson());

List<Widgets> in rows and lines dynamically in Flutter

I have json:
{
"name": "Test",
"groupsCount": 5,
"groups": [
{
"name": "William Cooper",
"number": 1,
"linesCount": 2,
"lines": [
{
"name": "Brittany Ramirez",
"number": 1,
"placesCount": 15,
"places": [
{
"name": "Elizabeth Welch",
"number": 1
},
{
"name": "Bradley Pugh",
"number": 2
},
{
"name": "Noah Johnson",
"number": 3
},
{
"name": "Laura Cox",
"number": 4
},
{
"name": "Tiffany Hatfield",
"number": 5
},
{
"name": "Patricia Hayes",
"number": 6
},
{
"name": "Kevin Jenkins MD",
"number": 7
},
{
"name": "Brent Wilkins",
"number": 8
},
{
"name": "Mr. Bruce Hart",
"number": 9
},
{
"name": "Courtney Newman",
"number": 10
},
{
"name": "Dawn Campbell",
"number": 11
},
{
"name": "Ashley Scott",
"number": 12
},
{
"name": "Robert Becker",
"number": 13
},
{
"name": "Kevin Williams",
"number": 14
},
{
"name": "Elizabeth Davidson",
"number": 15
}
]
},
{
"name": "Carol Watson",
"number": 2,
"placesCount": 12,
"places": [
{
"name": "Kathleen Jones",
"number": 16
},
{
"name": "Robin Smith",
"number": 17
},
{
"name": "David Johnson",
"number": 18
},
{
"name": "Richard Boyd",
"number": 19
},
{
"name": "Mason Randolph",
"number": 20
},
{
"name": "James Bernard",
"number": 21
},
{
"name": "Timothy Miller",
"number": 22
},
{
"name": "Thomas Stone",
"number": 23
},
{
"name": "Steven Jones",
"number": 24
},
{
"name": "William Hernandez",
"number": 25
},
{
"name": "Joy Duarte",
"number": 26
},
{
"name": "Justin Anderson",
"number": 27
}
]
}
]
},
{
"name": "Sarah Jordan",
"number": 2,
"linesCount": 1,
"lines": [
{
"name": "Lacey Estrada",
"number": 3,
"placesCount": 15,
"places": [
{
"name": "Madison Smith",
"number": 28
},
{
"name": "Kathleen Wells",
"number": 29
},
{
"name": "Dale Gross",
"number": 30
},
{
"name": "Brandy Cabrera",
"number": 31
},
{
"name": "Ashley Torres",
"number": 32
},
{
"name": "Ralph Long",
"number": 33
},
{
"name": "Christopher Walker",
"number": 34
},
{
"name": "Kimberly Moore",
"number": 35
},
{
"name": "Andrea Ortiz",
"number": 36
},
{
"name": "Heidi Todd",
"number": 37
},
{
"name": "Austin Wang",
"number": 38
},
{
"name": "Bryan Adams",
"number": 39
},
{
"name": "Jeffrey Alvarado",
"number": 40
},
{
"name": "Richard Morrison",
"number": 41
},
{
"name": "Jennifer Hodge",
"number": 42
}
]
}
]
},
{
"name": "Tiffany Lynch",
"number": 3,
"linesCount": 1,
"lines": [
{
"name": "Kimberly Howe DVM",
"number": 4,
"placesCount": 15,
"places": [
{
"name": "Nancy King",
"number": 43
},
{
"name": "Angela Cabrera",
"number": 44
},
{
"name": "Elizabeth Mack",
"number": 45
},
{
"name": "Shelly Riggs",
"number": 46
},
{
"name": "Jeremy French",
"number": 47
},
{
"name": "Deborah Myers",
"number": 48
},
{
"name": "Robert Kramer",
"number": 49
},
{
"name": "Brian Cunningham MD",
"number": 50
},
{
"name": "Christopher Brown",
"number": 51
},
{
"name": "Kathryn James",
"number": 52
},
{
"name": "Cassandra Martinez",
"number": 53
},
{
"name": "Nathan Long",
"number": 54
},
{
"name": "Molly Wilson",
"number": 55
},
{
"name": "Matthew Reilly",
"number": 56
},
{
"name": "Erin Maddox",
"number": 57
}
]
}
]
},
{
"name": "Christopher Martin",
"number": 4,
"linesCount": 1,
"lines": [
{
"name": "Gina Brewer",
"number": 5,
"placesCount": 13,
"places": [
{
"name": "Dennis Owens",
"number": 58
},
{
"name": "Rebecca Caldwell",
"number": 59
},
{
"name": "James Mckinney",
"number": 60
},
{
"name": "Donna Lee",
"number": 61
},
{
"name": "Michelle Martinez",
"number": 62
},
{
"name": "Jennifer Davis",
"number": 63
},
{
"name": "Shawn Moore",
"number": 64
},
{
"name": "Jeremiah Reilly",
"number": 65
},
{
"name": "Bruce Mendoza",
"number": 66
},
{
"name": "Juan Weaver",
"number": 67
},
{
"name": "Brian Bates",
"number": 68
},
{
"name": "Caitlin Jenkins",
"number": 69
},
{
"name": "Rachel Thomas",
"number": 70
}
]
}
]
},
{
"name": "Michelle Thompson",
"number": 5,
"linesCount": 2,
"lines": [
{
"name": "Kathleen Hall",
"number": 6,
"placesCount": 12,
"places": [
{
"name": "Jennifer Vaughan",
"number": 71
},
{
"name": "Glenn Mayer",
"number": 72
},
{
"name": "Allison Coleman",
"number": 73
},
{
"name": "Brittany Harris",
"number": 74
},
{
"name": "John Mccullough",
"number": 75
},
{
"name": "James Curtis",
"number": 76
},
{
"name": "John Smith",
"number": 77
},
{
"name": "Alison Morales",
"number": 78
},
{
"name": "Matthew Jones",
"number": 79
},
{
"name": "Jessica Watson",
"number": 80
},
{
"name": "Yvonne Anderson",
"number": 81
},
{
"name": "David Price",
"number": 82
}
]
},
{
"name": "Sarah White",
"number": 7,
"placesCount": 10,
"places": [
{
"name": "Kathleen Owen",
"number": 83
},
{
"name": "Amy Strickland",
"number": 84
},
{
"name": "James Collier",
"number": 85
},
{
"name": "Keith Smith Jr.",
"number": 86
},
{
"name": "Christopher York",
"number": 87
},
{
"name": "Patricia Todd",
"number": 88
},
{
"name": "Matthew Harris",
"number": 89
},
{
"name": "Betty Mckee",
"number": 90
},
{
"name": "Kayla Hahn",
"number": 91
},
{
"name": "Craig Duncan",
"number": 92
}
]
}
]
}
]
}
and I want to build view using lines and places. So if group have 2 lines and each line has 15 places I want to build something like that:
...............
...............
This is my code:
import 'package:flutter/material.dart';
import 'package:parking/models/groups.dart';
import 'package:parking/models/parking_group.dart';
import 'package:parking/services/parking_service.dart';
class ParkingDetailsScreen extends StatefulWidget {
#override
createState() => ParkingDetailsState();
}
class ParkingDetailsState extends State<ParkingDetailsScreen> {
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Parking Details"),
),
body: FutureBuilder<ParkingGroup>(
future: ParkingService.getParking(),
builder: (context, snapshot) {
if (snapshot.hasError) print(snapshot.error);
return snapshot.hasData
? _buildParking(snapshot.data)
: Center(child: CircularProgressIndicator());
},
)
);
}
}
final _parkings = <Groups>[];
Widget _buildParking(ParkingGroup parkingGroup) {
_parkings.clear();
_parkings.addAll(parkingGroup.groups);
return ListView.builder(
itemCount: _parkings.length,
itemBuilder: (context, index) {
return _buildRow(_parkings[index], context);
},
);
}
Widget _buildRow(Groups parkingGroup, BuildContext context) {
return Container(
padding: const EdgeInsets.all(16.0),
child: Row(
children: _buildRowList(parkingGroup),
),
);
}
List<Widget> _buildRowList(Groups parkingGroup) {
List<Widget> places = [];
for (var place in parkingGroup.lines) {
for (var placeLine in place.places) {
places.add(_buildPlace(placeLine));
}
}
return places;
}
Widget _buildPlace(place) {
return Container(
padding: const EdgeInsets.only(bottom: 8.0),
child:
SizedBox(
height: 5,
width: 5,
child: DecoratedBox(
decoration: BoxDecoration(
border: Border.all(color: Colors.blueAccent),
)),
),
);
}
//
//Widget _buildRow(Groups parkingGroup, BuildContext context) {
// return Container(
// padding: const EdgeInsets.all(16.0),
// child: Row(
// children: [
// Container(
// padding: const EdgeInsets.only(bottom: 8.0),
// child:
// SizedBox(
// height: 30,
// width: 30,
// child: DecoratedBox(
// decoration: BoxDecoration(
// border: Border.all(color: Colors.blueAccent),
// )),
// ),
// ),
// ],
// ),
// );
//}
but for this code I see all places in one line:
..............................
instead of
...............
...............
What I need to change in my code to get good result?
You need to change your _buildRow() and _buildRowList() methods:
Widget _buildRow(Groups parkingGroup, BuildContext context) {
return Container(
padding: const EdgeInsets.all(16.0),
child: Column( // As you expect multiple lines you need a column not a row
children: _buildRowList(parkingGroup),
),
);
}
List<Widget> _buildRowList(Groups parkingGroup) {
List<Widget> lines = []; // this will hold Rows according to available lines
for (var line in parkingGroup.lines) {
List<Widget> placesForLine = [] // this will hold the places for each line
for (var placeLine in line.places) {
placesForLine.add(_buildPlace(placeLine));
}
lines.add(Row(children: placesForLine));
}
return lines;
}

How to calculate YTD and MTD in mongodb?

How to calculate Month-To-Date(MTD) and Year-To-Date(YTD) in mongodb in a single query? sample data below, in this data requestedOn is a date field, I want to calculate MTD & YTD, on the assumption of financial year on "1st Jan of the year"(For example financial year for year 2016 is "01-Jan-2016" :
{
"_id": {
"$oid": "5808578b33fa6f161c9747f8"
},
"_class": "exceltest.TestBean",
"requestedOn": "2000-03-01",
"bookName": "Test6",
"revenue": 10.0,
"unitsSold": 1,
"bookCategory": [
{
"categoryCode": "Cooking/"
},
{
"categoryCode": "Cooking/Beverages"
},
{
"categoryCode": "Food Receipe/"
},
{
"categoryCode": "Food Receipe/Bartending"
},
{
"categoryCode": "Cooking/Beverages/Bartending"
},
{
"categoryCode": "Food Receipe/Taste"
}
]
}{
"_id": {
"$oid": "5808578b33fa6f161c9747f9"
},
"_class": "exceltest.TestBean",
"requestedOn": "2000-03-01",
"bookName": "Test1",
"revenue": 11.0,
"unitsSold": 2,
"bookCategory": [
{
"categoryCode": "Cooking/"
},
{
"categoryCode": "Cooking/Beverages"
},
{
"categoryCode": "Food Receipe/"
},
{
"categoryCode": "Food Receipe/Bartending"
},
{
"categoryCode": "Cooking/Beverages/Bartending"
},
{
"categoryCode": "Food Receipe/Taste"
}
]
}{
"_id": {
"$oid": "5808578b33fa6f161c9747fa"
},
"_class": "exceltest.TestBean",
"requestedOn": "2000-06-01",
"bookName": "Test2",
"revenue": 12.0,
"unitsSold": 3,
"bookCategory": [
{
"categoryCode": "Cooking/"
},
{
"categoryCode": "Cooking/Beverages"
},
{
"categoryCode": "Food Receipe/"
},
{
"categoryCode": "Food Receipe/Bartending"
},
{
"categoryCode": "Cooking/Beverages/Bartending"
},
{
"categoryCode": "Food Receipe/Taste"
}
]
}{
"_id": {
"$oid": "5808578b33fa6f161c9747fb"
},
"_class": "exceltest.TestBean",
"requestedOn": "2000-07-01",
"bookName": "Test3",
"revenue": 13.0,
"unitsSold": 4,
"bookCategory": [
{
"categoryCode": "Cooking/"
},
{
"categoryCode": "Cooking/Beverages"
},
{
"categoryCode": "Food Receipe/"
},
{
"categoryCode": "Food Receipe/Bartending"
},
{
"categoryCode": "Cooking/Beverages/Bartending"
},
{
"categoryCode": "Food Receipe/Taste"
}
]
}{
"_id": {
"$oid": "5808578b33fa6f161c9747fc"
},
"_class": "exceltest.TestBean",
"requestedOn": "2009-09-01",
"bookName": "Test4",
"revenue": 14.0,
"unitsSold": 5,
"bookCategory": [
{
"categoryCode": "Cooking/"
},
{
"categoryCode": "Cooking/Beverages"
},
{
"categoryCode": "Food Receipe/"
},
{
"categoryCode": "Food Receipe/Bartending"
},
{
"categoryCode": "Cooking/Beverages/Bartending"
},
{
"categoryCode": "Food Receipe/Taste"
}
]
}{
"_id": {
"$oid": "5808578b33fa6f161c9747fd"
},
"_class": "exceltest.TestBean",
"requestedOn": "2009-06-01",
"bookName": "Test5",
"revenue": 15.0,
"unitsSold": 6,
"bookCategory": [
{
"categoryCode": "Cooking/"
},
{
"categoryCode": "Cooking/Beverages"
},
{
"categoryCode": "Food Receipe/"
},
{
"categoryCode": "Food Receipe/Bartending"
},
{
"categoryCode": "Cooking/Beverages/Bartending"
},
{
"categoryCode": "Food Receipe/Taste"
}
]
}{
"_id": {
"$oid": "5808578b33fa6f161c9747fe"
},
"_class": "exceltest.TestBean",
"requestedOn": "2004-06-01",
"bookName": "Test10",
"revenue": 16.0,
"unitsSold": 7,
"bookCategory": [
{
"categoryCode": "Cooking/"
},
{
"categoryCode": "Cooking/Beverages"
},
{
"categoryCode": "Food Receipe/"
},
{
"categoryCode": "Food Receipe/Bartending"
},
{
"categoryCode": "Cooking/Beverages/Bartending"
},
{
"categoryCode": "Food Receipe/Taste"
}
]
}{
"_id": {
"$oid": "5808578b33fa6f161c9747ff"
},
"_class": "exceltest.TestBean",
"requestedOn": "2000-01-01",
"bookName": "Test11",
"revenue": 100.0,
"unitsSold": 100,
"bookCategory": [
{
"categoryCode": "Cooking/"
},
{
"categoryCode": "Cooking/Beverages"
},
{
"categoryCode": "Food Receipe/"
},
{
"categoryCode": "Food Receipe/Bartending"
},
{
"categoryCode": "Cooking/Beverages/Bartending"
},
{
"categoryCode": "Food Receipe/Taste"
}
]
}{
"_id": {
"$oid": "580857b833fa6f0c3499e462"
},
"_class": "exceltest.TestBean",
"requestedOn": "2000-02-01",
"bookName": "Test1",
"revenue": 20.0,
"unitsSold": 10,
"bookCategory": [
{
"categoryCode": "Cooking/"
},
{
"categoryCode": "Cooking/Beverages"
},
{
"categoryCode": "Food Receipe/"
},
{
"categoryCode": "Food Receipe/Bartending"
}
]
}{
"_id": {
"$oid": "580857b833fa6f0c3499e463"
},
"_class": "exceltest.TestBean",
"requestedOn": "2001-02-01",
"bookName": "Test2",
"revenue": 19.0,
"unitsSold": 9,
"bookCategory": [
{
"categoryCode": "Cooking/"
},
{
"categoryCode": "Cooking/Beverages"
},
{
"categoryCode": "Food Receipe/"
},
{
"categoryCode": "Food Receipe/Bartending"
}
]
}{
"_id": {
"$oid": "580857b833fa6f0c3499e464"
},
"_class": "exceltest.TestBean",
"requestedOn": "2001-02-01",
"bookName": "Test3",
"revenue": 18.0,
"unitsSold": 8,
"bookCategory": [
{
"categoryCode": "Cooking/"
},
{
"categoryCode": "Cooking/Beverages"
},
{
"categoryCode": "Food Receipe/"
},
{
"categoryCode": "Food Receipe/Bartending"
}
]
}{
"_id": {
"$oid": "580857b833fa6f0c3499e465"
},
"_class": "exceltest.TestBean",
"requestedOn": "2007-06-01",
"bookName": "Test4",
"revenue": 17.0,
"unitsSold": 7,
"bookCategory": [
{
"categoryCode": "Cooking/"
},
{
"categoryCode": "Cooking/Beverages"
},
{
"categoryCode": "Food Receipe/"
},
{
"categoryCode": "Food Receipe/Bartending"
}
]
}{
"_id": {
"$oid": "580857b833fa6f0c3499e466"
},
"_class": "exceltest.TestBean",
"requestedOn": "2005-06-01",
"bookName": "Test5",
"revenue": 16.0,
"unitsSold": 6,
"bookCategory": [
{
"categoryCode": "Cooking/"
},
{
"categoryCode": "Cooking/Beverages"
},
{
"categoryCode": "Food Receipe/"
},
{
"categoryCode": "Food Receipe/Bartending"
}
]
}{
"_id": {
"$oid": "580857b833fa6f0c3499e467"
},
"_class": "exceltest.TestBean",
"requestedOn": "2004-06-01",
"bookName": "Test1",
"revenue": 15.0,
"unitsSold": 5,
"bookCategory": [
{
"categoryCode": "Cooking/"
},
{
"categoryCode": "Cooking/Beverages"
},
{
"categoryCode": "Food Receipe/"
},
{
"categoryCode": "Food Receipe/Bartending"
}
]
}{
"_id": {
"$oid": "580857b833fa6f0c3499e468"
},
"_class": "exceltest.TestBean",
"requestedOn": "2002-06-01",
"bookName": "Test2",
"revenue": 14.0,
"unitsSold": 4,
"bookCategory": [
{
"categoryCode": "Cooking/"
},
{
"categoryCode": "Cooking/Beverages"
},
{
"categoryCode": "Food Receipe/"
},
{
"categoryCode": "Food Receipe/Bartending"
}
]
}{
"_id": {
"$oid": "580857b833fa6f0c3499e469"
},
"_class": "exceltest.TestBean",
"requestedOn": "2001-06-01",
"bookName": "Test3",
"revenue": 13.0,
"unitsSold": 3,
"bookCategory": [
{
"categoryCode": "Cooking/"
},
{
"categoryCode": "Cooking/Beverages"
},
{
"categoryCode": "Food Receipe/"
},
{
"categoryCode": "Food Receipe/Bartending"
}
]
}{
"_id": {
"$oid": "580857b833fa6f0c3499e46a"
},
"_class": "exceltest.TestBean",
"requestedOn": "2000-06-01",
"bookName": "Test4",
"revenue": 12.0,
"unitsSold": 2,
"bookCategory": [
{
"categoryCode": "Cooking/"
},
{
"categoryCode": "Cooking/Beverages"
},
{
"categoryCode": "Food Receipe/"
},
{
"categoryCode": "Food Receipe/Bartending"
}
]
}{
"_id": {
"$oid": "580857b833fa6f0c3499e46b"
},
"_class": "exceltest.TestBean",
"requestedOn": "2008-06-01",
"bookName": "Test5",
"revenue": 11.0,
"unitsSold": 1,
"bookCategory": [
{
"categoryCode": "Cooking/"
},
{
"categoryCode": "Cooking/Beverages"
},
{
"categoryCode": "Food Receipe/"
},
{
"categoryCode": "Food Receipe/Bartending"
}
]
}
Regards
Kris
It is a good practice to keep dates in MongoDB in its native dateformat ISODate().
You can use date formats like $year,$month,$day,$hour etc.
These can be used for grouping , in your case:
db.collectionName.aggregate([
{$group:{_id:{'Date':{$year:'$requestedOn'}},total:{$sum:'$FieldName'}}}
])
to convert string to ISODate , answers can be found at
- [http://stackoverflow.com/questions/15473772/how-to-convert-from-string-to-date-data-type?noredirect=1&lq=1][2]
- [http://stackoverflow.com/questions/15473772/how-to-convert-from-string-to-date-data-type?noredirect=1&lq=1][2]

JSONPath extracting values

I want extract all the offerId's from just one of the membershipId's below:
{
"resultCode": "SUCCESS",
"errorCode": null,
"errorMessage": null,
"membershipCoupons":
[
{
"membershipId": "32021428",
"coupons":
[
{
"offerId": "000C291EE8241ED4AAF43058D8564910",
"description": "nora",
"graphics":
[
{
"width": 400,
"height": 200,
"quality": "Low",
"url": "https://site/02_201506_011/000C291EE8241ED4AAF43058D8564910Low.jpg"
},
{
"width": 900,
"height": 600,
"quality": "High",
"url": "https://site/02_201506_011/000C291EE8241ED4AAF43058D8564910High.jpg"
}
],
"endTime": 1423353600000,
"activationDate": 1423579699407,
"redemption": null
},
{
"offerId": "000C291EE8241ED4AAF43058D857A910",
"description": "nora",
"graphics":
[
{
"width": 400,
"height": 200,
"quality": "Low",
"url": "https://site/02_201506_011/000C291EE8241ED4AAF43058D857A910Low.jpg"
},
{
"width": 900,
"height": 600,
"quality": "High",
"url": "https://site/02_201506_011/000C291EE8241ED4AAF43058D857A910High.jpg"
}
],
"endTime": 1423353600000,
"activationDate": 1423579703400,
"redemption": null
},
{
"offerId": "000C291EE8241ED4AAF43058D8608910",
"description": "nora",
"graphics":
[
{
"width": 400,
"height": 200,
"quality": "Low",
"url": "https://site/02_201506_011/000C291EE8241ED4AAF43058D8608910Low.jpg"
},
{
"width": 900,
"height": 600,
"quality": "High",
"url": "https://site/02_201506_011/000C291EE8241ED4AAF43058D8608910High.jpg"
}
],
"endTime": 1423353600000,
"activationDate": 1423579706707,
"redemption": null
},
{
"offerId": "000C291EE8241ED4AAF43058D862E910",
"description": "nora",
"graphics":
[
{
"width": 400,
"height": 200,
"quality": "Low",
"url": "https://site/02_201506_011/000C291EE8241ED4AAF43058D862E910Low.jpg"
},
{
"width": 900,
"height": 600,
"quality": "High",
"url": "https://site/02_201506_011/000C291EE8241ED4AAF43058D862E910High.jpg"
}
],
"endTime": 1423353600000,
"activationDate": 1423579710047,
"redemption": null
},
{
"offerId": "000C291EE8241ED4AAF43058D87A0910",
"description": "nora",
"graphics":
[
{
"width": 400,
"height": 200,
"quality": "Low",
"url": "https://site/02_201506_011/000C291EE8241ED4AAF43058D87A0910Low.jpg"
},
{
"width": 900,
"height": 600,
"quality": "High",
"url": "https://site/02_201506_011/000C291EE8241ED4AAF43058D87A0910High.jpg"
}
],
"endTime": 1423353600000,
"activationDate": 1423579713540,
"redemption": null
},
{
"offerId": "000C291EE8241ED4AAF43058D877E910",
"description": "nora",
"graphics":
[
{
"width": 400,
"height": 200,
"quality": "Low",
"url": "https://site/02_201506_011/000C291EE8241ED4AAF43058D877E910Low.jpg"
},
{
"width": 900,
"height": 600,
"quality": "High",
"url": "https://site/02_201506_011/000C291EE8241ED4AAF43058D877E910High.jpg"
}
],
"endTime": 1423353600000,
"activationDate": 1423579717533,
"redemption": null
},
{
"offerId": "000C291EE8241ED4AAF43058D87B8910",
"description": "nora",
"graphics":
[
{
"width": 400,
"height": 200,
"quality": "Low",
"url": "https://site/02_201506_011/000C291EE8241ED4AAF43058D87B8910Low.jpg"
},
{
"width": 900,
"height": 600,
"quality": "High",
"url": "https://site/02_201506_011/000C291EE8241ED4AAF43058D87B8910High.jpg"
}
],
"endTime": 1423353600000,
"activationDate": 1423579721123,
"redemption": null
},
{
"offerId": "000C291EE8241ED4AAF43058D8870910",
"description": "nora",
"graphics":
[
{
"width": 400,
"height": 200,
"quality": "Low",
"url": "https://site/02_201506_011/000C291EE8241ED4AAF43058D8870910Low.jpg"
},
{
"width": 900,
"height": 600,
"quality": "High",
"url": "https://site/02_201506_011/000C291EE8241ED4AAF43058D8870910High.jpg"
}
],
"endTime": 1423353600000,
"activationDate": 1423579724430,
"redemption": null
},
{
"offerId": "000C297765971EE4A8C22C6999219BA4",
"description": "nora",
"graphics":
[
{
"width": 400,
"height": 200,
"quality": "Low",
"url": "https://site/02_201504_003/000C297765971EE4A8C22C6999219BA4Low.jpg"
},
{
"width": 900,
"height": 600,
"quality": "High",
"url": "https://site/02_201504_003/000C297765971EE4A8C22C6999219BA4High.jpg"
}
],
"endTime": 1425168000000,
"activationDate": 1423136616203,
"redemption": null
},
{
"offerId": "000C297765971EE4A8C22C699921FBA4",
"description": "nora",
"graphics":
[
{
"width": 400,
"height": 200,
"quality": "Low",
"url": "https://site/02_201504_003/000C297765971EE4A8C22C699921FBA4Low.jpg"
},
{
"width": 900,
"height": 600,
"quality": "High",
"url": "https://site/02_201504_003/000C297765971EE4A8C22C699921FBA4High.jpg"
}
],
"endTime": 1425168000000,
"activationDate": 1423139501440,
"redemption": null
},
{
"offerId": "000C297765971EE4A8C22C6999233BA4",
"description": "nora",
"graphics":
[
{
"width": 400,
"height": 200,
"quality": "Low",
"url": "https://site/02_201504_003/000C297765971EE4A8C22C6999233BA4Low.jpg"
},
{
"width": 900,
"height": 600,
"quality": "High",
"url": "https://site/02_201504_003/000C297765971EE4A8C22C6999233BA4High.jpg"
}
],
"endTime": 1425168000000,
"activationDate": 1423215586673,
"redemption": null
}
]
},
{
"membershipId": "8315319211",
"coupons":
[
{
"offerId": "000C291EE8241ED4AAF43058D85CA910",
"description": "nora",
"graphics":
[
{
"width": 400,
"height": 200,
"quality": "Low",
"url": "https://site/02_201506_011/000C291EE8241ED4AAF43058D85CA910Low.jpg"
},
{
"width": 900,
"height": 600,
"quality": "High",
"url": "https://site/02_201506_011/000C291EE8241ED4AAF43058D85CA910High.jpg"
}
],
"endTime": 1423353600000,
"activationDate": null,
"redemption": null
},
{
"offerId": "000C291EE8241ED4AAF43058D85F6910",
"description": "nora",
"graphics":
[
{
"width": 400,
"height": 200,
"quality": "Low",
"url": "https://site/02_201506_011/000C291EE8241ED4AAF43058D85F6910Low.jpg"
},
{
"width": 900,
"height": 600,
"quality": "High",
"url": "https://site/02_201506_011/000C291EE8241ED4AAF43058D85F6910High.jpg"
}
],
"endTime": 1423353600000,
"activationDate": null,
"redemption": null
},
{
"offerId": "000C291EE8241ED4AAF43058D85E2910",
"description": "nora",
"graphics":
[
{
"width": 400,
"height": 200,
"quality": "Low",
"url": "https://site/02_201506_011/000C291EE8241ED4AAF43058D85E2910Low.jpg"
},
{
"width": 900,
"height": 600,
"quality": "High",
"url": "https://site/02_201506_011/000C291EE8241ED4AAF43058D85E2910High.jpg"
}
],
"endTime": 1423353600000,
"activationDate": null,
"redemption": null
},
{
"offerId": "000C291EE8241ED4AAF43058D85FC910",
"description": "nora",
"graphics":
[
{
"width": 400,
"height": 200,
"quality": "Low",
"url": "https://site/02_201506_011/000C291EE8241ED4AAF43058D85FC910Low.jpg"
},
{
"width": 900,
"height": 600,
"quality": "High",
"url": "https://site/02_201506_011/000C291EE8241ED4AAF43058D85FC910High.jpg"
}
],
"endTime": 1423353600000,
"activationDate": null,
"redemption": null
},
{
"offerId": "000C291EE8241ED4AAF43058D8776910",
"description": "nora",
"graphics":
[
{
"width": 400,
"height": 200,
"quality": "Low",
"url": "https://site/02_201506_011/000C291EE8241ED4AAF43058D8776910Low.jpg"
},
{
"width": 900,
"height": 600,
"quality": "High",
"url": "https://site/02_201506_011/000C291EE8241ED4AAF43058D8776910High.jpg"
}
],
"endTime": 1423353600000,
"activationDate": null,
"redemption": null
},
{
"offerId": "000C291EE8241ED4AAF43058D87A8910",
"description": "nora",
"graphics":
[
{
"width": 400,
"height": 200,
"quality": "Low",
"url": "https://site/02_201506_011/000C291EE8241ED4AAF43058D87A8910Low.jpg"
},
{
"width": 900,
"height": 600,
"quality": "High",
"url": "https://site/02_201506_011/000C291EE8241ED4AAF43058D87A8910High.jpg"
}
],
"endTime": 1423353600000,
"activationDate": null,
"redemption": null
},
{
"offerId": "000C291EE8241ED4AAF43058D87B6910",
"description": "nora",
"graphics":
[
{
"width": 400,
"height": 200,
"quality": "Low",
"url": "https://site/02_201506_011/000C291EE8241ED4AAF43058D87B6910Low.jpg"
},
{
"width": 900,
"height": 600,
"quality": "High",
"url": "https://site/02_201506_011/000C291EE8241ED4AAF43058D87B6910High.jpg"
}
],
"endTime": 1423353600000,
"activationDate": null,
"redemption": null
},
{
"offerId": "000C291EE8241ED4AAF43058D87D0910",
"description": "nora.",
"graphics":
[
{
"width": 400,
"height": 200,
"quality": "Low",
"url": "https://site/02_201506_011/000C291EE8241ED4AAF43058D87D0910Low.jpg"
},
{
"width": 900,
"height": 600,
"quality": "High",
"url": "https://site/02_201506_011/000C291EE8241ED4AAF43058D87D0910High.jpg"
}
],
"endTime": 1423353600000,
"activationDate": null,
"redemption": null
}
]
}
]
}
I have something that works for both memberId's but I want to parameterize so that I pick only the offerId's for a parameter I have in a session that I usually reference like this ${medlem}, I use Scala.
This works:
.check(jsonPath("$.membershipCoupons[*].coupons[?(#.activationDate==null)].offerId").findAll.optional.saveAs("itemList"))
But how can I say this with a parameter pointing to a specific memberId something like this:
.check(jsonPath("$.membershipCoupons[membershipId[${medlem}]].coupons[?(#.activationDate==null)].offerId").findAll.optional.saveAs("itemList"))
I think you need to split operation on 2 steps:
arrayMembershipId = $.membershipCoupons[*].membershipId
n = getIndex(membershipIdArray, yourcode)
arrayOffer = membershipCoupons[n].coupons[?(#.activationDate==null)].offerId