0

I have an List like this

List<MapEntry> _list = [
    MapEntry('a': []), 
    MapEntry('b': [Instance, Instance]), 
    MapEntry('c': [Instance]), 
    MapEntry('d': []), 
    MapEntry('e': [Instance, Instance]),
    MapEntry('f': []),
]

I need to make the

List<MapEntry> = [
        MapEntry('b': [Instance, Instance]), 
        MapEntry('c': [Instance]),
        MapEntry('e': [Instance, Instance]),
]

i was keep trying to use map methods but wasn't able to remove empty arrays inside the MapEntries value

what should I have to try?

1
  • try removeWhere Commented Sep 29, 2022 at 1:46

1 Answer 1

1

how about this:

void main() {
  List<MapEntry> _list = [
    MapEntry('a', []),
    MapEntry('b', ['Instance', 'Instance']),
    MapEntry('c', ['Instance']),
    MapEntry('d', []),
    MapEntry('e', ['Instance', 'Instance']),
    MapEntry('f', [])
  ];
  
  final ist = _list.where((e)=>(e.value as List).length>0).toList();
  
  print(ist);
// result:
// [MapEntry(b: [Instance, Instance]), MapEntry(c: [Instance]), MapEntry(e: [Instance, Instance])]
}
Sign up to request clarification or add additional context in comments.

Comments

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.