Flutter
플러터 - 토스트 메세지 만들기
최데브
2021. 6. 20. 22:13
import 'package:flutter/material.dart';
import 'package:fluttertoast/fluttertoast.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'test',
theme: ThemeData(primarySwatch: Colors.blue),
home: Mypage(),
);
}
}
class Mypage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Toast message'),
centerTitle: true,
),
body: Center(
child: FlatButton(
onPressed: () {
flutterToast();
},
child: Text('Toast'),
color: Colors.teal,
),
),
);
}
}
void flutterToast() {
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
);
}
toast를 사용하려면 pubspec.yaml 파일에 fluttertoast: ^8.0.7 도 추가해줘야한다.