Flutter Toast 생성
https://pub.dev/packages/fluttertoast
1. 라이브러리 추가
fluttertoast: ^8.0.8
2. 코드 추가
Build Context 없는 상태
Fluttertoast.showToast(
msg: "This is Center Short Toast",
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.CENTER,
timeInSecForIosWeb: 1,
backgroundColor: Colors.red,
textColor: Colors.white,
fontSize: 16.0
);
Build Context 있는 상태
FToast fToast;
@override
void initState() {
super.initState();
fToast = FToast();
fToast.init(context);
}
_showToast() {
Widget toast = Container(
padding: const EdgeInsets.symmetric(horizontal: 24.0, vertical: 12.0),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(25.0),
color: Colors.greenAccent,
),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Icon(Icons.check),
SizedBox(
width: 12.0,
),
Text("This is a Custom Toast"),
],
),
);
fToast.showToast(
child: toast,
gravity: ToastGravity.BOTTOM,
toastDuration: Duration(seconds: 2),
);
// Custom Toast Position
fToast.showToast(
child: toast,
toastDuration: Duration(seconds: 2),
positionedToastBuilder: (context, child) {
return Positioned(
child: child,
top: 16.0,
left: 16.0,
);
});
}
3. 머터리얼 스낵바 - SnackBar
ScaffoldMessenger.of(context)
.showSnackBar(SnackBar(
content: Text("Sending Message"),
)
);
반응형
'Dev > Flutter' 카테고리의 다른 글
Flutter - listener, callback 구현하기 (0) | 2021.11.19 |
---|---|
Flutter - ScrollListView (0) | 2021.11.17 |
Flutter - Syncfusion Calendar 사용 (0) | 2021.11.10 |
Flutter - 앱 종료 하기 (0) | 2021.11.09 |
Flutter - PackageInfo (0) | 2021.11.09 |