|
| 1 | +import 'package:flutter/material.dart'; |
| 2 | + |
| 3 | +/// A wrapper around SizedBox for making consistent gaps. |
| 4 | +/// |
| 5 | +/// By using [Gap] instead of [SizedBox] you have to write less code and your UI |
| 6 | +/// looks more consistent because you have a strict set of values to choose from. |
| 7 | +/// |
| 8 | +/// Examples: |
| 9 | +/// Gap.w4() = SizedBox(width: 4.0) |
| 10 | +/// Gap.h8() = SizedBox(height: 8.0) |
| 11 | +class Gap extends StatelessWidget { |
| 12 | + const Gap._({Key? key, required this.width, required this.height}) |
| 13 | + : super(key: key); |
| 14 | + |
| 15 | + /// A gap with a width of 2 |
| 16 | + const Gap.w2({Key? key}) |
| 17 | + : width = 2, |
| 18 | + height = 0, |
| 19 | + super(key: key); |
| 20 | + |
| 21 | + /// A gap with a width of 4 |
| 22 | + const Gap.w4({Key? key}) |
| 23 | + : width = 4, |
| 24 | + height = 0, |
| 25 | + super(key: key); |
| 26 | + |
| 27 | + /// A gap with a width of 8 |
| 28 | + const Gap.w8({Key? key}) |
| 29 | + : width = 8, |
| 30 | + height = 0, |
| 31 | + super(key: key); |
| 32 | + |
| 33 | + /// A gap with a width of 12 |
| 34 | + const Gap.w12({Key? key}) |
| 35 | + : width = 12, |
| 36 | + height = 0, |
| 37 | + super(key: key); |
| 38 | + |
| 39 | + /// A gap with a width of 16 |
| 40 | + const Gap.w16({Key? key}) |
| 41 | + : width = 16, |
| 42 | + height = 0, |
| 43 | + super(key: key); |
| 44 | + |
| 45 | + /// A gap with a height of 2 |
| 46 | + const Gap.h2({Key? key}) |
| 47 | + : width = 0, |
| 48 | + height = 2, |
| 49 | + super(key: key); |
| 50 | + |
| 51 | + /// A gap with a height of 4 |
| 52 | + const Gap.h4({Key? key}) |
| 53 | + : width = 0, |
| 54 | + height = 4, |
| 55 | + super(key: key); |
| 56 | + |
| 57 | + /// A gap with a height of 8 |
| 58 | + const Gap.h8({Key? key}) |
| 59 | + : width = 0, |
| 60 | + height = 8, |
| 61 | + super(key: key); |
| 62 | + |
| 63 | + /// A gap with a height of 12 |
| 64 | + const Gap.h12({Key? key}) |
| 65 | + : width = 0, |
| 66 | + height = 12, |
| 67 | + super(key: key); |
| 68 | + |
| 69 | + /// A gap with a height of 16 |
| 70 | + const Gap.h16({Key? key}) |
| 71 | + : width = 0, |
| 72 | + height = 16, |
| 73 | + super(key: key); |
| 74 | + |
| 75 | + final double width; |
| 76 | + final double height; |
| 77 | + |
| 78 | + @override |
| 79 | + Widget build(BuildContext context) { |
| 80 | + return SizedBox( |
| 81 | + height: height, |
| 82 | + width: width, |
| 83 | + ); |
| 84 | + } |
| 85 | +} |
0 commit comments