Fluttertoast.showToast(
msg: "This is Center Short Toast",
);
toastLength
来使其变得短或长 -Fluttertoast.showToast(
msg: "This is Center Short Toast",
toastLength: Toast.LENGTH_SHORT,
);
showMySnackBar({
required BuildContext context,
required double width,
double? height,
}) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
backgroundColor: Colors.transparent,
elevation: 0,
padding: EdgeInsets.zero,
content: Column(
mainAxisSize: MainAxisSize.min, // needed for flexible height
children: [
Container(
alignment: Alignment.center,
width: width,
height: height,
color: Colors.green,
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Text("MY snack"),
],
),
),
],
),
),
);
}
并使用
showMySnackBar(context: context, width: 400);
另一种解决方案是使用oktoast,我们可以通过位置参数来改变位置
showToast(
"$_counter",
duration: Duration(seconds: 2),
position: ToastPosition.bottom,
backgroundColor: Colors.black.withOpacity(0.8),
radius: 13.0,
textStyle: TextStyle(fontSize: 18.0),
);