Home > front end >  How to get key values from Html in Flutter?
How to get key values from Html in Flutter?

Time:08-01

I have the following html string. how to decode this and get key values

<html>
   <head></head>
   <body>order_id=1289&tracking_id=111028965908&bank_ref_no=916831&order_status="
      "Success&failure_message=&payment_mode=Credit Card&card_name=MasterCard&status_code=00&"
      "status_message=Approved¤cy=AED&amount=140.0&billing_name=Gx&billing_address=Yd&billing_city=Ud&"
      "billing_state=&billing_zip=Uf&billing_country=Andorra&billing_tel=4&[email protected]&"
      "delivery_name=Gx&delivery_address=Yd&delivery_city=Ud&delivery_state=&delivery_zip=Uf&"
      "delivery_country=Andorra&delivery_tel=4&merchant_param1=&merchant_param2=&merchant_param3="
      "&merchant_param4=&merchant_param5=&vault=N&offer_type=null&offer_code=null&discount_value=0.0&"
      "mer_amount=140.0&eci_value=05&card_holder_name=&bank_qsi_no=51000002968&bank_receipt_no=221315916831&"
      "merchant_param6=5123450008
   </body>
</html>

CodePudding user response:

You can also use this code if you don't want to use plugin to get key-value data

  • Assign a keyValueMap globally if you want to use it anywhere else

    String html = '<html><head></head><body>order_id=1289&tracking_id=111028965908&bank_ref_no=916831&order_status=Success&failure_message=&payment_mode=Credit Card&card_name=MasterCard&status_code=00&"status_message=Approved¤cy=AED&amount=140.0&billing_name=Gx&billing_address=Yd&billing_city=Ud&billing_state=&billing_zip=Uf&billing_country=Andorra&billing_tel=4&[email protected]&delivery_name=Gx&delivery_address=Yd&delivery_city=Ud&delivery_state=&delivery_zip=Uf&delivery_country=Andorra&delivery_tel=4&merchant_param1=&merchant_param2=&merchant_param3= &merchant_param4=&merchant_param5=&vault=N&offer_type=null&offer_code=null&discount_value=0.0&mer_amount=140.0&eci_value=05&card_holder_name=&bank_qsi_no=51000002968&bank_receipt_no=221315916831&merchant_param6=5123450008</body></html>';
    
    
    onTap: () {
    String temp;
    const start = "<body>";
    const end = "</body>";
    Map<String, dynamic> keyValueMap = {};
    if (html.contains(start)) {
      final startIndex = html.indexOf(start);
      final endIndex = html.indexOf(end, startIndex   start.length);
      temp = html.substring(startIndex   start.length, endIndex);
      List splitText = temp.split("&");
      for (var element in splitText) {
        element.runtimeType;
        if (element.contains('=')) {
          keyValueMap[element.split("=")[0] ?? ""] = element.split("=")[1] ?? "";
         }     
        }
      ///You'll get all key value in [keyValueMap]
      }
    },
    

CodePudding user response:

Use some Html decode plugins. Please go to pub.dev and search flutter_widget_from_html_core, flutter_widget_from_html, html_editor_enhanced, so many plugins there in pub.dev.

  • Related