弹出菜单按钮未在Flutter中显示

mxg2im7a  于 2023-01-14  发布在  Flutter
关注(0)|答案(1)|浏览(163)

我不知道我的代码出了什么问题,PopupMenuButton它不工作,
我已经运行了扑动更新,然而,它似乎没有工作。

下面是我的代码

import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:oga_bliss/screen/add_prop_page.dart';

import '../widget/notice_me.dart';
import '../widget/property_app_bar.dart';
import '../widget/property_tile_widget.dart';

enum SampleItem { itemOne, itemTwo, itemThree }

class ProductPropertyPage extends StatefulWidget {
  const ProductPropertyPage({Key? key}) : super(key: key);

  @override
  State<ProductPropertyPage> createState() => _ProductPropertyPageState();
}

class _ProductPropertyPageState extends State<ProductPropertyPage> {
  final GlobalKey _menuKey = GlobalKey();

  SampleItem? selectedMenu;
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Column(
        children: [
          const PropertyAppBar(title: 'Property'),
          Expanded(
            child: SingleChildScrollView(
              child: Column(
                children: [
                  NoticeMe(
                    title: 'Oops!',
                    desc: 'Your bank account is not yet verify!',
                    icon: Icons.warning,
                    icon_color: Colors.red,
                    border_color: Colors.red,
                    btnTitle: 'Verify Now',
                    btnColor: Colors.blue,
                    onTap: () {},
                  ),
                  PropertyTileWidget(
                    props_image_name:
                        'https://ogabliss.com/project_dir/property/45164d94bc96f243362af5468841cd44.jpg',
                    props_name: 'Newly Built 3 Bedroom flat',
                    props_desc:
                        'this newly built bedroom flat its covered with the latest and later type of euqipment that will keep your day going well',
                    props_price: '90000000000000',
                    props_type: 'Buy',
                    props_bedroom: '100',
                    props_bathroom: '290',
                    props_toilet: '100',
                    onTap: () {
                      _popUpBUtton();
                    },
                  ),
                  PropertyTileWidget(
                    props_image_name:
                        'https://ogabliss.com/project_dir/property/45164d94bc96f243362af5468841cd44.jpg',
                    props_name: 'Newly Built 3 Bedroom flat',
                    props_desc:
                        'this newly built bedroom flat its covered with the latest and later type of euqipment that will keep your day going well',
                    props_price: '90000000000000',
                    props_type: 'Rent',
                    props_bedroom: '100',
                    props_bathroom: '290',
                    props_toilet: '100',
                    onTap: () {
                      _popUpBUtton();
                    },
                  ),
                ],
              ),
            ),
          )
        ],
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: () {
          Get.to(
            () => AddPropertyPage(),
            transition: Transition.upToDown,
          );
        },
        child: const Icon(Icons.add),
      ),
    );
  }

  Widget _popUpBUtton() => PopupMenuButton<String>(
        enabled: true,
        itemBuilder: (context) {
          return [
            const PopupMenuItem(
              child: Text('Submit'),
              value: "One",
            ),
            const PopupMenuItem(
              child: Text('Edit'),
              value: "Two",
            ),
            const PopupMenuItem(
              child: Text('Delete'),
              value: "Three",
            ),
          ];
        },
      );
}
c3frrgcw

c3frrgcw1#

您不能通过点击其他微件来打开任何微件...而应尝试此操作

@override
  Widget build(BuildContext context) {
    return Column(
      children: [
    _popUpBUtton(),
     ]); }

 
Widget _popUpBUtton() => PopupMenuButton<String>(
        child: PropertyTileWidget(
          props_image_name:
              'https://ogabliss.com/project_dir/property/45164d94bc96f243362af5468841cd44.jpg',
          props_name: 'Newly Built 3 Bedroom flat',
          props_desc:
              'this newly built bedroom flat its covered with the latest and later type of euqipment that will keep your day going well',
          props_price: '90000000000000',
          props_type: 'Buy',
          props_bedroom: '100',
          props_bathroom: '290',
          props_toilet: '100',
        ),
        itemBuilder: (context) {
          return [
            const PopupMenuItem(
              value: "One",
              child: Text('Submit'),
            ),
            const PopupMenuItem(
              value: "Two",
              child: Text('Edit'),
            ),
            const PopupMenuItem(
              value: "Three",
              child: Text('Delete'),
            ),
          ];
        },
      );
}

相关问题