adplus-dvertising

How to get the first value of (bool, Map<String, dynamic>)

Asked 6 months ago
Viewed 69 times

Can someone help me to figure out, how to get the uid from my table?

When the user selects a row, then onSelect: onSelected is getting used.

This returns the selected row and the values (as example: true {uid: 1xorAjA7hRZfOdN3zpkAWI7spgp1, username: awdwa,...} - true means the row is selected, false the row is not selected)

Now I want to get the uid, so the first value of the Map<String, dynamic>.

My first step is to store all data in a variable: var selectedUid = userTable.onSelected, and then I need to get access to the Map<String, dynamic> to get the uid right?

But how can I get acess to the first value of Map<String, dynamic> when I have a (bool, Map <String, dynamic>)? Someone have an advice how I can do this?

Sorry, when this is a dumb question, but the (bool, Map <String, dynamic>) confuses me completly. Thank you a lot for your help.

code onSelected from table:

  List<Map<String, dynamic>> selecteds = [];

onSelected(bool value, Map <String, dynamic> item){
    print("$value  $item ");
    if (value) {
      selecteds.add(item);
    } else {
      selecteds.removeAt(selecteds.indexOf(item));
    }
    notifyListeners();
  }

Edit:

When I try to get the uid from the bool, Map<String, Dynamic> like this:

selectedId = userTable.getSelected,
print('Uid: '+selectedId[uid])

I get this error:

The following NoSuchMethodError was thrown while handling a gesture:
'[]'
Dynamic call of null.
Receiver: Instance of '(bool, Map<String, String>) => dynamic'
Arguments: ["M0glOQKUwagZJGOyzVEU1JJgQo23"]

When I try to safe the data in List<Map<String, dynamic>> and just try to get the first value, then I get the error:

Expected a value of type 'List<Map<String, dynamic>>', but got one of type '(bool, Map<String, dynamic>) => List<Map<String, dynamic>>'

code:

getSelected(bool value, Map <String, dynamic> item){
    print("$value  $item ");
    if (value) {
      selecteds.add(item);
      return selecteds as List<Map<String, dynamic>>;
    } else {
      selecteds.removeAt(selecteds.indexOf(item));
    }
    notifyListeners();
  }

asked 6 months ago

Correct Answer

Maps are not ordered. There is no "first" item. You probably meant to ask how to get the "uid" from the map?

You can use item["uid"].

answered 6 months ago