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 도 추가해줘야한다.
반응형
'Flutter' 카테고리의 다른 글
플러터의 GetX ? (0) | 2023.01.08 |
---|---|
플러터의 위젯이란? (0) | 2022.11.06 |
플러터란? (0) | 2022.11.06 |
플러터 - 스낵바 만들기 (0) | 2021.06.20 |