placeComponent function
order with type taken out and put back just before before or just
after after — at the end when neither is found. Pinned types stay
first, as they were.
Implementation
List<Type> placeComponent(
List<Type> order,
Type type, {
Type? before,
Type? after,
}) {
final rest = [
for (final t in order)
if (t != type) t,
];
var at = before != null
? rest.indexOf(before)
: after != null
? rest.indexOf(after) + 1
: -1;
if (at < 0 || (after != null && at == 0)) at = rest.length;
rest.insert(at, type);
return [
for (final t in rest)
if (isPinnedComponent(t)) t,
for (final t in rest)
if (!isPinnedComponent(t)) t,
];
}