Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Padding Extensions
import 'package:flutter/material.dart';
extension PaddingExtensions on Widget {
Widget horizontalListPadding({
@required int index,
@required int listLength,
double spacingFirstItem = 16,
double spacingLastItem = 16,
double spaceBetweenItems = 16,
}) {
final bool isFirstItem = index == 0;
final bool isLastItem = index + 1 == listLength;
return Padding(
padding: EdgeInsets.only(
left: isFirstItem ? spacingFirstItem : 0.0,
right: isLastItem ? spacingLastItem : spaceBetweenItems,
),
child: this,
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment