showSnackBar
코드 복사할 때, 밑에 '복사되었습니다' 구현하기 위함
버튼 클릭 부분
// 위의 코드
TextButton(
onPressed: () => {
showSnackBar(context),
},
child: Column(
children: [
const Text(
'코드 복사',
textAlign: TextAlign.center,
style: TextStyle(
color: Color(0xFFA9A9B0),
fontSize: 14,
height: 1,
),
),
Container(
width: 80,
height: 1,
decoration: const BoxDecoration(color: Color(0xFFD2D2D2)),
),
],
),
),
// 아래 코드
showSnackBar(BuildContext context) {
final snackBar = SnackBar(
content: Text(
'코드 복사 완!',
style: TextStyle(
color: Colors.white,
fontSize: 16,
height: 1,
),
),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(10))), // 둥글게
backgroundColor: const Color(0xff9E9E9E),
behavior: SnackBarBehavior.floating, // 아래 플로팅 띄우기
duration: const Duration(seconds: 2),
action:
SnackBarAction(label: '', textColor: Colors.white, onPressed: () {}),
);
ScaffoldMessenger.of(context).showSnackBar(snackBar);
}
추가
// 로딩표시
CircularProgressIndicator(),
에러
'showSnackBar' isn't defined
Error: The method 'showSnackBar' isn't defined for the class 'ScaffoldState'.
Try correcting the name to the name of an existing method, or defining a method named 'showSnackBar'.
Scaffold.of(context).showSnackBar(snackBar);
ScaffoldMessenger.of(context).showSnackBar(snackBar);
https://api.flutter.dev/flutter/material/ScaffoldMessengerState/showSnackBar.html