Basic use of Snackbar
Step 1: Application entry setting
When we import dependencies, we will use it GetMaterialApp
as the top layer at the top of the application, as shown below
import 'package:flutter/material.dart';
import 'package:get/get.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return GetMaterialApp(
title: "GetX",
home: Scaffold(
appBar: AppBar(title: Text("GetX Title"),),
),
);
}
}
Step 2: Call snackbar
We can Get.snackbar()
display it by snackbar
, as shown below
import 'package:flutter/material.dart';
import 'package:get/get.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return GetMaterialApp(
title: "GetX",
home: Scaffold(
appBar: AppBar(
title: Text("GetX Title"),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
ElevatedButton(
onPressed: () {
Get.snackbar("Snackbar 标题", "欢迎使用Snackbar");
},
child: Text("显示 Snackbar"))
],
),
),
),
);
}
}
Show results
Snackbar attribute description
serial number | field | Attributes | describe |
---|---|---|---|
1 | title | String | popup title text |
2 | message | String | popup message text |
3 | colorText | Color | Text color of title and message |
4 | duration | Duration | The duration of the Snackbar popup (default 3 seconds) |
5 | instantInit | bool | When false, you can put the snackbar in initState, the default is true |
6 | snackPosition | SnackPosition | The position when it pops up, there are two options [TOP, BOTTOM] default TOP |
7 | titleText | Widget | The component that pops up the title, setting this property will invalidate the title property |
8 | messageText | Widget | The component that pops up a message, setting this property will invalidate the messageText property |
9 | icon | Widget | Icon when popping up, displayed on the left side of title and message |
10 | shouldIconPulse | bool | Whether the icon blinks when popping up, the default is false |
11 | maxWidth | double | Snackbar maximum width |
12 | margin | EdgeInsets | Snackbar margin, default zero |
13 | padding | EdgeInsets | Snackbar inner margin, default EdgeInsets.all(16) |
14 | borderRadius | double | Border fillet size, default 15 |
15 | borderColor | Color | The color of the border, borderWidth must be set, otherwise it will have no effect |
16 | borderWidth | double | border line width |
17 | backgroundColor | Color | Snackbar background color, default Colors.grey.withOpacity(0.2) |
18 | leftBarIndicatorColor | Color | The color of the left indicator |
19 | boxShadows | List | Snackbar shadow color |
20 | backgroundGradient | Gradient | The linear color of the background |
21 | mainButton | TextButton | Main button, generally displaying send, confirm button |
22 | onTap | OnTap | Click Snackbar event callback |
23 | isDismissible | bool | Whether to enable Snackbar gesture closing, can be used with dismissDirection |
24 | showProgressIndicator | bool | Whether to display the progress bar indicator, default false |
25 | dismissDirection | SnackDismissDirection | Direction for Snackbar to close |
26 | progressIndicatorController | AnimationController | An animation controller for the progress bar indicator |
27 | progressIndicatorBackgroundColor | Color | The background color of the progress bar indicator |
28 | progressIndicatorValueColor | Animation | The background color of the progress bar indicator, Animation |
29 | snackStyle | SnackStyle | Whether the Snackbar will be attached to the edge of the screen |
30 | forwardAnimationCurve | Curve | Snackbar pop-up animation, default Curves.easeOutCirc |
31 | reverseAnimationCurve | Curve | Snackbar disappear animation, default Curves.easeOutCirc |
32 | animationDuration | Duration | Snackbar pop-up and hour animation duration, default 1 second |
33 | barBlur | double | The blurriness of the Snackbar background |
34 | overlayBlur | double | Frosted glass effect value when popping up, default 0 |
35 | snackbarStatus | SnackbarStatusCallback | Event callback when the Snackbar pops up or disappears (is about to open, has been opened, is about to close, has been closed) |
36 | overlayColor | Color | The background color of the frosted glass when popping up |
37 | userInputForm | Form | user input form |