Skip to content

Commit

Permalink
✨ Add action widgets pastel
Browse files Browse the repository at this point in the history
  • Loading branch information
iqfareez committed May 11, 2022
1 parent 385ff13 commit 5de11bd
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 19 deletions.
37 changes: 35 additions & 2 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,41 @@ class MyHomePage extends StatelessWidget {
),
const Divider(),
Text(
'Classic Admonition',
style: Theme.of(context).textTheme.headline5,
'...with actions',
style: Theme.of(context).textTheme.headline6,
),
PastelAdmonition.caution(
text: '(Caution) I hope you read this. With action button below.',
actions: [
TextButton(
style: TextButton.styleFrom(
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
primary: Theme.of(context).textTheme.bodyLarge!.color,
textStyle: const TextStyle(fontWeight: FontWeight.w600),
),
onPressed: () {
ScaffoldMessenger.of(context).removeCurrentSnackBar();
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(
content: Text('Button 1 pressed'),
behavior: SnackBarBehavior.floating,
));
},
child: const Text('Action 1')),
TextButton(
style: TextButton.styleFrom(
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
primary: Theme.of(context).textTheme.bodyLarge!.color,
textStyle: const TextStyle(fontWeight: FontWeight.w600),
),
onPressed: () {
ScaffoldMessenger.of(context).removeCurrentSnackBar();
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(
content: Text('Button 2 pressed'),
behavior: SnackBarBehavior.floating,
));
},
child: const Text('Action 2'))
],
),
],
),
Expand Down
52 changes: 35 additions & 17 deletions lib/src/pastel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class PastelAdmonition extends StatelessWidget {
this.color = Colors.blue,
this.icon,
this.opacity = .3,
this.actions,
this.primaryColor})
: assert(child == null || text == null,
'Either child or text is allowed to exist'),
Expand All @@ -22,6 +23,7 @@ class PastelAdmonition extends StatelessWidget {
this.color = const Color(0xffebedf0),
this.icon = const FaIcon(FontAwesomeIcons.circleInfo),
this.opacity = .3,
this.actions,
this.primaryColor,
}) : super(key: key);

Expand All @@ -32,6 +34,7 @@ class PastelAdmonition extends StatelessWidget {
this.color = const Color(0xff00a400),
this.icon = const FaIcon(FontAwesomeIcons.lightbulb),
this.opacity = .3,
this.actions,
this.primaryColor,
}) : super(key: key);

Expand All @@ -42,6 +45,7 @@ class PastelAdmonition extends StatelessWidget {
this.color = const Color(0xff54c7ec),
this.icon = const FaIcon(FontAwesomeIcons.circleExclamation),
this.opacity = .3,
this.actions,
this.primaryColor,
}) : super(key: key);
const PastelAdmonition.caution({
Expand All @@ -51,6 +55,7 @@ class PastelAdmonition extends StatelessWidget {
this.color = const Color(0xffffba00),
this.icon = const FaIcon(FontAwesomeIcons.triangleExclamation),
this.opacity = .3,
this.actions,
this.primaryColor,
}) : super(key: key);
const PastelAdmonition.danger({
Expand All @@ -60,6 +65,7 @@ class PastelAdmonition extends StatelessWidget {
this.color = const Color(0xfffa383e),
this.icon = const FaIcon(FontAwesomeIcons.fire),
this.opacity = .3,
this.actions,
this.primaryColor,
}) : super(key: key);

Expand All @@ -75,6 +81,8 @@ class PastelAdmonition extends StatelessWidget {

final Color? primaryColor;

final List<Widget>? actions;

@override
Widget build(BuildContext context) {
return Container(
Expand All @@ -83,24 +91,34 @@ class PastelAdmonition extends StatelessWidget {
decoration: BoxDecoration(
color: (color ?? Theme.of(context).primaryColor).withOpacity(opacity),
borderRadius: BorderRadius.circular(16)),
child: Row(
child: Column(
children: [
if (icon != null) ...[
IconTheme(
data: IconThemeData(
color: primaryColor ?? Theme.of(context).iconTheme.color,
size: 18),
child: icon!),
const SizedBox(width: 10)
],
if (text != null)
DefaultTextStyle(
style: TextStyle(
color: primaryColor ??
Theme.of(context).textTheme.bodyText1!.color),
child: Flexible(child: Text(text!)))
else
child!
Row(
children: [
if (icon != null) ...[
IconTheme(
data: IconThemeData(
color:
primaryColor ?? Theme.of(context).iconTheme.color,
size: 18),
child: icon!),
const SizedBox(width: 10)
],
if (text != null)
DefaultTextStyle(
style: TextStyle(
color: primaryColor ??
Theme.of(context).textTheme.bodyText1!.color),
child: Flexible(child: Text(text!)))
else
child!
],
),
if (actions != null)
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: actions!,
)
],
),
);
Expand Down

0 comments on commit 5de11bd

Please sign in to comment.