Created
November 24, 2020 21:45
-
-
Save samuelematias/61b839ffa80d840301aaebfa2ac6e5fa to your computer and use it in GitHub Desktop.
Padding Extensions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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