简介
ios风格下的Switch组件, 用法与Switch组件相同
基本用法
基本用法与Switch基本相同. 不同点在于, 该组件仅支持自定义activeColor, 也就是支持自定义当按钮处于true状态下,按钮的背景色.
实例演示
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
class CupertinoSwitchDemo extends StatefulWidget {
_Demo createState() => _Demo();
}
class _Demo extends State<CupertinoSwitchDemo> {
bool _lights = false;
Widget build(BuildContext context) {
return MergeSemantics(
child: ListTile(
title: Text('CupertinoSwitch'),
trailing: CupertinoSwitch(
activeColor: Colors.yellow,
value: _lights,
onChanged: (bool value) { setState(() { _lights = value; }); },
),
onTap: () { setState(() { _lights = !_lights; }); },
),
);
}
}