小编Bar*_*ryz的帖子

如何在 Flutter 中更改 CupertinoSwitch 非活动状态颜色

我的问题是,如何在 Flutter 中更改 CupertinoSwitch 的非活动颜色,使用普通 Switch 相当容易,因为我们有相应的属性,但在 CupertinoSwitch (iOS) 上我们没有这些属性。

编辑:

现在这是实现这一目标的自定义类。

import 'dart:ui';

import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/services.dart';

class MyCupertinoSwitch extends StatefulWidget {
  /// Creates an iOS-style switch.
  ///
  /// The [value] parameter must not be null.
  /// The [dragStartBehavior] parameter defaults to [DragStartBehavior.start] and must not be null.
  const MyCupertinoSwitch({
    Key key,
    @required this.value,
    @required this.onChanged,
    this.activeColor,
    this.trackColor,
    this.dragStartBehavior = DragStartBehavior.start,
  })  : assert(value != null),
        assert(dragStartBehavior != null),
        super(key: key);

  /// Whether …
Run Code Online (Sandbox Code Playgroud)

flutter flutter-cupertino

5
推荐指数
1
解决办法
2万
查看次数

标签 统计

flutter ×1

flutter-cupertino ×1