我想在 Flutter/Dart 中使用不同操作系统的 native 外观创建 switch/toggle 小部件。我的意思是,如果我在 iOS 移动设备上运行,它应该是这样的:
如果我在 Android 手机上运行,它应该是这样的:
帮我在flutter/dart中实现这种类型的功能
最佳答案
Creates a CupertinoSwitch if the target platform is iOS, creates a material design switch otherwise.
Switch.adaptive(value: true, onChanged: (newValue) {})
示例代码:
bool _value = true;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(),
body: Switch.adaptive(
value: _value,
onChanged: (newValue) => setState(() => _value = newValue),
),
);
}
关于flutter - 如何在 flutter 中管理开关小部件的 native 外观,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58319811/