我遇到了一个问题--我得到了这个Snackbar (下面的代码)--它在android中运行得很好。但不是在IOS模拟器中(我还没有在真正的设备上尝试过)。问题是,当我打开Snackbar时,它会像地狱一样滞后。
造成这种情况的原因是:behavior: SnackbarBehavior.floating,当我从代码中删除它时,一切都开始正常工作了。
但我真的需要这部分,这是必要的。
所以我的问题是:,是否有人知道解决这个问题的方法,或者知道如何解决这个问题?
因为Snackbar是完全不可用的,有这么多的滞后。
这是Snackbar:的代码
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,
),
),
),
);
}
}发布于 2021-02-06 08:06:24
只要使用颤音,它就能在IOS和Android上工作,而且使用起来也很容易。
对于您想要的设计,您需要使用Toast,这需要上下文。
代码:
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实例,它必须以的方式使用:
FToast fToast;
@override
void initState() {
super.initState();
fToast = FToast();
fToast.init(context);
}有关更多信息,请查看:烤面包片
https://stackoverflow.com/questions/66022284
复制相似问题