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

flutter DropdownButton使用

时间:2019-08-23 00:13:37      阅读:481      评论:0      收藏:0      [点我收藏+]

标签:img   mamicode   image   material   imp   key   center   class   ack   

import ‘package:flutter/material.dart‘;
class MyStatefulWidget extends StatefulWidget {
  MyStatefulWidget({Key key}) : super(key: key);

  @override
  _MyStatefulWidgetState createState() => _MyStatefulWidgetState();
}

class _MyStatefulWidgetState extends State<MyStatefulWidget> {
  String dropdownValue = ‘One‘;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(

        child: DropdownButton<String>(
          value: dropdownValue,
          onChanged: (String newValue) {
            setState(() {
              dropdownValue = newValue;
            });
          },
          items: <String>[‘One‘, ‘Two‘, ‘Free‘, ‘Four‘]
              .map<DropdownMenuItem<String>>((String value) {
            return DropdownMenuItem<String>(
              value: value,
              child: Text(value),
            );
          }).toList(),
        ),
      ),
    );
  }
}

效果:

技术图片

 

flutter DropdownButton使用

标签:img   mamicode   image   material   imp   key   center   class   ack   

原文地址:https://www.cnblogs.com/loaderman/p/11351674.html

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