반응형
- 코드 예시
import 'package:flutter/material.dart';
class ExamplePage extends StatefulWidget {
const ExamplePage({Key? key}) : super(key: key);
@override
State<ExamplePage> createState() => _ExamplePageState();
}
class _ExamplePageState extends State<ExamplePage> {
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: ElevatedButton(
child: Text(
"스낵 바 열기",
),
onPressed: () {
OpenSnackBar(context);
},
),
));
}
}
void OpenSnackBar(BuildContext context) {
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text("메세지를 입력하세요"),
));
ScaffoldMessenger.of(context).clearSnackBars(); //빠르게 닫고 싶을때 사용
}
반응형