首页 > 其他 > 详细

flutter PopupMenuButton弹出式菜单列表

时间:2019-08-13 12:39:20      阅读:633      评论:0      收藏:0      [点我收藏+]
import ‘package:flutter/material.dart‘;

class PopupMenuButtonDemo extends StatefulWidget {
  @override
  _PopupMenuButtonDemoState createState() => _PopupMenuButtonDemoState();
}

class _PopupMenuButtonDemoState extends State<PopupMenuButtonDemo> {
  String _currentMenuItem = ‘Home‘;
  
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(‘PopupMenuButtonDemo‘),
        elevation: 0.0,
      ),
      body: Container(
        padding: EdgeInsets.all(16.0),
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Row(
              mainAxisAlignment: MainAxisAlignment.center,
              children: <Widget>[
                Text(_currentMenuItem),
                PopupMenuButton(
                  onSelected: (value) {
                    print(value);
                    setState(() {
                      _currentMenuItem = value;
                    });
                  },
                  itemBuilder: (BuildContext context) => [
                    PopupMenuItem(
                      value: ‘Home‘,
                      child: Text(‘Home‘),
                    ),
                    PopupMenuItem(
                      value: ‘Discover‘,
                      child: Text(‘Discover‘),
                    ),
                    PopupMenuItem(
                      value: ‘Community‘,
                      child: Text(‘Community‘),
                    ),
                  ],
                ),
              ],
            ),
          ],
        ),
      )
    );
  }
}

文档:https://api.flutter.dev/flutter/material/PopupMenuButton-class.html

效果;

技术分享图片

技术分享图片

 

flutter PopupMenuButton弹出式菜单列表

原文:https://www.cnblogs.com/loaderman/p/11345081.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!