Notice
Recent Posts
Recent Comments
Link
250x250
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- LifeCycle
- textview
- TEST
- Dialog
- livedata
- textfield
- CustomScrollView
- Coroutines
- android
- tabbar
- appbar
- Button
- scroll
- 테스트
- 계측
- viewmodel
- Kotlin
- Navigation
- binding
- Flutter
- activity
- DART
- 안드로이드
- Compose
- 앱바
- 앱
- data
- intent
- ScrollView
- drift
Archives
- Today
- Total
Study Record
[Flutter] 토스트 팝업 메시지 (fluttertoast v8) 본문
728x90
🎁 fluttertoast
토스트 팝업 메시지를 보여주는 간단한 라이브러리이다.
😶 설치
pubspec.yaml 파일에 fluttertoast 라이브러리를 추가해 준 뒤 pub get 버튼을 누른다. (현재 시각 최신 버전 v8)
dependencies:
fluttertoast: ^8.2.1
😶 사용법
아주 간단하게 토스트 팝업을 띄우는 것은 Fluttertoast.showToast() 로 띄워주면 된다.
import 'package:fluttertoast/fluttertoast.dart';
Fluttertoast.showToast(
msg: "토스트 팝업 메시지",
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.TOP,
backgroundColor: Colors.brown.withOpacity(0.7),
textColor: Colors.white,
fontSize: 13.0,
);
😶 커스텀 토스트 팝업
토스트 팝업을 직접 꾸미고 싶다면 FToast 클래스를 직접 이용하면 된다. FToast 의 showToast() 의 child 로 직접 디자인한 위젯을 넣고 toastDuration 으로 팝업 보여주는 시간을 입력한다. positionedToastBuilder 인자로 화면 원하는 위치에 토스트 팝업을 배치할 수 있다.
import 'package:fluttertoast/fluttertoast.dart';
_showToast(BuildContext context) {
FToast fToast = FToast().init(context);
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),
);
*/
// 커스텀 배치 토스트 팝업
fToast.showToast(
child: toast,
toastDuration: Duration(seconds: 2),
positionedToastBuilder: (context, child) {
return Positioned(
child: child,
top: 50.0,
);
});
}
728x90
'Flutter > 라이브러리' 카테고리의 다른 글
[Flutter] 앱 로고 설정하기 (flutter_launcher_icons) (0) | 2023.04.23 |
---|---|
[Flutter] JSON (json_serializable 라이브러리) (0) | 2023.04.17 |
[Flutter] 서버와 통신하기 (dio v5.1.1) (0) | 2023.04.14 |
[Flutter] 간단한 데이터 저장 (flutter_secure_storage) (0) | 2023.04.07 |
[Flutter] drift 에서 Future 와 Stream 차이점 (2) | 2023.03.26 |