생각보다 처리하기 귀찮은 toast sample을 미리 작성해둔다.
Toast 변수 선언, initState에서 초기화
초기화를 해주고, 현재 context를 연결해준다.
late FToast fToast;
void initState() {
super.initState();
fToast = FToast();
fToast.init(context);
}
toast 디자인 method
구지 이럴필요가 있을까 싶지만, toast custom 디자인을 만들어 둘 수 있는게 더 낫겠지?
_showToast() {
Widget toast = Container(
padding: const EdgeInsets.symmetric(horizontal: 24.0, vertical: 12.0),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(25.0),
color: ThemeData.dark().primaryColor.withAlpha(80),
),
child: const Row(
mainAxisSize: MainAxisSize.min,
children: [
Icon(
Icons.check,
color: Colors.white,
),
SizedBox(
width: 12.0,
),
Text(
"This is a Custom Toast",
style: TextStyle(color: Colors.white),
),
],
),
);
fToast.showToast(
child: toast,
gravity: ToastGravity.BOTTOM,
toastDuration: const Duration(seconds: 2),
);
}
버튼 function으로 구현
버튼에서는 위에 만들어둔 _showToast() 만 호출하면 된다.
ElevatedButton(
onPressed: () {
_showToast();
},
child: const Text('show toast'),
),
끝.
'Dead Code > Flutter_Dart' 카테고리의 다른 글
[다트] 리스트 중복 제거 (0) | 2023.07.14 |
---|---|
[플러터] Map 정렬하기 (0) | 2023.07.12 |
[플러터] 구글 Sheets 를 DB로 사용해서 갤러리 만들기 #2 (0) | 2023.07.12 |
[플러터] .json theme 파일사용하기 (0) | 2023.07.11 |
[플러터] widget : Wrap (0) | 2023.07.06 |
[다트] dart 3.0 - records 괄호 지옥 (0) | 2023.05.26 |
[플러터] 구글 Sheets 를 DB로 사용해서 갤러리 만들기 #1 (0) | 2023.05.11 |
[플러터] Rive animation 실행은 해보자 #2 (0) | 2023.04.24 |
[플러터] 자질구래한 methods (0) | 2023.04.20 |
[플러터] Rive 오랜만에 사용 (0) | 2023.03.26 |