-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 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
1 parent
a86f0e3
commit cbf46d9
Showing
6 changed files
with
643 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'), | ||
), | ||
); | ||
}, | ||
), | ||
), | ||
], | ||
), | ||
], | ||
), | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
example/widgetbook/pages/components/snack_bar_widgetbook.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}, | ||
), | ||
); | ||
} |
Oops, something went wrong.