Guest User

DimZeta - GridView.builder in CustomScrollView loads all items

a guest
May 16th, 2021
358
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 25.50 KB | None | 0 0
  1. import 'dart:convert';
  2.  
  3. import 'package:flutter/material.dart';
  4. import 'package:flutter/services.dart';
  5.  
  6. void main() {
  7.   runApp(MyApp());
  8. }
  9.  
  10. class MyApp extends StatelessWidget {
  11.   @override
  12.   Widget build(BuildContext context) {
  13.     return MaterialApp(
  14.       title: 'Flutter Demo',
  15.       theme: ThemeData(
  16.         primarySwatch: Colors.blue,
  17.       ),
  18.       home: MyHomePage(title: 'GridView Builder'),
  19.     );
  20.   }
  21. }
  22.  
  23. class MyHomePage extends StatefulWidget {
  24.   MyHomePage({Key key, this.title}) : super(key: key);
  25.  
  26.   final String title;
  27.  
  28.   @override
  29.   _MyHomePageState createState() => _MyHomePageState();
  30. }
  31.  
  32. class _MyHomePageState extends State<MyHomePage> {
  33.   final ValueNotifier<dynamic> _list = ValueNotifier<dynamic>([]);
  34.   final _fakeData = '''
  35.    [
  36.  {
  37.    "_id": "60a16cb160d061330a7a7aed",
  38.    "index": 0,
  39.    "guid": "08d7b0df-b640-4111-aaf2-2cae6b04a9b7",
  40.    "isActive": false,
  41.    "balance": "\$2,630.54",
  42.    "picture": "http://placehold.it/32x32"
  43.  },
  44.  {
  45.    "_id": "60a16cb18eebc680a37d804d",
  46.    "index": 1,
  47.    "guid": "cdb57d55-75f0-43f5-b6bd-7878b0838efb",
  48.    "isActive": false,
  49.    "balance": "\$1,611.71",
  50.    "picture": "http://placehold.it/32x32"
  51.  },
  52.  {
  53.    "_id": "60a16cb129556b6c93b20df8",
  54.    "index": 2,
  55.    "guid": "884e1ff4-5aab-46d3-bee3-2515ff4145b8",
  56.    "isActive": false,
  57.    "balance": "\$1,653.44",
  58.    "picture": "http://placehold.it/32x32"
  59.  },
  60.  {
  61.    "_id": "60a16cb125856a8287d31f05",
  62.    "index": 3,
  63.    "guid": "96beb386-4103-4024-a062-c5e1e9d4eb8d",
  64.    "isActive": false,
  65.    "balance": "\$3,947.17",
  66.    "picture": "http://placehold.it/32x32"
  67.  },
  68.  {
  69.    "_id": "60a16cb1c32f529ef1fdf00b",
  70.    "index": 4,
  71.    "guid": "f7fc1e5d-5044-4218-8f59-7a635c28a537",
  72.    "isActive": true,
  73.    "balance": "\$3,467.95",
  74.    "picture": "http://placehold.it/32x32"
  75.  },
  76.  {
  77.    "_id": "60a16cb144600da2b245ea2f",
  78.    "index": 5,
  79.    "guid": "27016432-a376-46f6-8867-59ba39258cec",
  80.    "isActive": false,
  81.    "balance": "\$1,412.29",
  82.    "picture": "http://placehold.it/32x32"
  83.  },
  84.  {
  85.    "_id": "60a16cb18b21181074e99c4b",
  86.    "index": 6,
  87.    "guid": "c52e4bf0-7efb-4ea6-bf0f-133ae0bdc818",
  88.    "isActive": true,
  89.    "balance": "\$1,188.63",
  90.    "picture": "http://placehold.it/32x32"
  91.  },
  92.  {
  93.    "_id": "60a16cb1d090533c7488c21e",
  94.    "index": 7,
  95.    "guid": "16cde0b5-aa3c-4d7a-87bf-0a813cb9784f",
  96.    "isActive": true,
  97.    "balance": "\$3,344.94",
  98.    "picture": "http://placehold.it/32x32"
  99.  },
  100.  {
  101.    "_id": "60a16cb15b577830072126ee",
  102.    "index": 8,
  103.    "guid": "4363eb16-d0d6-4c1f-af1a-d8ad9f7bb638",
  104.    "isActive": true,
  105.    "balance": "\$3,370.47",
  106.    "picture": "http://placehold.it/32x32"
  107.  },
  108.  {
  109.    "_id": "60a16cb14b9a00362e497a69",
  110.    "index": 9,
  111.    "guid": "70fcca23-ade3-481c-9c90-28e4ac19c71f",
  112.    "isActive": true,
  113.    "balance": "\$2,772.38",
  114.    "picture": "http://placehold.it/32x32"
  115.  },
  116.  {
  117.    "_id": "60a16cb1eb145e2531def5b6",
  118.    "index": 10,
  119.    "guid": "b8c3b31f-10ae-474d-8380-58261b2ac1a4",
  120.    "isActive": true,
  121.    "balance": "\$1,511.79",
  122.    "picture": "http://placehold.it/32x32"
  123.  },
  124.  {
  125.    "_id": "60a16cb1d47cd2995beb10ab",
  126.    "index": 11,
  127.    "guid": "a13f6c97-139a-4a30-a4cf-3266d6a793e7",
  128.    "isActive": true,
  129.    "balance": "\$1,494.82",
  130.    "picture": "http://placehold.it/32x32"
  131.  },
  132.  {
  133.    "_id": "60a16cb14987c427b38ee662",
  134.    "index": 12,
  135.    "guid": "98fdc4b6-91e6-483d-9d6f-074594cb0c2d",
  136.    "isActive": false,
  137.    "balance": "\$1,979.58",
  138.    "picture": "http://placehold.it/32x32"
  139.  },
  140.  {
  141.    "_id": "60a16cb1083d2f6b7dd98b52",
  142.    "index": 13,
  143.    "guid": "537812cd-8a7b-44e6-a7e5-570d831af43a",
  144.    "isActive": true,
  145.    "balance": "\$3,603.61",
  146.    "picture": "http://placehold.it/32x32"
  147.  },
  148.  {
  149.    "_id": "60a16cb1c76b8d1f2db1bff1",
  150.    "index": 14,
  151.    "guid": "45d54eac-8088-4895-ad52-087a25f48318",
  152.    "isActive": true,
  153.    "balance": "\$2,850.44",
  154.    "picture": "http://placehold.it/32x32"
  155.  },
  156.  {
  157.    "_id": "60a16cb149734a0140f2cefe",
  158.    "index": 15,
  159.    "guid": "0b1c9a8b-98f8-45a4-ba6a-3b2b394c9e55",
  160.    "isActive": false,
  161.    "balance": "\$2,863.90",
  162.    "picture": "http://placehold.it/32x32"
  163.  },
  164.  {
  165.    "_id": "60a16cb19dccdec68bcd4981",
  166.    "index": 16,
  167.    "guid": "c58fe471-68fc-4fd3-b2b0-990e4386de68",
  168.    "isActive": true,
  169.    "balance": "\$1,383.35",
  170.    "picture": "http://placehold.it/32x32"
  171.  },
  172.  {
  173.    "_id": "60a16cb13bebda26a4b14ac6",
  174.    "index": 17,
  175.    "guid": "9a437dd0-d803-415e-bd4f-fa2114081ccd",
  176.    "isActive": false,
  177.    "balance": "\$2,933.81",
  178.    "picture": "http://placehold.it/32x32"
  179.  },
  180.  {
  181.    "_id": "60a16cb1191f16847d580173",
  182.    "index": 18,
  183.    "guid": "e8199f07-c509-4133-a05b-0756ff6efc81",
  184.    "isActive": false,
  185.    "balance": "\$2,414.93",
  186.    "picture": "http://placehold.it/32x32"
  187.  },
  188.  {
  189.    "_id": "60a16cb1fac8046b51e98685",
  190.    "index": 19,
  191.    "guid": "4e3582d4-600a-4629-9675-754e97cde45d",
  192.    "isActive": true,
  193.    "balance": "\$2,397.50",
  194.    "picture": "http://placehold.it/32x32"
  195.  },
  196.  {
  197.    "_id": "60a16cb11c23255b2ed118d5",
  198.    "index": 20,
  199.    "guid": "652840ba-8856-439c-ad11-106d0e3cd05b",
  200.    "isActive": false,
  201.    "balance": "\$1,849.44",
  202.    "picture": "http://placehold.it/32x32"
  203.  },
  204.  {
  205.    "_id": "60a16cb1ea0d47a86cee312e",
  206.    "index": 21,
  207.    "guid": "50b6cb7b-363e-46ea-b4c3-4958e03177d3",
  208.    "isActive": false,
  209.    "balance": "\$2,156.12",
  210.    "picture": "http://placehold.it/32x32"
  211.  },
  212.  {
  213.    "_id": "60a16cb1df983fd3b94ba681",
  214.    "index": 22,
  215.    "guid": "869d045d-c15b-4050-a4b9-d563626e6b37",
  216.    "isActive": true,
  217.    "balance": "\$3,354.23",
  218.    "picture": "http://placehold.it/32x32"
  219.  },
  220.  {
  221.    "_id": "60a16cb18d8572862cd7d043",
  222.    "index": 23,
  223.    "guid": "10e888f9-33ae-4f46-92a2-63478e52d8a0",
  224.    "isActive": false,
  225.    "balance": "\$1,153.50",
  226.    "picture": "http://placehold.it/32x32"
  227.  },
  228.  {
  229.    "_id": "60a16cb10b543382df48214a",
  230.    "index": 24,
  231.    "guid": "24aef107-67e0-45f5-8d10-9e003bc68374",
  232.    "isActive": true,
  233.    "balance": "\$2,313.70",
  234.    "picture": "http://placehold.it/32x32"
  235.  },
  236.  {
  237.    "_id": "60a16cb1189bd1ee387c55f2",
  238.    "index": 25,
  239.    "guid": "8d771cde-2924-4292-ae9a-8e1cab601f2f",
  240.    "isActive": true,
  241.    "balance": "\$3,363.68",
  242.    "picture": "http://placehold.it/32x32"
  243.  },
  244.  {
  245.    "_id": "60a16cb1722b86c0afa94f58",
  246.    "index": 26,
  247.    "guid": "00940e22-801b-4130-9c0a-400e0ff0e027",
  248.    "isActive": true,
  249.    "balance": "\$3,407.10",
  250.    "picture": "http://placehold.it/32x32"
  251.  },
  252.  {
  253.    "_id": "60a16cb1dd388784a40ed30f",
  254.    "index": 27,
  255.    "guid": "020fb7cd-1a27-46c1-8e7a-3f5e50d76ae7",
  256.    "isActive": false,
  257.    "balance": "\$3,312.78",
  258.    "picture": "http://placehold.it/32x32"
  259.  },
  260.  {
  261.    "_id": "60a16cb1661ff06a5eb491f1",
  262.    "index": 28,
  263.    "guid": "fa3f2c62-c26f-432e-9d54-8b05635f3239",
  264.    "isActive": false,
  265.    "balance": "\$1,918.69",
  266.    "picture": "http://placehold.it/32x32"
  267.  },
  268.  {
  269.    "_id": "60a16cb1a57fc0ad95025452",
  270.    "index": 29,
  271.    "guid": "7622b0fc-9dfa-40a8-ac49-c266f0309e74",
  272.    "isActive": true,
  273.    "balance": "\$3,220.47",
  274.    "picture": "http://placehold.it/32x32"
  275.  },
  276.  {
  277.    "_id": "60a16cb137cf773bead8a089",
  278.    "index": 30,
  279.    "guid": "3eb0d54e-a140-4792-88e6-9251477244a1",
  280.    "isActive": true,
  281.    "balance": "\$2,668.69",
  282.    "picture": "http://placehold.it/32x32"
  283.  },
  284.  {
  285.    "_id": "60a16cb1ebd520f320d44302",
  286.    "index": 31,
  287.    "guid": "c56e96f3-4a47-472a-b5b5-bccde81eaf53",
  288.    "isActive": false,
  289.    "balance": "\$2,472.49",
  290.    "picture": "http://placehold.it/32x32"
  291.  },
  292.  {
  293.    "_id": "60a16cb141bf3fe8de51ce28",
  294.    "index": 32,
  295.    "guid": "6e0c9a4b-fc23-406d-919b-1117a5667f6c",
  296.    "isActive": true,
  297.    "balance": "\$1,357.25",
  298.    "picture": "http://placehold.it/32x32"
  299.  },
  300.  {
  301.    "_id": "60a16cb16cbfa50a9829e719",
  302.    "index": 33,
  303.    "guid": "22f3f641-3403-4621-be9d-5af90bd8e366",
  304.    "isActive": true,
  305.    "balance": "\$3,262.91",
  306.    "picture": "http://placehold.it/32x32"
  307.  },
  308.  {
  309.    "_id": "60a16cb187f8cc917f9b8ffb",
  310.    "index": 34,
  311.    "guid": "d5695556-98b4-4d7e-82ca-853a0f914343",
  312.    "isActive": true,
  313.    "balance": "\$2,989.99",
  314.    "picture": "http://placehold.it/32x32"
  315.  },
  316.  {
  317.    "_id": "60a16cb16663a9df06a6c359",
  318.    "index": 35,
  319.    "guid": "dda5b895-c71f-4456-a486-b25733796fa6",
  320.    "isActive": false,
  321.    "balance": "\$3,245.06",
  322.    "picture": "http://placehold.it/32x32"
  323.  },
  324.  {
  325.    "_id": "60a16cb1204c57723c5685f2",
  326.    "index": 36,
  327.    "guid": "46e65957-8552-41da-9a69-2832cc2d5ce1",
  328.    "isActive": true,
  329.    "balance": "\$2,635.87",
  330.    "picture": "http://placehold.it/32x32"
  331.  },
  332.  {
  333.    "_id": "60a16cb1ab1bb647912a6f6c",
  334.    "index": 37,
  335.    "guid": "813211eb-0c00-4e17-97b9-93672eca0ff3",
  336.    "isActive": false,
  337.    "balance": "\$1,718.75",
  338.    "picture": "http://placehold.it/32x32"
  339.  },
  340.  {
  341.    "_id": "60a16cb196ea0e3e4be42fca",
  342.    "index": 38,
  343.    "guid": "3226b3da-33a3-4902-b6f6-0acb13e0f5fe",
  344.    "isActive": true,
  345.    "balance": "\$3,015.62",
  346.    "picture": "http://placehold.it/32x32"
  347.  },
  348.  {
  349.    "_id": "60a16cb194ad1478ffe22d2d",
  350.    "index": 39,
  351.    "guid": "1df42a22-5fca-4cc1-9e87-5a02d9e84fa7",
  352.    "isActive": true,
  353.    "balance": "\$1,436.54",
  354.    "picture": "http://placehold.it/32x32"
  355.  },
  356.  {
  357.    "_id": "60a16cb1504297bd63b91127",
  358.    "index": 40,
  359.    "guid": "1516e670-58e4-49fa-b5dd-dcdd2a876068",
  360.    "isActive": true,
  361.    "balance": "\$3,608.40",
  362.    "picture": "http://placehold.it/32x32"
  363.  },
  364.  {
  365.    "_id": "60a16cb1dfed41d0da562808",
  366.    "index": 41,
  367.    "guid": "a007e9a4-b2d4-428f-84d7-de0e83020c8f",
  368.    "isActive": false,
  369.    "balance": "\$1,472.60",
  370.    "picture": "http://placehold.it/32x32"
  371.  },
  372.  {
  373.    "_id": "60a16cb1557ebefecbf39f5e",
  374.    "index": 42,
  375.    "guid": "204dfa80-62db-498b-be6c-a81451d65b24",
  376.    "isActive": true,
  377.    "balance": "\$2,167.77",
  378.    "picture": "http://placehold.it/32x32"
  379.  },
  380.  {
  381.    "_id": "60a16cb13bab47225267ece2",
  382.    "index": 43,
  383.    "guid": "30171275-902a-4b46-b541-57c6bb311667",
  384.    "isActive": false,
  385.    "balance": "\$1,739.06",
  386.    "picture": "http://placehold.it/32x32"
  387.  },
  388.  {
  389.    "_id": "60a16cb1971b9ded438dcf3a",
  390.    "index": 44,
  391.    "guid": "9f74d725-cba7-417d-a0f2-70b46f358afe",
  392.    "isActive": false,
  393.    "balance": "\$3,242.84",
  394.    "picture": "http://placehold.it/32x32"
  395.  },
  396.  {
  397.    "_id": "60a16cb1aa6b170231807784",
  398.    "index": 45,
  399.    "guid": "9c16e34d-81c5-41c8-a2de-cbc01d266188",
  400.    "isActive": false,
  401.    "balance": "\$3,194.95",
  402.    "picture": "http://placehold.it/32x32"
  403.  },
  404.  {
  405.    "_id": "60a16cb1ea74eb72d18cc8cd",
  406.    "index": 46,
  407.    "guid": "0aa24a57-3eb4-49f9-8809-cef06c998e0d",
  408.    "isActive": false,
  409.    "balance": "\$3,977.36",
  410.    "picture": "http://placehold.it/32x32"
  411.  },
  412.  {
  413.    "_id": "60a16cb13576219426140158",
  414.    "index": 47,
  415.    "guid": "c86143d8-38f1-4f3d-a9b4-2cba764bf7c4",
  416.    "isActive": true,
  417.    "balance": "\$3,179.25",
  418.    "picture": "http://placehold.it/32x32"
  419.  },
  420.  {
  421.    "_id": "60a16cb1b9fe94b2000e980d",
  422.    "index": 48,
  423.    "guid": "b66712bd-354e-4064-884e-6c7d0cfec2da",
  424.    "isActive": false,
  425.    "balance": "\$1,747.17",
  426.    "picture": "http://placehold.it/32x32"
  427.  },
  428.  {
  429.    "_id": "60a16cb183eac69ac2bca5ac",
  430.    "index": 49,
  431.    "guid": "cab5881d-7310-4735-adbb-c2cc90c76b97",
  432.    "isActive": true,
  433.    "balance": "\$3,340.32",
  434.    "picture": "http://placehold.it/32x32"
  435.  },
  436.  {
  437.    "_id": "60a16cb10536917af1b0b053",
  438.    "index": 50,
  439.    "guid": "739bdc0e-3cec-4ef9-bb1c-362867daa2ac",
  440.    "isActive": false,
  441.    "balance": "\$3,216.33",
  442.    "picture": "http://placehold.it/32x32"
  443.  },
  444.  {
  445.    "_id": "60a16cb1bd110afbe899b8d2",
  446.    "index": 51,
  447.    "guid": "6d469f9c-065f-471b-8fa1-b7e37bd775d1",
  448.    "isActive": true,
  449.    "balance": "\$1,111.28",
  450.    "picture": "http://placehold.it/32x32"
  451.  },
  452.  {
  453.    "_id": "60a16cb1c0a7d35e103b42c4",
  454.    "index": 52,
  455.    "guid": "36142246-6c63-45e3-9565-1f91a4e05b71",
  456.    "isActive": false,
  457.    "balance": "\$1,580.84",
  458.    "picture": "http://placehold.it/32x32"
  459.  },
  460.  {
  461.    "_id": "60a16cb1267a29c903df1a9d",
  462.    "index": 53,
  463.    "guid": "2d1ba7e9-2d8a-4d93-962d-8dff03c9ded3",
  464.    "isActive": false,
  465.    "balance": "\$1,441.96",
  466.    "picture": "http://placehold.it/32x32"
  467.  },
  468.  {
  469.    "_id": "60a16cb1e8ca6e94cc110a6d",
  470.    "index": 54,
  471.    "guid": "55f1717f-0ba3-44b7-818d-18135399e750",
  472.    "isActive": true,
  473.    "balance": "\$2,500.78",
  474.    "picture": "http://placehold.it/32x32"
  475.  },
  476.  {
  477.    "_id": "60a16cb149f2764bb94a3a64",
  478.    "index": 55,
  479.    "guid": "910855ea-4733-4c7c-82d9-4c43b08ad70e",
  480.    "isActive": false,
  481.    "balance": "\$1,814.13",
  482.    "picture": "http://placehold.it/32x32"
  483.  },
  484.  {
  485.    "_id": "60a16cb19db215704f95ed87",
  486.    "index": 56,
  487.    "guid": "5173c9e0-60c8-41f9-8059-0da53371b0d2",
  488.    "isActive": true,
  489.    "balance": "\$2,003.07",
  490.    "picture": "http://placehold.it/32x32"
  491.  },
  492.  {
  493.    "_id": "60a16cb16544b102a89406f5",
  494.    "index": 57,
  495.    "guid": "399096e9-afe3-4368-86e6-3733a8b4b49b",
  496.    "isActive": false,
  497.    "balance": "\$3,040.12",
  498.    "picture": "http://placehold.it/32x32"
  499.  },
  500.  {
  501.    "_id": "60a16cb1390bc58b77bf66ce",
  502.    "index": 58,
  503.    "guid": "a73ead73-5951-4486-be26-f39fe12afd64",
  504.    "isActive": false,
  505.    "balance": "\$1,517.08",
  506.    "picture": "http://placehold.it/32x32"
  507.  },
  508.  {
  509.    "_id": "60a16cb1343170d9383f1e39",
  510.    "index": 59,
  511.    "guid": "07a36959-5c49-48ef-889a-54140beb7c3d",
  512.    "isActive": true,
  513.    "balance": "\$3,659.94",
  514.    "picture": "http://placehold.it/32x32"
  515.  },
  516.  {
  517.    "_id": "60a16cb1adc6ee6c53bc7444",
  518.    "index": 60,
  519.    "guid": "4c363de7-1396-449d-989f-9eefbdfa6f31",
  520.    "isActive": true,
  521.    "balance": "\$1,656.40",
  522.    "picture": "http://placehold.it/32x32"
  523.  },
  524.  {
  525.    "_id": "60a16cb10fe9538e7937514b",
  526.    "index": 61,
  527.    "guid": "b2abe55f-77d4-4dfb-83a8-b3969fc0c309",
  528.    "isActive": true,
  529.    "balance": "\$2,644.89",
  530.    "picture": "http://placehold.it/32x32"
  531.  },
  532.  {
  533.    "_id": "60a16cb1b922e71ffffa2b65",
  534.    "index": 62,
  535.    "guid": "534ea809-7224-41fb-9e65-501ac786a786",
  536.    "isActive": true,
  537.    "balance": "\$3,378.35",
  538.    "picture": "http://placehold.it/32x32"
  539.  },
  540.  {
  541.    "_id": "60a16cb18f8610b81cb7aa86",
  542.    "index": 63,
  543.    "guid": "13fbf98f-e37d-4cb5-854d-76dd881b18e7",
  544.    "isActive": true,
  545.    "balance": "\$1,974.12",
  546.    "picture": "http://placehold.it/32x32"
  547.  },
  548.  {
  549.    "_id": "60a16cb1f46ea845de8e2fe5",
  550.    "index": 64,
  551.    "guid": "7b4b9fb3-ed39-46bd-9d97-0b823ca7b6fa",
  552.    "isActive": true,
  553.    "balance": "\$3,254.18",
  554.    "picture": "http://placehold.it/32x32"
  555.  },
  556.  {
  557.    "_id": "60a16cb1b2c87d4ed054ca50",
  558.    "index": 65,
  559.    "guid": "da18ce4e-1df1-4bc3-9ef9-32097d085131",
  560.    "isActive": false,
  561.    "balance": "\$2,540.71",
  562.    "picture": "http://placehold.it/32x32"
  563.  },
  564.  {
  565.    "_id": "60a16cb15f2b79ac77cfe7f1",
  566.    "index": 66,
  567.    "guid": "3fef2761-0d76-44b0-856c-90201c22cd1e",
  568.    "isActive": false,
  569.    "balance": "\$2,307.36",
  570.    "picture": "http://placehold.it/32x32"
  571.  },
  572.  {
  573.    "_id": "60a16cb19fe0569e888a8d14",
  574.    "index": 67,
  575.    "guid": "d4427f2e-d029-43fb-b8ad-4061a9f74358",
  576.    "isActive": true,
  577.    "balance": "\$3,784.25",
  578.    "picture": "http://placehold.it/32x32"
  579.  },
  580.  {
  581.    "_id": "60a16cb1331ea2f2b69defc0",
  582.    "index": 68,
  583.    "guid": "aec1b9cc-bd8d-4b7a-9e0c-bab998a8efb1",
  584.    "isActive": true,
  585.    "balance": "\$2,057.26",
  586.    "picture": "http://placehold.it/32x32"
  587.  },
  588.  {
  589.    "_id": "60a16cb107cba63bf4e7eaf4",
  590.    "index": 69,
  591.    "guid": "ecbfb3ea-8383-4825-9809-a4253d6ccada",
  592.    "isActive": false,
  593.    "balance": "\$1,627.23",
  594.    "picture": "http://placehold.it/32x32"
  595.  },
  596.  {
  597.    "_id": "60a16cb120920cff9c61edbb",
  598.    "index": 70,
  599.    "guid": "4fe52eeb-16d9-48cd-ad21-efe40152dfef",
  600.    "isActive": true,
  601.    "balance": "\$3,605.30",
  602.    "picture": "http://placehold.it/32x32"
  603.  },
  604.  {
  605.    "_id": "60a16cb1bb3a1fc7a29ea98b",
  606.    "index": 71,
  607.    "guid": "be1e03e0-e01b-41fe-a4c5-977d92a9ed5c",
  608.    "isActive": true,
  609.    "balance": "\$2,192.96",
  610.    "picture": "http://placehold.it/32x32"
  611.  },
  612.  {
  613.    "_id": "60a16cb1b1846e2f4b6854a0",
  614.    "index": 72,
  615.    "guid": "cb1f7e99-e6f9-4b35-a774-515c99ce1297",
  616.    "isActive": true,
  617.    "balance": "\$2,283.59",
  618.    "picture": "http://placehold.it/32x32"
  619.  },
  620.  {
  621.    "_id": "60a16cb16de8834259f9d599",
  622.    "index": 73,
  623.    "guid": "dc3183dd-4ab3-402a-a93f-235351fbe69a",
  624.    "isActive": false,
  625.    "balance": "\$3,359.38",
  626.    "picture": "http://placehold.it/32x32"
  627.  },
  628.  {
  629.    "_id": "60a16cb130c794ff9687571d",
  630.    "index": 74,
  631.    "guid": "0fc7e553-21ef-416f-9cf2-3374e4c42ddf",
  632.    "isActive": true,
  633.    "balance": "\$1,565.30",
  634.    "picture": "http://placehold.it/32x32"
  635.  },
  636.  {
  637.    "_id": "60a16cb16e5e8377aa5fabe1",
  638.    "index": 75,
  639.    "guid": "316486ae-8066-4aa7-b61c-2b843278aaad",
  640.    "isActive": true,
  641.    "balance": "\$2,468.51",
  642.    "picture": "http://placehold.it/32x32"
  643.  },
  644.  {
  645.    "_id": "60a16cb1355c6d17330ae389",
  646.    "index": 76,
  647.    "guid": "808c5967-98be-4b58-b44b-515f002cb029",
  648.    "isActive": true,
  649.    "balance": "\$2,638.45",
  650.    "picture": "http://placehold.it/32x32"
  651.  },
  652.  {
  653.    "_id": "60a16cb17804136aacdc1d21",
  654.    "index": 77,
  655.    "guid": "a5c6900b-7959-464a-9e83-512613fd393c",
  656.    "isActive": false,
  657.    "balance": "\$3,344.44",
  658.    "picture": "http://placehold.it/32x32"
  659.  },
  660.  {
  661.    "_id": "60a16cb1553f03ef08eac9cd",
  662.    "index": 78,
  663.    "guid": "4eddb332-22b4-448c-9ada-3ef49ab3a85a",
  664.    "isActive": true,
  665.    "balance": "\$2,620.10",
  666.    "picture": "http://placehold.it/32x32"
  667.  },
  668.  {
  669.    "_id": "60a16cb1c3ad88354793f028",
  670.    "index": 79,
  671.    "guid": "f521fe6b-373d-4dc5-865d-8decaafab32b",
  672.    "isActive": true,
  673.    "balance": "\$2,863.96",
  674.    "picture": "http://placehold.it/32x32"
  675.  },
  676.  {
  677.    "_id": "60a16cb1482dbe909f7b6d44",
  678.    "index": 80,
  679.    "guid": "c1861cf2-f758-469e-83d7-9668015fd615",
  680.    "isActive": true,
  681.    "balance": "\$1,274.10",
  682.    "picture": "http://placehold.it/32x32"
  683.  },
  684.  {
  685.    "_id": "60a16cb1a4aa43a1f609cff7",
  686.    "index": 81,
  687.    "guid": "3efed868-e2cb-4269-bb56-281182aeb53b",
  688.    "isActive": false,
  689.    "balance": "\$2,929.17",
  690.    "picture": "http://placehold.it/32x32"
  691.  },
  692.  {
  693.    "_id": "60a16cb1f893ba2fa174bedc",
  694.    "index": 82,
  695.    "guid": "f3cc7243-8159-494f-9e7f-fbf79ad7613c",
  696.    "isActive": true,
  697.    "balance": "\$1,847.57",
  698.    "picture": "http://placehold.it/32x32"
  699.  },
  700.  {
  701.    "_id": "60a16cb1ec4dc58f6339fee5",
  702.    "index": 83,
  703.    "guid": "6f4bc76f-7abe-4593-975c-b76e9cb6ec3a",
  704.    "isActive": true,
  705.    "balance": "\$3,314.66",
  706.    "picture": "http://placehold.it/32x32"
  707.  },
  708.  {
  709.    "_id": "60a16cb18f3a0a4fb6f9c3b3",
  710.    "index": 84,
  711.    "guid": "eb5940e3-3e55-4a20-8bbb-a6e18cc586fa",
  712.    "isActive": false,
  713.    "balance": "\$2,791.02",
  714.    "picture": "http://placehold.it/32x32"
  715.  },
  716.  {
  717.    "_id": "60a16cb1742a949974e82998",
  718.    "index": 85,
  719.    "guid": "de7c5294-d90e-45dc-ae73-ec8819365882",
  720.    "isActive": true,
  721.    "balance": "\$2,514.48",
  722.    "picture": "http://placehold.it/32x32"
  723.  },
  724.  {
  725.    "_id": "60a16cb18fe67c98ddf6e64a",
  726.    "index": 86,
  727.    "guid": "bb413078-c7c6-4bfc-8a18-6ac9f0429e27",
  728.    "isActive": true,
  729.    "balance": "\$1,309.79",
  730.    "picture": "http://placehold.it/32x32"
  731.  },
  732.  {
  733.    "_id": "60a16cb1fefffc51ba5eba7f",
  734.    "index": 87,
  735.    "guid": "0fb98569-98c3-4967-9753-8705f7c9395c",
  736.    "isActive": true,
  737.    "balance": "\$1,618.91",
  738.    "picture": "http://placehold.it/32x32"
  739.  },
  740.  {
  741.    "_id": "60a16cb11abd26d02c751979",
  742.    "index": 88,
  743.    "guid": "dc08a227-16b3-4873-aef5-e160eb3a1d4e",
  744.    "isActive": true,
  745.    "balance": "\$1,106.96",
  746.    "picture": "http://placehold.it/32x32"
  747.  },
  748.  {
  749.    "_id": "60a16cb1323e18270ee4d0a4",
  750.    "index": 89,
  751.    "guid": "4c07002d-04d1-4869-a63d-d9c59b8a6a2f",
  752.    "isActive": true,
  753.    "balance": "\$1,095.13",
  754.    "picture": "http://placehold.it/32x32"
  755.  },
  756.  {
  757.    "_id": "60a16cb16a5d5c13aa9a58e9",
  758.    "index": 90,
  759.    "guid": "aea5e428-9307-452e-93e7-335c8dc97866",
  760.    "isActive": true,
  761.    "balance": "\$3,098.84",
  762.    "picture": "http://placehold.it/32x32"
  763.  },
  764.  {
  765.    "_id": "60a16cb13e46073d56a1d747",
  766.    "index": 91,
  767.    "guid": "90ec4ede-9538-4331-b67c-a83f89617d3f",
  768.    "isActive": false,
  769.    "balance": "\$1,130.92",
  770.    "picture": "http://placehold.it/32x32"
  771.  },
  772.  {
  773.    "_id": "60a16cb1c9b6f5a6ce78bff1",
  774.    "index": 92,
  775.    "guid": "8b737f90-e036-4ec5-85ac-5621c96fcd00",
  776.    "isActive": true,
  777.    "balance": "\$2,085.38",
  778.    "picture": "http://placehold.it/32x32"
  779.  },
  780.  {
  781.    "_id": "60a16cb1941df6a8274eac8a",
  782.    "index": 93,
  783.    "guid": "ff954482-9ec0-47f9-a828-12acb5f8dfac",
  784.    "isActive": true,
  785.    "balance": "\$1,141.40",
  786.    "picture": "http://placehold.it/32x32"
  787.  },
  788.  {
  789.    "_id": "60a16cb19749bd43e3b79ef4",
  790.    "index": 94,
  791.    "guid": "45425cf3-59da-485c-ad9d-5ab9d55d71e8",
  792.    "isActive": false,
  793.    "balance": "\$3,711.72",
  794.    "picture": "http://placehold.it/32x32"
  795.  },
  796.  {
  797.    "_id": "60a16cb1dc97ebeedc2fdc09",
  798.    "index": 95,
  799.    "guid": "fa5f16ce-3d8c-4c60-a3f2-a4f92738d416",
  800.    "isActive": true,
  801.    "balance": "\$2,872.31",
  802.    "picture": "http://placehold.it/32x32"
  803.  },
  804.  {
  805.    "_id": "60a16cb1bb8d11e018375bcc",
  806.    "index": 96,
  807.    "guid": "2e377091-e9b3-49fe-9d31-9f6274fd31d5",
  808.    "isActive": true,
  809.    "balance": "\$2,102.08",
  810.    "picture": "http://placehold.it/32x32"
  811.  },
  812.  {
  813.    "_id": "60a16cb102571ec2d7b72991",
  814.    "index": 97,
  815.    "guid": "f4318cbe-cfa7-463c-9d3b-d63729214be8",
  816.    "isActive": false,
  817.    "balance": "\$1,232.39",
  818.    "picture": "http://placehold.it/32x32"
  819.  },
  820.  {
  821.    "_id": "60a16cb1580f32dfeeda487e",
  822.    "index": 98,
  823.    "guid": "108d5d00-79b6-4f8d-b7b8-d5bab1d241ff",
  824.    "isActive": true,
  825.    "balance": "\$1,547.58",
  826.    "picture": "http://placehold.it/32x32"
  827.  },
  828.  {
  829.    "_id": "60a16cb1e7c9ff28ce9e5f75",
  830.    "index": 99,
  831.    "guid": "4de5e655-3f89-448c-b7b9-95dc81cc6aac",
  832.    "isActive": false,
  833.    "balance": "\$1,466.40",
  834.    "picture": "http://placehold.it/32x32"
  835.  }
  836. ]
  837.  
  838.  ''';
  839.  
  840.   @override
  841.   Widget build(BuildContext context) {
  842.     return Scaffold(
  843.       body: SafeArea(
  844.         child: LayoutBuilder(
  845.           builder: (context, constraints) {
  846.             return CustomScrollView(
  847.               slivers: [
  848.                 SliverAppBar(
  849.                   elevation: 0,
  850.                   backgroundColor: Colors.transparent,
  851.                   expandedHeight: 300,
  852.                   pinned: true,
  853.                   flexibleSpace: FlexibleSpaceBar(
  854.                     titlePadding: EdgeInsets.symmetric(vertical: 4),
  855.                     title: ConstrainedBox(
  856.                       constraints:
  857.                           BoxConstraints(maxWidth: constraints.maxWidth * 0.5),
  858.                       child: Hero(
  859.                         tag: "extension-logo-1",
  860.                         child: Image.network(
  861.                             'https://media.graphiline.com/src/images/news/articles/ima-graphiste-youtube-26441.jpg'),
  862.                       ),
  863.                     ),
  864.                     background: Align(
  865.                       alignment: Alignment.topCenter,
  866.                       child: Hero(
  867.                         tag: "extension-spotlight-1",
  868.                         child: Image.network(
  869.                             'https://velseoity.com/wp-content/uploads/2019/09/online-942408_960_720-696x492.jpg'),
  870.                       ),
  871.                     ),
  872.                   ),
  873.                 ),
  874.                 SliverPadding(
  875.                   padding: EdgeInsets.symmetric(horizontal: 16.0),
  876.                   sliver: SliverList(
  877.                     delegate: SliverChildListDelegate([
  878.                       ElevatedButton(
  879.                         onPressed: loadData,
  880.                         child: Text('Load data'),
  881.                       ),
  882.                       SizedBox(height: 16),
  883.                       ValueListenableBuilder(
  884.                         valueListenable: _list,
  885.                         builder: (context, value, child) {
  886.                           return _buildListGrid(value);
  887.                         },
  888.                       ),
  889.                     ]),
  890.                   ),
  891.                 )
  892.               ],
  893.             );
  894.           },
  895.         ),
  896.       ),
  897.     );
  898.   }
  899.  
  900.   loadData() async {
  901.     _list.value = await json.decode(_fakeData);
  902.   }
  903.  
  904.   _buildListGrid(list) {
  905.     if (list.length == 0) {
  906.       return Text('No items');
  907.     }
  908.  
  909.     return GridView.builder(
  910.       shrinkWrap: true,
  911.       physics: ScrollPhysics(),
  912.       itemCount: list.length,
  913.       gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
  914.         crossAxisCount: 3,
  915.         mainAxisSpacing: 16.0,
  916.         crossAxisSpacing: 16.0,
  917.         childAspectRatio: 635 / 889,
  918.       ),
  919.       itemBuilder: (context, index) {
  920.         return _buildItem(list[index]);
  921.       },
  922.     );
  923.   }
  924.  
  925.   Widget _buildItem(item) {
  926.     print('item built');
  927.     return Container(
  928.       decoration: BoxDecoration(
  929.         border: Border.all(color: Colors.blue),
  930.         borderRadius: BorderRadius.circular(12.0),
  931.       ),
  932.       child: Center(
  933.         child: Column(
  934.           mainAxisAlignment: MainAxisAlignment.center,
  935.           children: [
  936.             Text(item['index'].toString()),
  937.             Text(item['balance'].toString())
  938.           ],
  939.         ),
  940.       ),
  941.     );
  942.   }
  943. }
  944.  
Advertisement
Add Comment
Please, Sign In to add comment