如何使用旧的Flutter开关设计?

问题描述 投票:0回答:1

我目前使用的是最新版本的 Flutter 和 Dart,但在我的项目中,我想使用 Flutter 开关的旧设计。

电流开关:

Current Flutter Switch Design

旧开关:

Old Flutter Switch Design

我尝试使用 Flutter 中 Switch 类提供的几乎所有属性,但无法将其恢复到旧设计。

我还搜索了 pub.dev 相关的包,但没有找到可以做到这一点的。

flutter dart customization
1个回答
0
投票

新的开关设计是由于Android更新了开关样式。如果你想 为了使您的开关看起来像旧的 UI,您应该创建一个自定义样式的开关并使其看起来像您想要的那样。

例如

Switch(
  value: isSwitchOn,
  onChanged: (newValue) {
    setState(() {
      isSwitchOn = newValue;
    });
  },
  activeColor: Colors.green,
  inactiveThumbColor: Colors.red,
  activeTrackColor: Colors.lightGreen,
  inactiveTrackColor: Colors.grey,
)
© www.soinside.com 2019 - 2024. All rights reserved.