Skip to content

Instantly share code, notes, and snippets.

@giuliano-macedo
Created December 18, 2022 15:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save giuliano-macedo/a55030f7307c19d85e656059be39b6a4 to your computer and use it in GitHub Desktop.
Save giuliano-macedo/a55030f7307c19d85e656059be39b6a4 to your computer and use it in GitHub Desktop.
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