fluttertoast是一个轻量级的库

 fluttertoast: ^8.2.6

使用

Fluttertoast.showToast(
  msg: "This is Center Short Toast",  // 设置Toast消息内容
  toastLength: Toast.LENGTH_SHORT,    // 设置显示时长为短
  gravity: ToastGravity.CENTER,       // 设置Toast消息显示在屏幕中间
  timeInSecForIosWeb: 1,              // 设置iOS/Web平台的显示时长为1秒
  backgroundColor: Colors.red,        // 设置Toast消息的背景色为红色
  textColor: Colors.white,            // 设置文字颜色为白色
  fontSize: 16.0                      // 设置文字大小为16.0
);

关闭

Fluttertoast.cancel()

 强制横屏无法使用

AndroidManifest.xml(在 android/app/src/main/ 路径下):

<activity
    android:name=".MainActivity"
    android:screenOrientation="sensor"  <!-- 使用sensor而不是landscape -->
    ...>
</activity>

Info.plist(在 ios/Runner/ 路径下):

<key>UISupportedInterfaceOrientations</key>
<array>
  <string>UIInterfaceOrientationPortrait</string>
  <string>UIInterfaceOrientationPortraitUpsideDown</string>
  <string>UIInterfaceOrientationLandscapeLeft</string>
  <string>UIInterfaceOrientationLandscapeRight</string>
</array>

 

posted on 2024-07-09 11:17  鲤斌  阅读(10)  评论(0编辑  收藏  举报