gpt4 book ai didi

flutter - 将 Slidable 与 onPressed 一起使用时出现问题。 (flutter_slidable : ^1. 2.0)

转载 作者:行者123 更新时间:2023-12-03 08:11:41 25 4
gpt4 key购买 nike

我在使用 flutter_slidable: ^1.2.0 时遇到问题。
看下面的代码

import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_slidable/flutter_slidable.dart';

class SlidableWidget extends StatelessWidget {
final Widget child;
final void Function(BuildContext context) onDismissed;

const SlidableWidget({required this.child, required this.onDismissed, Key? key}) : super(key: key);

@override
Widget build(BuildContext context) => Slidable(
child: child,
endActionPane: const ActionPane(motion: ScrollMotion(), children: [
SlidableAction(
flex: 1,
onPressed: this.onDismissed(context),
backgroundColor: Colors.red,
foregroundColor: Colors.white,
icon: Icons.delete,
label: 'Delete',
),
],
extentRatio: 0.2,),
);
}

我希望将 onDismissed 函数作为参数传递,但在 onPressed: this.onDismissed(context) 行上,这是不正确的。它显示无效的常量值。但我不知道出了什么问题以及如何解决。谁能给我解释一下吗?

非常感谢。

苏拉

最佳答案

删除 ActionPane 之前的“const”

然后你可以使用这个:

onPressed:(BuildContext 上下文){

},

关于flutter - 将 Slidable 与 onPressed 一起使用时出现问题。 (flutter_slidable : ^1. 2.0),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70632914/

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