在 modalButtomSheet 中使用 viewinsets 时溢出
Overflow when using viewinsets in a modalButtomSheet
问题:
- 我正在使用 MediaQuery 和 viewInsets 添加填充,当用户
在 modalBottomSheet.
中触发键盘
- 看起来不错,但我收到一条关于溢出的消息
- 当我手动绘制 modalBottomSheet 时,我可以看到 sheet 后面发生溢出。
先写代码,再截图:
这是打开模式的 GestureDetector sheet:
GestureDetector(
onTap: () {
showModalBottomSheet(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.vertical(
top: Radius.circular(23.r),
),
),
isScrollControlled: true,
context: context,
builder: (bctx) => StatefulBuilder(builder:
(BuildContext context, StateSetter setModalState) {
return ModalAddFavorite();
}));
},
这是我用作模态表的 Widegt:
class ModalAddFavorite extends StatefulWidget {
const ModalAddFavorite({Key? key}) : super(key: key);
@override
_ModalAddFavoriteState createState() => _ModalAddFavoriteState();
}
class _ModalAddFavoriteState extends State<ModalAddFavorite> {
@override
Widget build(BuildContext context) {
return StatefulBuilder(
builder: (BuildContext context, StateSetter setModalState) {
return Padding(
padding: EdgeInsets.only(
bottom: MediaQuery.of(context).viewInsets.bottom * 0.98.h),
//
child: SingleChildScrollView(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
SizedBox(
height: 20.h,
),
Container(
width: 80.w,
height: 6.w,
decoration: BoxDecoration(
color: Provider.of<CustomColors>(context, listen: false)
.customColorScheme['Grey 2'],
borderRadius: BorderRadius.circular(6.r),
),
),
SizedBox(
height: 25.h,
),
//
Text(
'ADD A FAVORITE',
style: Provider.of<CustomTextStyle>(context)
.customTextStyle('ModalHeader'),
),
SizedBox(
height: 25.5.h,
),
//
//
InputFieldAddFavorite(),
SizedBox(
height: 40.h,
)
],
),
),
);
});
}
}
截图:
模态 Sheet 打开/键盘不活动/无溢出
Modal sheet 打开/键盘激活/Flutter 中的溢出警告
Modal shett 手动拉回 // 在 sheet:
后面可见溢出
尝试在您的 SingleChildScrollView()
下添加 physics: NeverScrollableScrollPhysics()
。
问题已解决:我需要包装包含页面本身的列,而不是将模式 sheet 包装在 SingleChildScrollView 中。
问题:
- 我正在使用 MediaQuery 和 viewInsets 添加填充,当用户 在 modalBottomSheet. 中触发键盘
- 看起来不错,但我收到一条关于溢出的消息
- 当我手动绘制 modalBottomSheet 时,我可以看到 sheet 后面发生溢出。
先写代码,再截图:
这是打开模式的 GestureDetector sheet:
GestureDetector(
onTap: () {
showModalBottomSheet(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.vertical(
top: Radius.circular(23.r),
),
),
isScrollControlled: true,
context: context,
builder: (bctx) => StatefulBuilder(builder:
(BuildContext context, StateSetter setModalState) {
return ModalAddFavorite();
}));
},
这是我用作模态表的 Widegt:
class ModalAddFavorite extends StatefulWidget {
const ModalAddFavorite({Key? key}) : super(key: key);
@override
_ModalAddFavoriteState createState() => _ModalAddFavoriteState();
}
class _ModalAddFavoriteState extends State<ModalAddFavorite> {
@override
Widget build(BuildContext context) {
return StatefulBuilder(
builder: (BuildContext context, StateSetter setModalState) {
return Padding(
padding: EdgeInsets.only(
bottom: MediaQuery.of(context).viewInsets.bottom * 0.98.h),
//
child: SingleChildScrollView(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
SizedBox(
height: 20.h,
),
Container(
width: 80.w,
height: 6.w,
decoration: BoxDecoration(
color: Provider.of<CustomColors>(context, listen: false)
.customColorScheme['Grey 2'],
borderRadius: BorderRadius.circular(6.r),
),
),
SizedBox(
height: 25.h,
),
//
Text(
'ADD A FAVORITE',
style: Provider.of<CustomTextStyle>(context)
.customTextStyle('ModalHeader'),
),
SizedBox(
height: 25.5.h,
),
//
//
InputFieldAddFavorite(),
SizedBox(
height: 40.h,
)
],
),
),
);
});
}
}
截图:
模态 Sheet 打开/键盘不活动/无溢出
Modal sheet 打开/键盘激活/Flutter 中的溢出警告
Modal shett 手动拉回 // 在 sheet:
后面可见溢出尝试在您的 SingleChildScrollView()
下添加 physics: NeverScrollableScrollPhysics()
。
问题已解决:我需要包装包含页面本身的列,而不是将模式 sheet 包装在 SingleChildScrollView 中。