Skip to content

Commit

Permalink
feat(main): SnackBar (#10)
Browse files Browse the repository at this point in the history
* add snackbar example

* Add snackbar widgetbook

* feat(main): SnackBar

* [automated commit] lint format and import sort

* remove view icon

* Add view icon

* Add widgetbook icon helper

* [automated commit] lint format and import sort

* fix alphabetical imports

* Fix delete and error background color

---------

Co-authored-by: github-actions <[email protected]>
  • Loading branch information
2 people authored and thelukewalton committed Apr 12, 2024
1 parent a86f0e3 commit cbf46d9
Show file tree
Hide file tree
Showing 6 changed files with 643 additions and 0 deletions.
2 changes: 2 additions & 0 deletions example/lib/home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import 'package:zeta_example/pages/components/list_item_example.dart';
import 'package:zeta_example/pages/components/navigation_bar_example.dart';
import 'package:zeta_example/pages/components/radio_example.dart';
import 'package:zeta_example/pages/components/switch_example.dart';
import 'package:zeta_example/pages/components/snackbar_example.dart';
import 'package:zeta_example/pages/theme/color_example.dart';
import 'package:zeta_example/pages/components/password_input_example.dart';
import 'package:zeta_example/pages/components/progress_example.dart';
Expand Down Expand Up @@ -47,6 +48,7 @@ final List<Component> components = [
Component(PasswordInputExample.name, (context) => const PasswordInputExample()),
Component(DropdownExample.name, (context) => const DropdownExample()),
Component(ProgressExample.name, (context) => const ProgressExample()),
Component(SnackBarExample.name, (context) => const SnackBarExample()),
Component(DialPadExample.name, (context) => const DialPadExample()),
Component(RadioButtonExample.name, (context) => const RadioButtonExample()),
Component(SwitchExample.name, (context) => const SwitchExample()),
Expand Down
229 changes: 229 additions & 0 deletions example/lib/pages/components/snackbar_example.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,229 @@
import 'package:flutter/material.dart';
import 'package:zeta_example/widgets.dart';
import 'package:zeta_flutter/zeta_flutter.dart';

class SnackBarExample extends StatelessWidget {
static const String name = 'SnackBar';

const SnackBarExample({super.key});

@override
Widget build(BuildContext context) {
return ExampleScaffold(
name: SnackBarExample.name,
child: SingleChildScrollView(
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Column(
children: [
// Standard Rounded
Row(
children: [
Padding(
padding: const EdgeInsets.only(top: ZetaSpacing.x4),
child: ZetaButton.primary(
label: "Standard Rounded SnackBar",
onPressed: () {
ScaffoldMessenger.of(context).showSnackBar(
ZetaSnackBar(
context: context,
onPressed: () {
ScaffoldMessenger.of(context).hideCurrentSnackBar();
},
actionLabel: "Action",
content: Text('This is a snackbar'),
),
);
},
),
),
],
),

// Standard Sharp
Padding(
padding: const EdgeInsets.only(top: ZetaSpacing.x4),
child: ZetaButton.primary(
label: "Standard Sharp SnackBar",
onPressed: () {
ScaffoldMessenger.of(context).showSnackBar(
ZetaSnackBar(
context: context,
onPressed: () {
ScaffoldMessenger.of(context).hideCurrentSnackBar();
},
actionLabel: "Action",
rounded: false,
content: Text('This is a snackbar'),
),
);
},
),
),

// Default
Padding(
padding: const EdgeInsets.only(top: ZetaSpacing.x4),
child: ZetaButton.primary(
label: "Contectual Default",
onPressed: () {
ScaffoldMessenger.of(context).showSnackBar(
ZetaSnackBar(
context: context,
type: ZetaSnackBarType.defaultType,
leadingIcon: Icon(Icons.mood_rounded),
content: Text('Message with icon'),
),
);
},
),
),

// Action
Padding(
padding: const EdgeInsets.only(top: ZetaSpacing.x4),
child: ZetaButton.primary(
label: "Action",
onPressed: () {
ScaffoldMessenger.of(context).showSnackBar(
ZetaSnackBar(
context: context,
type: ZetaSnackBarType.action,
onPressed: () {},
actionLabel: "Action",
content: Text('Actionable message with icon'),
),
);
},
),
),

// Positive
Padding(
padding: const EdgeInsets.only(top: ZetaSpacing.x4),
child: ZetaButton.primary(
label: "Positive",
onPressed: () {
ScaffoldMessenger.of(context).showSnackBar(
ZetaSnackBar(
context: context,
type: ZetaSnackBarType.positive,
content: Text('Request sent successfully'),
),
);
},
),
),

// Info
Padding(
padding: const EdgeInsets.only(top: ZetaSpacing.x4),
child: ZetaButton.primary(
label: "Info",
onPressed: () {
ScaffoldMessenger.of(context).showSnackBar(
ZetaSnackBar(
context: context,
type: ZetaSnackBarType.info,
content: Text('Information is being displayed'),
),
);
},
),
),

// Info
Padding(
padding: const EdgeInsets.only(top: ZetaSpacing.x4),
child: ZetaButton.primary(
label: "Info",
onPressed: () {
ScaffoldMessenger.of(context).showSnackBar(
ZetaSnackBar(
context: context,
type: ZetaSnackBarType.info,
content: Text('Information is being displayed'),
),
);
},
),
),

// Warning
Padding(
padding: const EdgeInsets.only(top: ZetaSpacing.x4),
child: ZetaButton.primary(
label: "Warning",
onPressed: () {
ScaffoldMessenger.of(context).showSnackBar(
ZetaSnackBar(
context: context,
type: ZetaSnackBarType.warning,
content: Text('Warning has been issued'),
),
);
},
),
),

// Error
Padding(
padding: const EdgeInsets.only(top: ZetaSpacing.x4),
child: ZetaButton.primary(
label: "Error",
onPressed: () {
ScaffoldMessenger.of(context).showSnackBar(
ZetaSnackBar(
context: context,
type: ZetaSnackBarType.error,
content: Text('Error has been detected'),
),
);
},
),
),

// Deletion
Padding(
padding: const EdgeInsets.only(top: ZetaSpacing.x4),
child: ZetaButton.primary(
label: "Deletion",
onPressed: () {
ScaffoldMessenger.of(context).showSnackBar(
ZetaSnackBar(
context: context,
type: ZetaSnackBarType.deletion,
onPressed: () {},
content: Text('Item was deleted'),
),
);
},
),
),

// View
Padding(
padding: const EdgeInsets.only(top: ZetaSpacing.x4),
child: ZetaButton.primary(
label: "View",
onPressed: () {
ScaffoldMessenger.of(context).showSnackBar(
ZetaSnackBar(
context: context,
type: ZetaSnackBarType.view,
onPressed: () {},
content: Text('Something neeeds your attention'),
),
);
},
),
),
],
),
],
),
),
);
}
}
5 changes: 5 additions & 0 deletions example/widgetbook/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import 'pages/components/password_input_widgetbook.dart';
import 'pages/components/progress_widgetbook.dart';
import 'pages/components/radio_widgetbook.dart';
import 'pages/components/switch_widgetbook.dart';
import 'pages/components/snack_bar_widgetbook.dart';
import 'pages/theme/color_widgetbook.dart';
import 'pages/theme/radius_widgetbook.dart';
import 'pages/theme/spacing_widgetbook.dart';
Expand Down Expand Up @@ -92,6 +93,10 @@ class HotReload extends StatelessWidget {
),
WidgetbookUseCase(name: 'Radio Button', builder: (context) => radioButtonUseCase(context)),
WidgetbookUseCase(name: 'Switch', builder: (context) => switchUseCase(context)),
WidgetbookUseCase(
name: 'Snack Bar',
builder: (context) => snackBarUseCase(context),
),
]..sort((a, b) => a.name.compareTo(b.name)),
),
WidgetbookCategory(
Expand Down
56 changes: 56 additions & 0 deletions example/widgetbook/pages/components/snack_bar_widgetbook.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import 'package:flutter/material.dart';
import 'package:widgetbook/widgetbook.dart';
import 'package:zeta_flutter/zeta_flutter.dart';

import '../../test/test_components.dart';
import '../../utils/utils.dart';

Widget snackBarUseCase(BuildContext context) {
return WidgetbookTestWidget(
widget: Builder(
builder: (context) {
final text = context.knobs.string(
label: 'Content Text',
initialValue: 'This is a snackbar',
);

final actionLabel = context.knobs.stringOrNull(
label: 'Action Label',
initialValue: null,
);

final type = context.knobs.listOrNull<ZetaSnackBarType>(
label: 'Type',
options: [null, ...ZetaSnackBarType.values],
labelBuilder: (type) => type?.name ?? '',
);

final leadingIcon = iconKnob(
context,
name: "Leading Icon",
initial: Icons.mood_rounded,
nullable: true,
);

final rounded = context.knobs.boolean(label: 'Rounded', initialValue: true);

return ZetaButton.primary(
label: "Show Snackbar",
onPressed: () {
print(actionLabel);
final snackBar = ZetaSnackBar(
context: context,
onPressed: () {},
actionLabel: actionLabel,
type: type,
leadingIcon: leadingIcon != null ? Icon(leadingIcon) : null,
rounded: rounded,
content: Text(text),
);

ScaffoldMessenger.of(context).showSnackBar(snackBar);
});
},
),
);
}
Loading

0 comments on commit cbf46d9

Please sign in to comment.