我必须在FloatingActionButton上运行一个动作。为了测试它是否工作或按下正确,我只是在onPressed()中创建了一个简单的打印,但在终端中什么也没有。这是我的代码:
@override
Widget buildView() {
return Scaffold(
appBar: AppBar(
title: const Text('Find Devices'),
),
// body:
floatingActionButton: FloatingActionButton(
onPressed: () =>
print("Scan Button"),
backgroundColor: Colors.blue,
child: const Icon(Icons.search),
),
);
}
1条答案
按热度按时间xytpbqjk1#
这看起来像是在使用
StatefulWidget
中的buildView
方法。为了使FloatingActionButton
真正显示在屏幕上,您需要从StatefulWidget
的build
方法而不是buildView
中返回它。请尝试修改代码,如下所示: