Skip to content

Commit 3b0e654

Browse files
feat: Custom widget enhancements (#8)
* feat: added support for snacky above navigation bar * Use padding directly * fix configuration * move back * Revert * Added the changelog * Add new features to Snacky in version 0.8.0 --------- Co-authored-by: Koen Van Looveren <vanlooverenkoen.dev@gmail.com>
1 parent e94ea29 commit 3b0e654

4 files changed

Lines changed: 47 additions & 14 deletions

File tree

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
# 0.8.0
2+
3+
## Feat
4+
5+
- Added `padding` to `Snacky`
6+
- Added `openUntilClosed` and `canBeClosed` as an option for a `Snacky.widget`
7+
18
# 0.7.0
29

310
## Feat

example/lib/widget/snacky_example.dart

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,26 @@ class SnackyExampleScreen extends StatelessWidget {
141141
controller.showMessage((context) => snacky);
142142
},
143143
),
144+
ImpaktfullButton.accent(
145+
label: 'show custom widget that will still open until closed',
146+
onTap: () {
147+
final snacky = Snacky.widget(
148+
builder: (context, cancelabelSnacky) => Container(
149+
color: const Color(0xFF7D64F2),
150+
padding: const EdgeInsets.all(16),
151+
child: const Text(
152+
'This is a custom widget',
153+
style: TextStyle(color: Colors.white),
154+
),
155+
),
156+
location: SnackyLocation.bottom,
157+
canBeClosed: true,
158+
openUntillClosed: true,
159+
padding: const EdgeInsets.only(bottom: kBottomNavigationBarHeight),
160+
);
161+
controller.showMessage((context) => snacky);
162+
},
163+
),
144164
ImpaktfullButton.primary(
145165
label: 'cancel all snackies',
146166
onTap: () => controller.cancelAll(),

lib/src/model/snacky.dart

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class Snacky {
1818
final Duration transitionDuration;
1919
final Curve transitionCurve;
2020
final SnackyLocation? location;
21+
final EdgeInsets? padding;
2122

2223
final Widget Function(BuildContext, CancelableSnacky)? builder;
2324
final EdgeInsetsGeometry? margin;
@@ -43,6 +44,7 @@ class Snacky {
4344
this.transitionCurve = Curves.easeInOut,
4445
this.margin,
4546
this.location,
47+
this.padding,
4648
}) : builder = null,
4749
_showDuration = showDuration;
4850

@@ -53,14 +55,15 @@ class Snacky {
5355
this.transitionCurve = Curves.easeInOut,
5456
this.margin,
5557
this.location,
58+
this.openUntillClosed = false,
59+
this.canBeClosed = false,
60+
this.padding,
5661
}) : title = '',
5762
_showDuration = showDuration,
5863
type = SnackyType.info,
5964
subtitle = null,
6065
leadingWidgetBuilder = null,
6166
trailingWidgetBuilder = null,
6267
bottomWidgetBuilder = null,
63-
onTap = null,
64-
canBeClosed = false,
65-
openUntillClosed = false;
68+
onTap = null;
6669
}

lib/src/widget/snacky_configurator_widget.dart

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -55,17 +55,20 @@ class _SnackyConfiguratorWidgetState extends State<SnackyConfiguratorWidget>
5555
final snackyLocation =
5656
layoutConfig.getSnackyLocation(context, activeSnacky.snacky);
5757
return Builder(
58-
builder: (context) => Stack(
59-
key: ValueKey(activeSnacky.hashCode),
60-
alignment: snackyLocation.alignment,
61-
children: [
62-
widget.snackyBuilder.build(
63-
context,
64-
layoutConfig,
65-
activeSnacky,
66-
snackyController,
67-
),
68-
],
58+
builder: (context) => Padding(
59+
padding: activeSnacky.snacky.padding ?? EdgeInsets.zero,
60+
child: Stack(
61+
key: ValueKey(activeSnacky.hashCode),
62+
alignment: snackyLocation.alignment,
63+
children: [
64+
widget.snackyBuilder.build(
65+
context,
66+
layoutConfig,
67+
activeSnacky,
68+
snackyController,
69+
),
70+
],
71+
),
6972
),
7073
);
7174
}

0 commit comments

Comments
 (0)