Flutter Switch

Flutter series overall directory

Switch control a switch.

Attributes Explanation
value true: open false: Off
onChanged Callback change
activeColor Open state color
activeTrackColor Color open state track
inactiveThumbColor Off thumb colors
inactiveTrackColor Off track color
activeThumbImage Open state thumb picture
inactiveThumbImage Off thumb picture
materialTapTargetSize Click area

track and thumb position:
Here Insert Picture Description

example:

import 'package:flutter/material.dart';

class SwitchDemo extends StatefulWidget {
  @override
  State<StatefulWidget> createState() => _SwitchDemo();
}

class _SwitchDemo extends State<SwitchDemo> {
  bool _value = true;

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Column(
      children: <Widget>[
        Switch(
          value: _value,
          onChanged: (newValue) {
            setState(() {
              _value = newValue;
            });
          },
          activeColor: Colors.red,
          activeTrackColor:Colors.black,
          inactiveThumbColor:Colors.green,
          inactiveTrackColor: Colors.blue,
          activeThumbImage: AssetImage(
            'images/1.png',
          ),
        ),
      ],
    );
  }
}

Here Insert Picture DescriptionHere Insert Picture Description

Published 113 original articles · won praise 66 · Views 300,000 +

Guess you like

Origin blog.csdn.net/mengks1987/article/details/85107740