How to filter and remove duplicate JSON List?












1















I have a local JSON file as shown below and I load it into my flutter project using "await rootBundle.loadString(****)". I decoded to map as "Map _mapCompany = jsonDecode(jsonComapany)" than later assign map to list as "_tmpCompany = _mapComapany["companyBranch"];"



Now I need to use filter to get [companyName] and also I need to remove duplicate [companyName] and load to dropdown button.



I use var "_result = new Collection(_tmpCompany).distinct()" to remove duplicate but how can I assign _result.toList() to List _comapnyName; or to dropdown button?



Once the first dropdown loads I use on change event to load branch list using filter. How can I do that?



{  
“companyBranch”:[
{
"companyCode":"1",
"companyName”:”COMAPANY A”,
"branchCode”:”855”,
"branchName”:”BRANCH A1”
},
{
"companyCode":"1",
"companyName”:”COMPANY A”,
"branchCode":"856",
"branchName”:”BRANCH A2“
},
{
"companyCode":"10",
"companyName”:”COMAPNY B”,
"branchCode":"860",
"branchName”:”BRANCH B1”
},
{
"companyCode":"10",
"companyName”:”COMPANY B”,
"branchCode":"861",
"branchName”:”BRANCH B2”
},









share|improve this question



























    1















    I have a local JSON file as shown below and I load it into my flutter project using "await rootBundle.loadString(****)". I decoded to map as "Map _mapCompany = jsonDecode(jsonComapany)" than later assign map to list as "_tmpCompany = _mapComapany["companyBranch"];"



    Now I need to use filter to get [companyName] and also I need to remove duplicate [companyName] and load to dropdown button.



    I use var "_result = new Collection(_tmpCompany).distinct()" to remove duplicate but how can I assign _result.toList() to List _comapnyName; or to dropdown button?



    Once the first dropdown loads I use on change event to load branch list using filter. How can I do that?



    {  
    “companyBranch”:[
    {
    "companyCode":"1",
    "companyName”:”COMAPANY A”,
    "branchCode”:”855”,
    "branchName”:”BRANCH A1”
    },
    {
    "companyCode":"1",
    "companyName”:”COMPANY A”,
    "branchCode":"856",
    "branchName”:”BRANCH A2“
    },
    {
    "companyCode":"10",
    "companyName”:”COMAPNY B”,
    "branchCode":"860",
    "branchName”:”BRANCH B1”
    },
    {
    "companyCode":"10",
    "companyName”:”COMPANY B”,
    "branchCode":"861",
    "branchName”:”BRANCH B2”
    },









    share|improve this question

























      1












      1








      1








      I have a local JSON file as shown below and I load it into my flutter project using "await rootBundle.loadString(****)". I decoded to map as "Map _mapCompany = jsonDecode(jsonComapany)" than later assign map to list as "_tmpCompany = _mapComapany["companyBranch"];"



      Now I need to use filter to get [companyName] and also I need to remove duplicate [companyName] and load to dropdown button.



      I use var "_result = new Collection(_tmpCompany).distinct()" to remove duplicate but how can I assign _result.toList() to List _comapnyName; or to dropdown button?



      Once the first dropdown loads I use on change event to load branch list using filter. How can I do that?



      {  
      “companyBranch”:[
      {
      "companyCode":"1",
      "companyName”:”COMAPANY A”,
      "branchCode”:”855”,
      "branchName”:”BRANCH A1”
      },
      {
      "companyCode":"1",
      "companyName”:”COMPANY A”,
      "branchCode":"856",
      "branchName”:”BRANCH A2“
      },
      {
      "companyCode":"10",
      "companyName”:”COMAPNY B”,
      "branchCode":"860",
      "branchName”:”BRANCH B1”
      },
      {
      "companyCode":"10",
      "companyName”:”COMPANY B”,
      "branchCode":"861",
      "branchName”:”BRANCH B2”
      },









      share|improve this question














      I have a local JSON file as shown below and I load it into my flutter project using "await rootBundle.loadString(****)". I decoded to map as "Map _mapCompany = jsonDecode(jsonComapany)" than later assign map to list as "_tmpCompany = _mapComapany["companyBranch"];"



      Now I need to use filter to get [companyName] and also I need to remove duplicate [companyName] and load to dropdown button.



      I use var "_result = new Collection(_tmpCompany).distinct()" to remove duplicate but how can I assign _result.toList() to List _comapnyName; or to dropdown button?



      Once the first dropdown loads I use on change event to load branch list using filter. How can I do that?



      {  
      “companyBranch”:[
      {
      "companyCode":"1",
      "companyName”:”COMAPANY A”,
      "branchCode”:”855”,
      "branchName”:”BRANCH A1”
      },
      {
      "companyCode":"1",
      "companyName”:”COMPANY A”,
      "branchCode":"856",
      "branchName”:”BRANCH A2“
      },
      {
      "companyCode":"10",
      "companyName”:”COMAPNY B”,
      "branchCode":"860",
      "branchName”:”BRANCH B1”
      },
      {
      "companyCode":"10",
      "companyName”:”COMPANY B”,
      "branchCode":"861",
      "branchName”:”BRANCH B2”
      },






      list filter dart flutter dropdown






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 22 '18 at 14:33









      NickNick

      33712




      33712
























          1 Answer
          1






          active

          oldest

          votes


















          2














          This should do what you want



          var uniqueCompanyNames = _tmpCompany.map<String>(
          (c) => (c as List)['companyName'] as String)
          .toSet().toList()





          share|improve this answer
























          • how to assign uniqueCompanyNames to dropdown I am getting error

            – Nick
            Nov 22 '18 at 14:51











          • What's the error? Please add the code to your question that causes this error.

            – Günter Zöchbauer
            Nov 22 '18 at 14:54






          • 2





            thanks, I forget to add .toList(), end of it...

            – Nick
            Nov 22 '18 at 14:57











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53433186%2fhow-to-filter-and-remove-duplicate-json-list%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          2














          This should do what you want



          var uniqueCompanyNames = _tmpCompany.map<String>(
          (c) => (c as List)['companyName'] as String)
          .toSet().toList()





          share|improve this answer
























          • how to assign uniqueCompanyNames to dropdown I am getting error

            – Nick
            Nov 22 '18 at 14:51











          • What's the error? Please add the code to your question that causes this error.

            – Günter Zöchbauer
            Nov 22 '18 at 14:54






          • 2





            thanks, I forget to add .toList(), end of it...

            – Nick
            Nov 22 '18 at 14:57
















          2














          This should do what you want



          var uniqueCompanyNames = _tmpCompany.map<String>(
          (c) => (c as List)['companyName'] as String)
          .toSet().toList()





          share|improve this answer
























          • how to assign uniqueCompanyNames to dropdown I am getting error

            – Nick
            Nov 22 '18 at 14:51











          • What's the error? Please add the code to your question that causes this error.

            – Günter Zöchbauer
            Nov 22 '18 at 14:54






          • 2





            thanks, I forget to add .toList(), end of it...

            – Nick
            Nov 22 '18 at 14:57














          2












          2








          2







          This should do what you want



          var uniqueCompanyNames = _tmpCompany.map<String>(
          (c) => (c as List)['companyName'] as String)
          .toSet().toList()





          share|improve this answer













          This should do what you want



          var uniqueCompanyNames = _tmpCompany.map<String>(
          (c) => (c as List)['companyName'] as String)
          .toSet().toList()






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 22 '18 at 14:35









          Günter ZöchbauerGünter Zöchbauer

          321k68957892




          321k68957892













          • how to assign uniqueCompanyNames to dropdown I am getting error

            – Nick
            Nov 22 '18 at 14:51











          • What's the error? Please add the code to your question that causes this error.

            – Günter Zöchbauer
            Nov 22 '18 at 14:54






          • 2





            thanks, I forget to add .toList(), end of it...

            – Nick
            Nov 22 '18 at 14:57



















          • how to assign uniqueCompanyNames to dropdown I am getting error

            – Nick
            Nov 22 '18 at 14:51











          • What's the error? Please add the code to your question that causes this error.

            – Günter Zöchbauer
            Nov 22 '18 at 14:54






          • 2





            thanks, I forget to add .toList(), end of it...

            – Nick
            Nov 22 '18 at 14:57

















          how to assign uniqueCompanyNames to dropdown I am getting error

          – Nick
          Nov 22 '18 at 14:51





          how to assign uniqueCompanyNames to dropdown I am getting error

          – Nick
          Nov 22 '18 at 14:51













          What's the error? Please add the code to your question that causes this error.

          – Günter Zöchbauer
          Nov 22 '18 at 14:54





          What's the error? Please add the code to your question that causes this error.

          – Günter Zöchbauer
          Nov 22 '18 at 14:54




          2




          2





          thanks, I forget to add .toList(), end of it...

          – Nick
          Nov 22 '18 at 14:57





          thanks, I forget to add .toList(), end of it...

          – Nick
          Nov 22 '18 at 14:57


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53433186%2fhow-to-filter-and-remove-duplicate-json-list%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Costa Masnaga

          Fotorealismo

          Sidney Franklin