Flutter 悬浮按钮 FloatingActionButton 的详细配置使用

小鱼儿 2023-10-07 17:05 74阅读 0赞

志在巅峰的攀登者,不会陶醉在沿途的某个脚印之中,在码农的世界里,优美的应用体验,来源于程序员对细节的处理以及自我要求的境界,年轻人也是忙忙碌碌的码农中一员,每天、每周,都会留下一些脚印,就是这些创作的内容,有一种执着,就是不知为什么,如果你迷茫,不妨来瞅瞅码农的轨迹。

如果你有兴趣 你可以关注一下公众号 biglead 来获取最新的学习资料。

  • Flutter 从入门 到精通系列文章在这里
  • 当然也必需是要有源码的 在这里了
  • github 有点慢 不妨来看看码云的源码吧
  • 系列学习教程在这里

Flutter 中 FloatingActionButton 是用来实现悬浮按钮效果的

  1. class ScffoldHomePage extends StatefulWidget {
  2. @override
  3. State<StatefulWidget> createState() {
  4. return ScffoldHomePageState();
  5. }
  6. }
  7. class ScffoldHomePageState extends State<ScffoldHomePage> {
  8. ///当前选中的页面
  9. num index =0;
  10. @override
  11. Widget build(BuildContext context) {
  12. ///使用 Scaffold 组件来构建应用的基本页面
  13. /// 页面的架构
  14. return Scaffold(
  15. ///定义页面的标题
  16. appBar: AppBar(
  17. title: Text("这里是首页"),
  18. ),
  19. ///定义的页面的主体内容
  20. body:pageWidgetList[index],
  21. ///定义的悬浮按钮
  22. floatingActionButton: FloatingActionButton(
  23. child: Text("++"),
  24. ///点击响应事
  25. onPressed: () {
  26. print("点击了 FloatingActionButton");
  27. },
  28. ///长按提示
  29. tooltip: "点击了 tooltip s ",
  30. ///设置悬浮按钮的背景
  31. backgroundColor: Colors.red,
  32. ///获取焦点时显示的颜色
  33. focusColor: Colors.green,
  34. ///鼠标悬浮在按钮上时显示的颜色
  35. hoverColor: Colors.yellow,
  36. ///水波纹颜色
  37. splashColor: Colors.deepPurple,
  38. ///定义前景色 主要影响文字的颜色
  39. foregroundColor: Colors.black,
  40. ///配制阴影高度 未点击时
  41. elevation: 0.0,
  42. ///配制阴影高度 点击时
  43. highlightElevation: 20.0,
  44. ),
  45. ///用来控制 FloatingActionButton 的位置
  46. ///FloatingActionButtonLocation.endFloat 默认使用 浮动右下角
  47. ///FloatingActionButtonLocation.endDocked 右下角
  48. ///FloatingActionButtonLocation.endTop 右上角
  49. ///FloatingActionButtonLocation.startTop 左上角
  50. ///FloatingActionButtonLocation.centerFloat 底部中间浮动
  51. ///FloatingActionButtonLocation.centerDocked 底部中间不浮动
  52. floatingActionButtonLocation: FloatingActionButtonLocation.endFloat,
  53. );
  54. }
  55. }

发表评论

表情:
评论列表 (有 0 条评论,74人围观)

还没有评论,来说两句吧...

相关阅读