首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >颤振中的SnackBar不喜欢iOS上的“SnackBarBehavior.floating”

颤振中的SnackBar不喜欢iOS上的“SnackBarBehavior.floating”
EN

Stack Overflow用户
提问于 2021-02-03 06:24:17
回答 1查看 224关注 0票数 1

我遇到了一个问题--我得到了这个Snackbar (下面的代码)--它在android中运行得很好。但不是在IOS模拟器中(我还没有在真正的设备上尝试过)。问题是,当我打开Snackbar时,它会像地狱一样滞后。

造成这种情况的原因是:behavior: SnackbarBehavior.floating,当我从代码中删除它时,一切都开始正常工作了。

但我真的需要这部分,这是必要的。

所以我的问题是:,是否有人知道解决这个问题的方法,或者知道如何解决这个问题?

因为Snackbar是完全不可用的,有这么多的滞后。

这是Snackbar:的代码

代码语言:javascript
复制
import 'package:auto_size_text/auto_size_text.dart';
import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';
    
class SnackBarCustom {

  SnackBar snackBarCustom(final String title, final double height, final double width, final int maxLines) {
    return SnackBar(
      elevation: 1000,
      duration: Duration(seconds: 2),
      behavior: SnackBarBehavior.floating,
      backgroundColor: Colors.transparent,
      content: Padding(
        padding: EdgeInsets.symmetric(
          horizontal: width * 0.11,
          vertical: height * 0.06,
        ),
        child: Container(
          padding: EdgeInsets.symmetric(horizontal: width * 0.0075),
          height: height * 0.06,
          width: width,
          alignment: Alignment.center,
          decoration: BoxDecoration(
            borderRadius: BorderRadius.circular(height * 0.0374),
            color: const Color(0xFF555555).withOpacity(0.75),
          ),
          child: AutoSizeText(
            title,
            textAlign: TextAlign.center,
            style: GoogleFonts.montserrat(
              fontWeight: FontWeight.w700,
              fontSize: width * 0.32,
              color: const Color(0xFFFFFFFF),
              letterSpacing: 0.8,
            ),
            minFontSize: 5,
            maxFontSize: 14,
            maxLines: maxLines,
          ),
        ),
      ),
    );
  }

}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-02-06 08:06:24

只要使用颤音,它就能在IOS和Android上工作,而且使用起来也很容易。

对于您想要的设计,您需要使用Toast,这需要上下文。

代码:

代码语言:javascript
复制
showToast(final FToast fToast, final String title, final double height, final double width, final int maxLines) {
    Widget toast = Container(
      padding: EdgeInsets.symmetric(horizontal: width * 0.015),
      height: height * 0.06,
      width: width * 0.55,
      alignment: Alignment.center,
      decoration: BoxDecoration(
        borderRadius: BorderRadius.circular(height * 0.0374),
        color: const Color(0xFF555555).withOpacity(0.75),
      ),
      child: AutoSizeText(
        title,
        textAlign: TextAlign.center,
        style: GoogleFonts.montserrat(
          fontWeight: FontWeight.w700,
          fontSize: width * 0.32,
          color: const Color(0xFFFFFFFF),
          letterSpacing: 0.8,
          fontStyle: FontStyle.italic,
        ),
        minFontSize: 5,
        maxFontSize: 14,
        maxLines: maxLines,
      ),
    );


    fToast.showToast(
      child: toast,
      gravity: ToastGravity.BOTTOM,
      toastDuration: Duration(seconds: 2),
    );

  }

您还需要有一个FToast实例,它必须以的方式使用:

代码语言:javascript
复制
 FToast fToast;

  @override
  void initState() {
    super.initState();
    fToast = FToast();
    fToast.init(context);
  }

有关更多信息,请查看:烤面包片

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66022284

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档