-
Notifications
You must be signed in to change notification settings - Fork 49
/
custom_snack_bar.dart
154 lines (145 loc) · 4.27 KB
/
custom_snack_bar.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
import 'dart:math';
import 'package:flutter/material.dart';
/// Popup widget that you can use by default to show some information
class CustomSnackBar extends StatefulWidget {
const CustomSnackBar.success({
Key? key,
required this.message,
this.messagePadding = const EdgeInsets.symmetric(horizontal: 24),
this.icon = const Icon(
Icons.sentiment_very_satisfied,
color: Color(0x15000000),
size: 120,
),
this.textStyle = const TextStyle(
fontWeight: FontWeight.w600,
fontSize: 16,
color: Colors.white,
),
this.maxLines = 2,
this.iconRotationAngle = 32,
this.iconPositionTop = -10,
this.iconPositionLeft = -8,
this.backgroundColor = const Color(0xff00E676),
this.boxShadow = kDefaultBoxShadow,
this.borderRadius = kDefaultBorderRadius,
this.textScaleFactor = 1.0,
this.textAlign = TextAlign.center,
}) : super(key: key);
const CustomSnackBar.info({
Key? key,
required this.message,
this.messagePadding = const EdgeInsets.symmetric(horizontal: 24),
this.icon = const Icon(
Icons.sentiment_neutral,
color: Color(0x15000000),
size: 120,
),
this.textStyle = const TextStyle(
fontWeight: FontWeight.w600,
fontSize: 16,
color: Colors.white,
),
this.maxLines = 2,
this.iconRotationAngle = 32,
this.iconPositionTop = -10,
this.iconPositionLeft = -8,
this.backgroundColor = const Color(0xff2196F3),
this.boxShadow = kDefaultBoxShadow,
this.borderRadius = kDefaultBorderRadius,
this.textScaleFactor = 1.0,
this.textAlign = TextAlign.center,
}) : super(key: key);
const CustomSnackBar.error({
Key? key,
required this.message,
this.messagePadding = const EdgeInsets.symmetric(horizontal: 24),
this.icon = const Icon(
Icons.error_outline,
color: Color(0x15000000),
size: 120,
),
this.textStyle = const TextStyle(
fontWeight: FontWeight.w600,
fontSize: 16,
color: Colors.white,
),
this.maxLines = 2,
this.iconRotationAngle = 32,
this.iconPositionTop = -10,
this.iconPositionLeft = -8,
this.backgroundColor = const Color(0xffff5252),
this.boxShadow = kDefaultBoxShadow,
this.borderRadius = kDefaultBorderRadius,
this.textScaleFactor = 1.0,
this.textAlign = TextAlign.center,
}) : super(key: key);
final String message;
final Widget icon;
final Color backgroundColor;
final TextStyle textStyle;
final int maxLines;
final int iconRotationAngle;
final List<BoxShadow> boxShadow;
final BorderRadius borderRadius;
final double iconPositionTop;
final double iconPositionLeft;
final EdgeInsetsGeometry messagePadding;
final double textScaleFactor;
final TextAlign textAlign;
@override
CustomSnackBarState createState() => CustomSnackBarState();
}
class CustomSnackBarState extends State<CustomSnackBar> {
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
return Container(
clipBehavior: Clip.hardEdge,
height: 80,
decoration: BoxDecoration(
color: widget.backgroundColor,
borderRadius: widget.borderRadius,
boxShadow: widget.boxShadow,
),
width: double.infinity,
child: Stack(
children: [
Positioned(
top: widget.iconPositionTop,
left: widget.iconPositionLeft,
child: SizedBox(
height: 95,
child: Transform.rotate(
angle: widget.iconRotationAngle * pi / 180,
child: widget.icon,
),
),
),
Center(
child: Padding(
padding: widget.messagePadding,
child: Text(
widget.message,
style: theme.textTheme.bodyMedium?.merge(widget.textStyle),
textAlign: widget.textAlign,
overflow: TextOverflow.ellipsis,
maxLines: widget.maxLines,
textScaleFactor: widget.textScaleFactor,
),
),
),
],
),
);
}
}
const kDefaultBoxShadow = [
BoxShadow(
color: Colors.black26,
offset: Offset(0, 8),
spreadRadius: 1,
blurRadius: 30,
),
];
const kDefaultBorderRadius = BorderRadius.all(Radius.circular(12));