Skip to content

Commit 45afcb5

Browse files
committed
✨ Introduce Gap and SliverGap
1 parent 7522bb2 commit 45afcb5

File tree

2 files changed

+76
-0
lines changed

2 files changed

+76
-0
lines changed

lib/src/constants/constants.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export '../widget/builder/fade_image_builder.dart';
2828
export '../widget/builder/image_page_builder.dart';
2929
export '../widget/builder/video_page_builder.dart';
3030
export '../widget/fixed_appbar.dart';
31+
export '../widget/gaps.dart';
3132
export '../widget/platform_progress_indicator.dart';
3233

3334
export 'colors.dart';

lib/src/widget/gaps.dart

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
///
2+
/// [Author] Alex (https://github.com/AlexV525)
3+
/// [Date] 2020/10/27 17:14
4+
///
5+
import 'package:flutter/material.dart';
6+
7+
class Gap extends StatelessWidget {
8+
const Gap.h(
9+
double width, {
10+
Key? key,
11+
double? height,
12+
this.color,
13+
}) : _width = width,
14+
_height = height,
15+
super(key: key);
16+
17+
const Gap.v(
18+
double height, {
19+
Key? key,
20+
double? width,
21+
this.color,
22+
}) : _width = width,
23+
_height = height,
24+
super(key: key);
25+
26+
final double? _width;
27+
final double? _height;
28+
final Color? color;
29+
30+
@override
31+
Widget build(BuildContext context) {
32+
Widget _w = SizedBox(width: _width, height: _height);
33+
if (color != null) {
34+
_w = ColoredBox(color: color!, child: _w);
35+
}
36+
return _w;
37+
}
38+
}
39+
40+
class SliverGap extends StatelessWidget {
41+
const SliverGap.h(
42+
double width, {
43+
Key? key,
44+
double? height,
45+
this.color,
46+
}) : _width = width,
47+
_height = height,
48+
super(key: key);
49+
50+
const SliverGap.v(
51+
double height, {
52+
Key? key,
53+
double? width,
54+
this.color,
55+
}) : _width = width,
56+
_height = height,
57+
super(key: key);
58+
59+
final double? _width;
60+
final double? _height;
61+
final Color? color;
62+
63+
@override
64+
Widget build(BuildContext context) {
65+
Widget child;
66+
if (_width != null) {
67+
child = Gap.h(_width!, height: _height, color: color);
68+
} else if (_height != null) {
69+
child = Gap.v(_height!, width: _width, color: color);
70+
} else {
71+
child = const SizedBox.shrink();
72+
}
73+
return SliverToBoxAdapter(child: child);
74+
}
75+
}

0 commit comments

Comments
 (0)