【发布时间】:2019-09-22 22:16:05
【问题描述】:
在此小部件中,选项卡在类型之间导航,如果有问题,它会转到指定的屏幕。如果是论坛,它会转到另一个论坛。问题是我需要将当前点击的类型传递给浮动操作按钮中的按下功能。但是浮动操作按钮位于脚手架主体之外。有没有办法将值传递给浮动操作按钮?
class TabScreen extends StatelessWidget {
final GlobalKey<ScaffoldState> _scaffoldKey = new GlobalKey<ScaffoldState();
@override
Widget build(BuildContext context) {
final bool showfab = MediaQuery.of(context).viewInsets.bottom == 0.0;
final AuthService authService = Provider.of<AuthService>(context);
return StreamBuilder<List<String>>(
stream: forumServices.forumsTypes$,
builder: (context, snapshot) {
if (!snapshot.hasData) {
return CircularProgressIndicator();
}
List<String> types = snapshot.data;
num tabLen = types.length;
return DefaultTabController(
length: tabLen,
child: Scaffold(
key: _scaffoldKey,
body: CustomScrollView(slivers: <Widget>[
SliverAppBar(
title: Text("kdkdkkd"),
bottom: TabBar(
tabs: types.map((String f) {
return Text(f);
}).toList()),
),
SliverFillRemaining(
child: StreamBuilder<List<Forums>>(
stream: forumServices.forums$,
builder: (context, snap) {
if (!snap.hasData) {
return CircularProgressIndicator();
}
final forum = snap.data;
return TabBarView(
children: types.map((String type) {
List<Forums> listofthistype =
forum.where((Forums fo) {
return fo.type == type;
}).toList();
final cards = listofthistype
.map((thistype) => ForumCard(
choosentype: thistype,
forumServices: forumServices,
))
.toList();
return ListView(
children: cards,
);
}).toList(),
);
}),
),
]),
floatingActionButton:
FloatingActionButton(
onPressed: () => _showBottom(),
tooltip: 'Increment',
child: Icon(Icons.add),
)
));
});
【问题讨论】:
-
我也有同样的问题。我想将快照传递给浮动按钮 onPressed 函数。
-
我使用了一个模型,从中获取所有数据,然后使用提供程序在按钮中调用它
标签: flutter parameter-passing floating-action-button scaffold