Skip to content

Commit 468c9d2

Browse files
committed
feat: switch
1 parent d238eff commit 468c9d2

File tree

3 files changed

+50
-4
lines changed

3 files changed

+50
-4
lines changed

docs/widget/form/switch/index.md

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,33 @@
1-
## **文档完善中**
1+
## **Switch**
2+
3+
>
4+
Switch是切换按钮控件,通常用于设置的选项里
5+
6+
### 构造方法
7+
``` dart
8+
Switch({
9+
Key key,
10+
@required this.value,
11+
@required this.onChanged,
12+
this.activeColor,
13+
this.activeTrackColor,
14+
this.inactiveThumbColor,
15+
this.inactiveTrackColor,
16+
this.activeThumbImage,
17+
this.inactiveThumbImage,
18+
this.materialTapTargetSize,
19+
this.dragStartBehavior = DragStartBehavior.start,
20+
})
21+
```
22+
23+
### 属性介绍
24+
* value: true:开 false:关
25+
* onChanged: 变化时回调
26+
* activeColor: 打开状态下颜色
27+
* activeTrackColor: 打开状态下track颜色
28+
* inactiveThumbColor: 关闭状态thumb颜色
29+
* inactiveTrackColor: 关闭状态track颜色
30+
* activeThumbImage: 打开状态下thumb图片
31+
* inactiveThumbImage: 关闭状态thumb图片
32+
* materialTapTargetSize: 配置点击目标的最小尺寸
33+
* dragStartBehavior: 确定处理拖动开始行为的方式

lib/widget/form/switch/demo.dart

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ class Index extends StatefulWidget {
66
}
77

88
class _IndexState extends State<Index> {
9+
bool _switchValue = false;
910
@override
1011
void initState() {
1112
super.initState();
@@ -18,7 +19,20 @@ class _IndexState extends State<Index> {
1819
title: Text('Switch'),
1920
),
2021
body: Center(
21-
child: Text('更新中'),
22+
child: Switch(
23+
value: _switchValue,
24+
onChanged: (value){
25+
setState(() {
26+
_switchValue = value;
27+
});
28+
},
29+
activeColor: Theme.of(context).primaryColor,
30+
activeTrackColor: Theme.of(context).primaryColor.withOpacity(0.3),
31+
inactiveThumbColor: Colors.black87,
32+
inactiveTrackColor: Colors.black12,
33+
activeThumbImage: NetworkImage('http://pic1.win4000.com/wallpaper/2019-02-15/5c664c4b4dc2f.jpg'),
34+
inactiveThumbImage: NetworkImage('http://pic1.win4000.com/wallpaper/2019-02-14/5c651084373de.jpg',),
35+
),
2236
),
2337
);
2438
}

lib/widget/form/switch/index.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import 'package:flutter/material.dart';
22
import 'package:efox_flutter/components/widgetComp.dart' as WidgetComp;
3-
// import 'demo.dart' as Demo;
3+
import 'demo.dart' as Demo;
44

55
class Index extends StatefulWidget {
66
static String title = 'Switch';
@@ -19,7 +19,7 @@ class _IndexState extends State<Index> {
1919
originCodeUrl: Index.originCodeUrl,
2020
mdUrl: Index.mdUrl,
2121
demoChild: [
22-
// Demo.Index(),
22+
Demo.Index(),
2323
],
2424
);
2525
}

0 commit comments

Comments
 (0)