Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A dart extension on a list of flutter widgets so that it can add padding between each one.
import 'package:collection/collection.dart';
import 'package:flutter/material.dart';
extension WidgetListSpacing on List<Widget> {
List<Widget> withSizedBoxBetween({double? width, double? height}) {
final box = SizedBox(width: width, height: height);
return mapIndexed((index, widget) => index == 0 || index == length ? [widget] : [box, widget]).flattened.toList();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment