Skip to content

Commit 231e538

Browse files
Merge pull request #29 from solid-software/feature/overlay
fix #8
2 parents 44d9d97 + a132d40 commit 231e538

File tree

6 files changed

+103
-29
lines changed

6 files changed

+103
-29
lines changed

example/lib/storybook/stories/help_widget_story.dart

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,61 @@ import 'package:widgetbook/widgetbook.dart';
44

55
final _backgroundColor = Colors.grey.withOpacity(0.5);
66

7+
/// Test height.
8+
const testHeight = 420.0;
9+
10+
/// Test width
11+
const testWidth = 420.0;
12+
13+
const _listLength = 100;
14+
715
/// Definition of using 4 different widget inherited from [HelpWidget].
816
WidgetbookComponent get helpWidgetStory => WidgetbookComponent(
917
name: 'HelpWidget',
1018
useCases: [
1119
WidgetbookUseCase(
1220
name: 'First',
1321
builder: (context) {
22+
final alignmentX = context.knobs.slider(
23+
label: 'Alignment on x Axis',
24+
initialValue: -1,
25+
min: -1,
26+
max: 1,
27+
);
28+
29+
final alignmentY = context.knobs.slider(
30+
label: 'Alignment on y Axis',
31+
initialValue: -1,
32+
min: -1,
33+
max: 1,
34+
);
35+
36+
final _alignment = Alignment(alignmentX, alignmentY);
37+
1438
return Container(
1539
alignment: Alignment.center,
1640
color: _backgroundColor,
17-
child: HorizontalHelpWidget(),
41+
child: CardRounded(
42+
padding: EdgeInsets.zero,
43+
backgroundColor: Colors.black,
44+
height: testHeight,
45+
width: testWidth,
46+
child: OverlayWidget(
47+
alignment: _alignment,
48+
overlayWidget: HorizontalHelpWidget(),
49+
child: ListView(
50+
children: List.generate(
51+
_listLength,
52+
(i) => Text(
53+
i.toString(),
54+
style: const TextStyle(
55+
color: Colors.white,
56+
),
57+
),
58+
),
59+
),
60+
),
61+
),
1862
);
1963
},
2064
),

lib/src/components/card_rounded/card_rounded.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class CardRounded extends StatelessWidget {
5050
this.width,
5151
this.onClose,
5252
this.closeButtonIcon,
53-
this.closeButtonAlignment = const Alignment(1, -1.05),
53+
this.closeButtonAlignment = const Alignment(1.04, -1.05),
5454
this.padding = const EdgeInsets.symmetric(
5555
vertical: 10,
5656
horizontal: 10,

lib/src/widgets/help_collection/horizontal_help_widget.dart

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,14 @@ class HorizontalHelpWidget extends StatelessWidget {
2828
Widget build(BuildContext context) {
2929
return HelpWidget(
3030
controller: _controller,
31-
optionsView: CardRounded(
32-
padding: const EdgeInsets.only(right: 3, left: 3, bottom: 12, top: 6),
33-
child: LinksCardWidget(
34-
options: defaultOptionsList,
35-
onClose: _controller.goBack,
31+
optionsView: Container(
32+
constraints: const BoxConstraints.tightFor(width: 340),
33+
child: CardRounded(
34+
padding: const EdgeInsets.only(right: 3, left: 3, bottom: 12, top: 6),
35+
child: LinksCardWidget(
36+
options: defaultOptionsList,
37+
onClose: _controller.goBack,
38+
),
3639
),
3740
),
3841
mainView: CardRounded(
@@ -77,7 +80,6 @@ class HorizontalHelpWidget extends StatelessWidget {
7780
onTap: _controller.goForward,
7881
child: const FlagCard(),
7982
),
80-
constraints: const BoxConstraints.tightFor(width: 366),
8183
);
8284
}
8385
}

lib/src/widgets/help_widget/help_widget.dart

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@ class HelpWidget extends StatelessWidget {
2424

2525
final TraverseController<HelpWidgetView> _controller;
2626

27-
/// It's a parameter that defines the allowed size of the widget.
28-
final BoxConstraints? constraints;
29-
3027
///Constructor
3128
const HelpWidget({
3229
Key? key,
@@ -35,7 +32,6 @@ class HelpWidget extends StatelessWidget {
3532
required this.mainView,
3633
required TraverseController<HelpWidgetView> controller,
3734
this.axis = Axis.vertical,
38-
this.constraints,
3935
}) : _controller = controller,
4036
super(key: key);
4137

@@ -47,23 +43,20 @@ class HelpWidget extends StatelessWidget {
4743
HelpWidgetView.options: optionsView,
4844
};
4945

50-
return Container(
51-
constraints: constraints,
52-
child: AnimatedBuilder(
53-
animation: _controller,
54-
builder: (context, _) {
55-
final view = _controller.currentItem;
56-
57-
return AnimatedViewTransition(
58-
axis: axis,
59-
transitionForward: _controller.didTraverseForward,
60-
child: SizedBox(
61-
key: ValueKey(view),
62-
child: viewMap[view],
63-
),
64-
);
65-
},
66-
),
46+
return AnimatedBuilder(
47+
animation: _controller,
48+
builder: (context, _) {
49+
final view = _controller.currentItem;
50+
51+
return AnimatedViewTransition(
52+
axis: axis,
53+
transitionForward: _controller.didTraverseForward,
54+
child: SizedBox(
55+
key: ValueKey(view),
56+
child: viewMap[view],
57+
),
58+
);
59+
},
6760
);
6861
}
6962
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import 'package:flutter/material.dart';
2+
3+
/// [OverlayWidget] need to drop in the widget to predefined location on screen.
4+
class OverlayWidget extends StatelessWidget {
5+
/// Child widget.
6+
final Widget child;
7+
8+
/// Overlay widget.
9+
final Widget overlayWidget;
10+
11+
/// Alignment.
12+
final Alignment alignment;
13+
14+
/// Constructor.
15+
const OverlayWidget({
16+
Key? key,
17+
required this.child,
18+
required this.overlayWidget,
19+
required this.alignment,
20+
}) : super(key: key);
21+
22+
@override
23+
Widget build(BuildContext context) {
24+
return Stack(
25+
children: [
26+
child,
27+
Align(
28+
alignment: alignment,
29+
child: overlayWidget,
30+
),
31+
],
32+
);
33+
}
34+
}

lib/src/widgets/widgets.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export 'help_collection/help_collection.dart';
22
export 'help_widget/help_widget.dart';
33
export 'links_card_widget/links_card_widget.dart';
4+
export 'overlay_widget/overlay_widget.dart';
45
export 'ukraine_flag_widget.dart';

0 commit comments

Comments
 (0)