dart 如何在Flutter中为PopupMenu添加圆角边框?

dwbf0jvd  于 11个月前  发布在  Flutter
关注(0)|答案(4)|浏览(209)

有没有什么方法可以创建自定义弹出窗口与圆角边框?这是我目前的代码和设计:

child: Container(
                 child: PopupMenuButton(
                   onSelected: _savedLocationOptionSelected,
                   itemBuilder: (context) {
                     return SavedLocationOptions.choises.map((value) {
                       return PopupMenuItem<String>(
                         value: value,
                         child: Text(value),
                       );
                     }).toList();
                   },
                   icon: Icon(
                     Icons.more_vert,
                     color: Colors.grey[300],
                   ),
                 ),
               ),

字符串


的数据

kxxlusnw

kxxlusnw1#

你只要在弹出菜单按钮上这样添加

shape: RoundedRectangleBorder(
          borderRadius: BorderRadius.all(
               Radius.circular(20.0),
          ),
),

字符串
例如

PopupMenuButton(
      child: Text("Show Popup Menu"),
      shape: RoundedRectangleBorder(
          borderRadius: BorderRadius.all(Radius.circular(15.0))
      ),
      itemBuilder: (context) => [
        PopupMenuItem(
          child: Text("pub.dev"),
        ),
        PopupMenuItem(
          child: Text("Flutter"),
        ),
        PopupMenuItem(
          child: Text("Google.com"),
        ),
        PopupMenuItem(
          child: Text("https://blogdeveloperspot.blogspot.com/search?q=flutter"),
        ),
      ],
    ),

snvhrwxg

snvhrwxg2#

添加到@Taz给出的答案您可以使用主题在一个地方的每个弹出窗口中设置圆角:

MaterialApp(
  // ....
  theme: ThemeData(
  // ....
  popupMenuTheme: PopupMenuThemeData(
    shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(8))
  )
)

字符串

q5lcpyga

q5lcpyga3#

另一个简单的方法是:

shape: ContinuousRectangleBorder(
         borderRadius: BorderRadius.circular(30),
       ),

字符串

dddzy1tm

dddzy1tm4#

在你的代码中点击右键“PopupMenuButton”,然后将其粘贴到“PopupMenu”命名的页面中,并将此链接中的代码粘贴到Dart文件中
然后访问此链接:

https://github.com/mohamedashraf8850/flutter/edit/master/packages/flutter/lib/src/material/popup_menu.dart

相关问题