1

so im using sql_conn dependency on my flutter project to connect database to my flutter project.

im following the example in the flutter package site and using this method

  var res = "";
  Future<void> cetak(String query) async {
    var req = await SqlConn.readData(query);
    setState(() {
      res = req;
    });
  }

the problem is, res is showing an Stringlike this

[{"CUST_NAME" : "MY NAME"}]

and i just want to show MY NAME later in Text() widget.

How do i parse res so i can get only MY NAME Value

2 Answers 2

3

try this, and read more here

import 'dart:convert';
var res = "";
  Future<void> cetak(String query) async {
    var req = await SqlConn.readData(query);
    var parsedJson = jsonDecode(req);
    setState(() {
      res = parsedJson[0]['CUST_NAME'];
    });
  }
Sign up to request clarification or add additional context in comments.

Comments

0

Try this once

  var res = "";
  Future<void> cetak(String query) async {
    var req = await SqlConn.readData(query);
    setState(() {
      res =req[0]["CUST_NAME"];
    });
  }

Please try this let me know if it works for you if you need more modification then pls provide me with your print(req) so I can get more ideas and prepare as you want

1 Comment

i have triend this, but its not working, because [{"CUST_NAME" : "MY NAME"}] , Its not an array.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.