gpt4 book ai didi

flutter - 如何一次只允许打开一个 Slidable

转载 作者:行者123 更新时间:2023-12-03 03:55:32 26 4
gpt4 key购买 nike

我正在将 flutter_slidable 用于聊天应用幻灯片,我当时只想打开一张幻灯片,所以我尝试了他们在文档中推荐的内容,但它不起作用,我不知道为什么

class _ChatTileState extends State<ChatTile> {
final SlidableController slidableController = SlidableController();

@override
Widget build(BuildContext context) {
return GestureDetector(
onTap: () {},
child: Container(
padding: EdgeInsets.symmetric(vertical: 10),
child: Slidable(
key: UniqueKey(),
controller: slidableController,
movementDuration: Duration(milliseconds: 100),
...

最佳答案

嘿,为了使用 flutter_slidable 包一次打开一个图块。您需要为所有磁贴使用相同的 Slidable Controller 。从您的代码来看,您似乎正在为每个 tile 实例化新的 Slidable Controller 。您应该做的是从父小部件实例化 SlidableController 并将其传递给 tile 小部件。
这是父小部件


...
String title = 'Customers';
final SlidableController slidableController = SlidableController();
@override
Widget build(BuildContext context) {
return ScaffoldBody(
centerTitle: true,
title: title,

drawer: CustomerScreen.isOrderAdding == true ? null : AppDrawer(),
body: FutureBuilder(
future: _refreshCustomers(context),
builder: (ctx, snapshot) =>
snapshot.connectionState == ConnectionState.waiting
? Center(
child: Center(
child: Image(
image: AssetImage('assets/img/LoadingCartoon.gif'),
),
),
)
: RefreshIndicator(
onRefresh: () => _refreshCustomers(context),
child: Consumer<CustomerHttps>(
builder: (ctx, customerData, _) => Padding(
padding: EdgeInsets.all(5),
child: ListView.builder(
itemCount: customerData.items.length,
itemBuilder: (_, i) => CustomerTile(
slidableController: slidableController,
id: customerData.items[i].id,
name: customerData.items[i].name,
),
),
),
),
),
),
);
在我的可滑动 Tile 小部件(子小部件)中
 final String id;
final String name;
final SlidableController slidableController;

CustomerTile({
this.id,
this.name,
this.slidableController,
});

Widget build(BuildContext context) {
return CustomerScreen.isOrderAdding
? Container(
padding: EdgeInsets.only(bottom: 9),
child: Material(
elevation: 5,
borderRadius: BorderRadius.all(Radius.circular(10)),
color: Colors.white,
child: InkWell(
borderRadius: BorderRadius.all(Radius.circular(10)),
splashColor: Theme.of(context).primaryColor,
onTap: () {
//clears any products and signature saved after selecting a new customer
var provider =
Provider.of<AddingProductOrder>(context, listen: false);
provider.clear();
Navigator.of(context).pushNamed(
EditOrderScreen.routeName,
arguments: [id, 'selection'],
);
},
child: Container(
width: double.infinity,
child: ListTile(
title: Text(name,
style: TextStyle(color: Colors.black),
overflow: TextOverflow.ellipsis,
maxLines: 1,
softWrap: false),
leading: Icon(
Icons.person,
color: Theme.of(context).primaryColor,
),
),
),
),
),
)
: Slidable(
key: Key(id),
actionPane: SlidableDrawerActionPane(),
controller: slidableController,
actionExtentRatio: 0.25,
child: Container(...

关于flutter - 如何一次只允许打开一个 Slidable,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61475025/

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