美文网首页Flutter学习笔记
Flutter的Switch和Slider

Flutter的Switch和Slider

作者: 王俏 | 来源:发表于2019-10-10 10:49 被阅读0次

    Switch

    import 'package:flutter/material.dart';
    
    class SwitchDemo extends StatefulWidget {
      @override
      _SwitchDemoState createState() => _SwitchDemoState();
    }
    
    class _SwitchDemoState extends State<SwitchDemo> {
      bool _switchA = false;
      @override
      Widget build(BuildContext context) {
        return Scaffold(
          appBar: AppBar(
            title: Text('SwitchDemo'),
            elevation: 0.0,
          ),
          body: Container(
            padding: EdgeInsets.all(16.0),
            child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              children: <Widget>[
                Text(_switchA ? '☺' :'😭',style: TextStyle(fontSize: 32.0)),
                Switch(
                  value: _switchA,
                  onChanged: (value) {
                    setState(() {
                      _switchA = value;
                    });
                  },
    
                )
              ],
            ),
          ),
        );
      }
    }
    
    

    SwitchListTile

     SwitchListTile(
                  value: _switchA,
                  onChanged: (value) {
                    setState(() {
                      _switchA = value;
                    });
                  },
                  title: Text('Switch Item A'),
                  subtitle:Text('Description'),
                  secondary: _switchA ? Icon(Icons.visibility):Icon(Icons.visibility_off),
                  selected: _switchA,
                )
                
    

    Slider

     Slider(
                      value: _sliderA,
                      onChanged: (value) {
                        setState(() {
                          _sliderA = value;
                        });
                      },
                      min: 0.0,
                      max: 10.0,
                      divisions: 10,
                      activeColor: Theme.of(context).accentColor,
                      inactiveColor: Theme.of(context).accentColor.withOpacity(0.3),
                      label: '${_sliderA.toInt()}',
                      
                    )
                    
    

    相关文章

      网友评论

        本文标题:Flutter的Switch和Slider

        本文链接:https://www.haomeiwen.com/subject/yaxjyctx.html