我有一个过滤器按钮。它是一个带有边框的容器,里面有两个连续的图标。所有这些都包含在手势检测器中。
当用户点击手势检测器时,我将显示底部模式表。这一切都有效。但是,我希望其中一个图标根据用户是否激活底部模式表而改变。我怎样才能实现这个目标?
我想我可以在点击按钮后、在显示模式底部表单之前调用 setState 。当用户点击时如何再次调用 setState ?
谢谢!
是否有一个选项可以在 showModalBottomSheet 构造函数中配置它?
由于您没有发布任何代码,我猜测您正在使用该方法showModalBottomSheet。
该方法具有以下原型:
Future<T?> showModalBottomSheet<T>({
required BuildContext context,
required WidgetBuilder builder,
Color? backgroundColor,
double? elevation,
ShapeBorder? shape,
Clip? clipBehavior,
BoxConstraints? constraints,
Color? barrierColor,
bool isScrollControlled = false,
bool useRootNavigator = false,
bool isDismissible = true,
bool enableDrag = true,
RouteSettings? routeSettings,
AnimationController? transitionAnimationController,
})
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,它返回一个Future<T?>类型,这意味着您可以将await,then或whenComplete应用于返回的未来操作。在您的情况下,whenComplete如果您不需要底部工作表中的任何值,那么使用可能是更好的选择。
showModalBottomSheet<void>(
context: context,
builder: (context) {
return Container(
height: 200,
color: Colors.amber,
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
mainAxisSize: MainAxisSize.min,
children: <Widget>[
const Text('Modal BottomSheet'),
ElevatedButton(
child: const Text('Close BottomSheet'),
onPressed: () => Navigator.pop(context),
)
],
),
),
);
},
).whenComplete(_onBottomSheetClosed);
Run Code Online (Sandbox Code Playgroud)
void _onBottomSheetClosed() {
print("Closed bottomsheet");
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5416 次 |
| 最近记录: |