Skip to content

Commit

Permalink
fix: added extra documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
vanlooverenkoen committed Oct 1, 2024
1 parent a8d7066 commit 1a903ec
Show file tree
Hide file tree
Showing 9 changed files with 217 additions and 105 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

- Yellow underline (because of missing `Material` widget)

## Docs

- Added documentation on the Snacky custom widget implementation

# 0.2.4

## CI
Expand Down
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,20 @@ final snacky = Snacky(
SnackyController.instance.showMessage((context) => snacky);
```

## Show a snacky with a custom widget

```dart
final snacky = Snacky.widget(
builder: (context, cancelableSnacky) => YourCustomSnackyWidget(),
showDuration: Duration(seconds: 3), // How long the snacky should be shown
transitionDuration: Duration(milliseconds: 300), // How long the transition should take
transitionCurve: Curves.easeInOut, // The curve of the transition
location: SnackyLocation
.top, // Where the snacky should be shown (SnackyLocation.top or SnackyLocation.bottom)
);
SnackyController.instance.showMessage((context) => snacky);
```

## Cancel the active snacky

```dart
Expand Down
104 changes: 23 additions & 81 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'package:flutter/material.dart';
import 'package:snacky/snacky.dart';
import 'package:impaktfull_ui/impaktfull_ui.dart';

const colorAccent = Color(0xFF7D64F2);
const colorPrimary = Color(0xFF1A1A1A);
Expand Down Expand Up @@ -45,8 +44,8 @@ class HomeScreen extends StatelessWidget {
height: 50,
),
const SizedBox(height: 16),
ExampleButton(
title: 'show success at the top of the screen',
ImpaktfullButton.accent(
label: 'show success at the top of the screen',
onTap: () {
const snacky = Snacky(
title: 'Top',
Expand All @@ -55,8 +54,8 @@ class HomeScreen extends StatelessWidget {
SnackyController.instance.showMessage((context) => snacky);
},
),
ExampleButton(
title: 'show error at the top of the screen',
ImpaktfullButton.accent(
label: 'show error at the top of the screen',
onTap: () {
const snacky = Snacky(
title: 'Top',
Expand All @@ -65,8 +64,8 @@ class HomeScreen extends StatelessWidget {
SnackyController.instance.showMessage((context) => snacky);
},
),
ExampleButton(
title: 'show warning at the top of the screen',
ImpaktfullButton.accent(
label: 'show warning at the top of the screen',
onTap: () {
const snacky = Snacky(
title: 'Top',
Expand All @@ -75,8 +74,8 @@ class HomeScreen extends StatelessWidget {
SnackyController.instance.showMessage((context) => snacky);
},
),
ExampleButton(
title: 'show info at the top of the screen',
ImpaktfullButton.accent(
label: 'show info at the top of the screen',
onTap: () {
const snacky = Snacky(
title: 'Top',
Expand All @@ -86,8 +85,8 @@ class HomeScreen extends StatelessWidget {
},
),
const SizedBox(height: 32),
ExampleButton(
title: 'show success at the bottom of the screen',
ImpaktfullButton.accent(
label: 'show success at the bottom of the screen',
onTap: () {
const snacky = Snacky(
title: 'Bottom',
Expand All @@ -97,8 +96,8 @@ class HomeScreen extends StatelessWidget {
SnackyController.instance.showMessage((context) => snacky);
},
),
ExampleButton(
title: 'show success that can be canceled',
ImpaktfullButton.accent(
label: 'show success that can be canceled',
onTap: () {
const snacky = Snacky(
title: 'Top (cancelable)',
Expand All @@ -108,8 +107,8 @@ class HomeScreen extends StatelessWidget {
SnackyController.instance.showMessage((context) => snacky);
},
),
ExampleButton(
title: 'show success that can be canceled by tap',
ImpaktfullButton.accent(
label: 'show success that can be canceled by tap',
onTap: () {
final snacky = Snacky(
title: 'Top (tap to cancel)',
Expand All @@ -119,8 +118,8 @@ class HomeScreen extends StatelessWidget {
SnackyController.instance.showMessage((context) => snacky);
},
),
ExampleButton(
title: 'show successs that will stay open untill closed',
ImpaktfullButton.accent(
label: 'show successs that will stay open untill closed',
onTap: () {
const snacky = Snacky(
title: 'Top (open untill closed/cancelled)',
Expand All @@ -131,8 +130,8 @@ class HomeScreen extends StatelessWidget {
SnackyController.instance.showMessage((context) => snacky);
},
),
ExampleButton(
title: 'show custom widget',
ImpaktfullButton.accent(
label: 'show custom widget',
onTap: () {
final snacky = Snacky.widget(
builder: (context, cancelabelSnacky) => Container(
Expand All @@ -145,73 +144,16 @@ class HomeScreen extends StatelessWidget {
SnackyController.instance.showMessage((context) => snacky);
},
),
ExampleButton.primary(
title: 'cancel all snackies',
ImpaktfullButton.primary(
label: 'cancel all snackies',
onTap: () => SnackyController.instance.cancelAll(),
),
ExampleButton.primary(
title: 'cancel active snacky',
ImpaktfullButton.primary(
label: 'cancel active snacky',
onTap: () => SnackyController.instance.cancelActiveSnacky(),
),
],
),
);
}
}

class ExampleButton extends StatelessWidget {
final String title;
final VoidCallback onTap;
final Color color;

const ExampleButton({
required this.title,
required this.onTap,
super.key,
}) : color = colorAccent;

const ExampleButton.primary({
required this.title,
required this.onTap,
super.key,
}) : color = colorPrimary;

@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.symmetric(vertical: 4),
child: ClipRRect(
borderRadius: BorderRadius.circular(4),
child: Stack(
children: [
Container(
width: double.infinity,
color: color,
padding: const EdgeInsets.symmetric(
horizontal: 16,
vertical: 12,
),
child: Text(
title,
style: const TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
),
textAlign: TextAlign.center,
),
),
Positioned.fill(
child: Material(
color: Colors.transparent,
child: InkWell(
onTap: onTap,
child: const ColoredBox(color: Colors.transparent),
),
),
),
],
),
),
);
}
}
Loading

0 comments on commit 1a903ec

Please sign in to comment.