有一个非常有用的软件包可供您使用 - fluttertoast。
简单写-
Fluttertoast.showToast(
msg: "This is Center Short Toast",
);
您可以添加
toastLength
使其变短或变长 -
Fluttertoast.showToast(
msg: "This is Center Short Toast",
toastLength: Toast.LENGTH_SHORT,
);
希望这有帮助。让我知道。
这里有一个不使用包的棘手方法:
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
backgroundColor: Colors.transparent,
elevation: 0,
padding: EdgeInsets.zero,
duration: const Duration(seconds: 2),
behavior: SnackBarBehavior.floating,
margin: const EdgeInsets.only(bottom: 76.0),
content: Theme(
data: ThemeData.dark(), // Use different theme with main app!
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Card(
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(2.0))),
child: Padding(
padding: const EdgeInsets.symmetric(
horizontal: 16.0, vertical: 12.0),
child: Text(text),
),
),
],
),
),
),
);
另一个解决方案是使用oktoast,我们可以通过位置参数改变位置
showToast(
"$_counter",
duration: Duration(seconds: 2),
position: ToastPosition.bottom,
backgroundColor: Colors.black.withOpacity(0.8),
radius: 13.0,
textStyle: TextStyle(fontSize: 18.0),
);