码迷,mamicode.com
首页 > 其他好文 > 详细

switch and checkbox

时间:2019-04-21 21:41:46      阅读:182      评论:0      收藏:0      [点我收藏+]

标签:pack   lap   mep   oid   override   state   axis   rac   style   

import ‘package:flutter/material.dart‘;

void main()=>runApp(MyApp());

class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: HomePage(),
);
}
}

class HomePage extends StatefulWidget {
@override
_HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
int _counter=0;
@override
Widget build(BuildContext context) {
return Scaffold(
body:Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
SwitchAndCheckBoxTestRoute(),
],
),
),
);
}
}
class SwitchAndCheckBoxTestRoute extends StatefulWidget {
@override
_SwitchAndCheckBoxTestRouteState createState() => _SwitchAndCheckBoxTestRouteState();
}

class _SwitchAndCheckBoxTestRouteState extends State<SwitchAndCheckBoxTestRoute> {
bool _switchSelected=true; //维护单选开关状态
bool _checkboxSelected=true;//维护复选框状态
@override
Widget build(BuildContext context) {
return Column(
children: <Widget>[
Switch(
value: _switchSelected,//当前状态
activeColor: Colors.lime,
inactiveThumbColor: Colors.grey,
activeTrackColor: Colors.deepPurple,
onChanged:(value){
//重新构建页面
setState(() {
_switchSelected=value;
});
},
),
Checkbox(
value: _checkboxSelected,
activeColor: Colors.orange, //选中时的颜色
checkColor: Colors.lightBlue,
onChanged:(value){
setState(() {
_checkboxSelected=value;
});
} ,
)
],
);
}
}

switch and checkbox

标签:pack   lap   mep   oid   override   state   axis   rac   style   

原文地址:https://www.cnblogs.com/braveheart007/p/10747098.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!