Flutter学习之-Image&单选框&switch

199 阅读1分钟

#Image学习


class ImageIconDemo extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Column(
      children: [
        Icon(Icons.add),
        IconButton(
          icon: Icon(Icons.home),
          onPressed: () {},
        ),
        Container(
          width: double.infinity,
          child: Image.network(
            "https://dss0.bdstatic.com/70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/u=2496571732,442429806&fm=26&gp=0.jpg",
            fit: BoxFit.fill,
          ),
        ),
        Image.asset("images/11111.jpeg")
      ],
    );
  }
}

Simulator Screen Shot - iPad Pro (12.9-inch) (5th generation) - 2021-06-09 at 21.28.49.png

###设置本地图片的一些配置操作

  1. 找到pubspec.yaml文件 2.在上述文件中找到assets 3.打开注释,并且设置为图片路径
assets:
    - images/11111.jpeg

WX20210609-211432@2x.png

#单选框&Switch


class CheckDemo extends StatefulWidget {
  @override
  _CheckDemoState createState() => _CheckDemoState();
}

class _CheckDemoState extends State<CheckDemo> {
  bool _check = false;
  bool _switch = false;
  @override
  Widget build(BuildContext context) {
    return Column(
      children: [
        Checkbox(
            value: _check,
            onChanged: (v) {
              setState(() {
                _check = v!;
              });
            }),
        Switch(
            value: _switch,
            onChanged: (v) {
              setState(() {
                _switch = v!;
              });
            }),
      ],
    );
  }
}

Simulator Screen Shot - iPad Pro (12.9-inch) (5th generation) - 2021-06-09 at 21.26.11.png