gpt4 book ai didi

ios - Flutter 中的 SnackBar 在 iOS 上不会变得透明

转载 作者:行者123 更新时间:2023-12-04 08:10:00 27 4
gpt4 key购买 nike

我遇到了这个问题 Snackbar我希望它看起来像 pciture1,它在 android 中运行良好,但在 iOS 中运行良好。
在iOS中,它看起来像picture2。
我无法找出是什么导致了 iOS 中这种奇怪的差异。
所以我的问题是:如何在iOS中实现picture1的设计?
注意:如果可能,我不想使用 FlutterToast 或 Flushbar。
图一:
enter image description here
图2:
enter image description hereSnackbar代码:

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,
),
),
),
);
}

}

最佳答案

正如您难过的那样,如果可能,您不想使用 fluttertoast,但我认为,
没有它,他们不是实现你所尝试的简单方法。
所以我建议你使用 fluttertoast,它适用于 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);
}
有关更多信息,请查看: fluttertoast

关于ios - Flutter 中的 SnackBar 在 iOS 上不会变得透明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66023922/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com