You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
48 lines
963 B
Dart
48 lines
963 B
Dart
2 years ago
|
import 'package:get/get.dart';
|
||
|
|
||
|
extension ListExtension<T> on List<T> {
|
||
|
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<T> on RxList<T> {
|
||
|
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;
|
||
|
}
|
||
|
}
|
||
|
}
|