Skip to content

Commit 0d0d658

Browse files
author
Jens Becker
committed
Add Gap widget
1 parent ab0cbf7 commit 0d0d658

File tree

3 files changed

+88
-0
lines changed

3 files changed

+88
-0
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,8 @@ All features with links to their page in the documentation:
196196
197197
198198
- ### Flutter Widgets:
199+
- #### [Gap](https://pub.dev/documentation/fleasy/latest/fleasy/Gap-class.html)
200+
A wrapper around `SizedBox` for making consistent gaps. Example: Instead of `SizedBox(width: 4.0)` you can just write `Gap.w4()`.
199201
- #### [EasyFutureBuilder<T>](https://pub.dev/documentation/fleasy/latest/fleasy/EasyFutureBuilder-class.html)
200202
A wrapper around `FutureBuilder` which makes it easy to display the various states of fetching data from the given `Future`. See [example](https://github.com/devj3ns/fleasy/blob/main/example/lib/main.dart).
201203
- #### [EasyStreamBuilder<T>](https://pub.dev/documentation/fleasy/latest/fleasy/EasyStreamBuilder-class.html)

lib/src/widgets/gap.dart

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
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+
}

lib/src/widgets/widgets.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
export 'easy_future_builder.dart';
22
export 'easy_stream_builder.dart';
3+
export 'gap.dart';
34
export 'snapshot_state_info.dart';

0 commit comments

Comments
 (0)