import 'package:get/get.dart'; extension ListExtension on List { bool addOrSet(int index, T value) { if (length == index) { add(value); return true; } else if (length > index) { this[index] = value; return true; } return false; } T getWithSetCallback(int index, T Function() callback) { if (length > index) { return this[index]; } else { var data = callback(); addOrSet(index, data); return data; } } } extension RxListExtension on RxList { bool addOrSet(int index, T value) { if (length == index) { add(value); return true; } else if (length > index) { this[index] = value; return true; } return false; } T getWithSetCallback(int index, T Function() callback) { if (length > index) { return this[index]; } else { var data = callback(); addOrSet(index, data); return data; } } }