多看官方文档吧 我看的是2019年的视频,跟着写代码发现了不少错误,又去看官方文档修改,太难了,学不动了!!!

    1. import 'package:flutter/material.dart';
    2. // import 'package:english_words/english_words.dart';
    3. void main() => runApp(new MyApp());
    4. class MyApp extends StatelessWidget {
    5. @override
    6. Widget build(BuildContext context) {
    7. return new MaterialApp(
    8. title: 'Welcome to Flutter',
    9. home: new Scaffold(
    10. appBar: new AppBar(
    11. title: new Text('Welcome to Flutter12'),
    12. ),
    13. body: Column(
    14. children: <Widget>[
    15. Image.asset(
    16. 'static/pic/mg3414.jpg',
    17. width: 200,
    18. height: 300,
    19. ),
    20. Image.asset('static/pic/162.jpg',
    21. width: 200,),
    22. Image.network('http://8.129.221.250:3000/uploads/fc3eace4355f22498f5d1008a942da30-NrJn4jqrY5Dd492d82806fe4d6b2a5707d806722350c.png'),
    23. Icon(Icons.zoom_out_sharp),
    24. new MySelect(),
    25. new MySwitchAndCheckBox()
    26. ]
    27. ),
    28. ),
    29. );
    30. }
    31. }
    32. // 下拉框
    33. class MySelect extends StatefulWidget {
    34. @override
    35. State<StatefulWidget> createState() {
    36. return _MySelect();
    37. }
    38. }
    39. class _MySelect extends State<MySelect> {
    40. // List getList() {
    41. // List<DropdownMenuItem> lists = [];
    42. // lists.add(DropdownMenuItem(child: new Text("上海"), value: 'sh'));
    43. // lists.add(DropdownMenuItem(child: new Text("北京"), value: 'bj'));
    44. // lists.add(DropdownMenuItem(child: new Text("广州"), value: 'gz'));
    45. // lists.add(DropdownMenuItem(child: new Text("深圳"), value: 'sz'));
    46. // return lists;
    47. // }
    48. var selectValue;
    49. @override
    50. Widget build(BuildContext context) {
    51. return new Column(
    52. children: <Widget>[
    53. new DropdownButton(
    54. items: [
    55. (DropdownMenuItem(child: new Text("上海"), value: 'sh')),
    56. (DropdownMenuItem(child: new Text("北京"), value: 'bj')),
    57. (DropdownMenuItem(child: new Text("广州"), value: 'gz')),
    58. (DropdownMenuItem(child: new Text("深圳"), value: 'sz')),
    59. ],
    60. hint: new Text('请选择城市'),
    61. value: selectValue,
    62. onChanged: (val) {
    63. setState(() {
    64. this.selectValue = val;
    65. });
    66. }
    67. )
    68. ],
    69. );
    70. }
    71. }
    72. // 单选和多选
    73. class MySwitchAndCheckBox extends StatefulWidget {
    74. @override
    75. State<StatefulWidget> createState() {
    76. return _MySwitchAndCheckBox();
    77. }
    78. }
    79. class _MySwitchAndCheckBox extends State<MySwitchAndCheckBox> {
    80. @override
    81. bool _switchValue = true;
    82. bool _checkboxValue = false;
    83. Widget build(BuildContext context) {
    84. return new Column(
    85. children: [
    86. new Switch(value: _switchValue, onChanged: (val) {
    87. setState(() {
    88. this._switchValue = val;
    89. });
    90. }),
    91. new Checkbox(value: _checkboxValue, onChanged: (bool? val) {
    92. setState(() {
    93. this._checkboxValue = val!;
    94. });
    95. })
    96. ],
    97. );
    98. }
    99. }