大佬教程收集整理的这篇文章主要介绍了手势按钮内的弹出菜单按钮在 Flutter 中不起作用,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在 Gesture button 中创建一个 PopUp 菜单,但单击该按钮时菜单没有显示。单击按钮时什么也没有发生。我应该怎么做才能使其在单击按钮时可见? 我也使用了 Focused Menu button 但它也发生了同样的情况。我无法弄清楚问题所在。
我正在制作这样的屏幕:
我想在点击按钮时显示这些菜单:
我的屏幕代码是这样的:
import 'package:epicare/Navigbar.dart';
import 'package:Flutter/material.dart';
import 'package:Fluttertoast/Fluttertoast.dart';
import 'package:focused_menu/focused_menu.dart';
import 'package:focused_menu/modals.dart';
import 'AddMedicinescreen.dart';
class MedicinesRecord extends StatefulWidget {
@overrIDe
_MedicinesRecordState createState() => _MedicinesRecordState();
}
class _MedicinesRecordState extends State<MedicinesRecord>
with TickerProvIDerStateMixin {
TabController _tabController;
var _selectedindex = 0;
@overrIDe
voID initState() {
super.initState();
_tabController = TabController(length: 2,vsync: this)
..addListener(() {
setState(() {
_selectedindex = _tabController.index;
});
});
}
@overrIDe
voID dispose() {
super.dispose();
_tabController.dispose();
}
@overrIDe
Widget build(BuildContext context) {
return Scaffold(
backgroundcolor: colors.white,appbar: Appbar(
backgroundcolor: const color(0xffE5E0A1),elevation: 0,centerTitle: true,Title: Text(
"Medicine",style: TextStyle(
FontSize: 15.0,color: colors.black,FontFamily: 'Montserrat',FontWeight: FontWeight.normal,),leading: Iconbutton(
icon: Icon(
Icons.arrow_back,onpressed: () {
Navigator.push(
context,MaterialPageRoute(
builder: (context) {
return Homepage();
},);
},body: Column(
children: [
// give the tab bar a height [can change height to preferred height]
Container(
margin: EdgeInsets.only(top: 32,right: 45,left: 45),height: 45,decoration: Boxdecoration(
color: const color(0xffE5E0A1),borderRadius: borderRadius.circular(
17.0,border: border.all(wIDth: 1.0,color: const color(0xff2f363d)),child: Tabbar(
controller: _tabController,// give the indicator a decoration (color and border radius)
indicator: Boxdecoration(
borderRadius: borderRadius.circular(
17.0,labelcolor: const color(0xffd4d411),unselectedLabelcolor: colors.black,tabs: [
// first tab [you can add an icon using the icon property]
Tab(
child: Text(
'Medicines',style: TextStyle(
FontFamily: 'Montserrat',FontSize: 16,//color: const color(0xffd4d411),letterSpacing: 0.48,textAlign: TextAlign.left,// second tab [you can add an icon using the icon property]
Tab(
child: Text(
'History',],// tab bar vIEw her
Expanded(
child: TabbarVIEw(
controller: _tabController,children: [
// Container(
//padding: EdgeInsets.symmetric(vertical: 25,horizontal: 32),//height: 50,//child:
Medicine(),//),// second tab bar vIEw Widget
MedHistory(),floatingActionbutton: _selectedindex > 0
? Container()
: floatingActionbutton(
child: Icon(
Icons.add,size: 40,backgroundcolor: const color(0xffd4d411),onpressed: () {
Navigator.push(
context,MaterialPageRoute(
builder: (context) {
return AddMedicine();
},);
},);
}
Widget Medicine() {
Size size = Mediaquery.of(context).size;
return ListVIEw(
children: [
Container(
margin: EdgeInsets.only(top: 25,left: 32,right: 32),wIDth: size.wIDth * 0.80,height: 54,padding: EdgeInsets.symmetric(vertical: 11,horizontal: 20),decoration: Boxdecoration(
borderRadius: borderRadius.circular(9.0),color: colors.white,BoxShadow: [
BoxShadow(
color: const color(0x29000000),offset: Offset(0,3),blurRadius: 6,child: Stack(
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.start,children: [
Text(
'Panadol',FontSize: 12,FontWeight: FontWeight.w500,color: const color(0xff232425),Text(
'Thrice a day',FontSize: 10,color: const color(0x80232425),Container(
wIDth: size.wIDth,child: Column(
crossAxisAlignment: CrossAxisAlignment.end,children: [
Text(
'50 mg',style: TextStyle(
FontFamily: 'Montserrat',FontWeight: FontWeight.w600,color: const color(0x80515559),GestureDetector(
onTap: () {
myPopMenu();
// FocusedMenuHolder(
// menuBoxdecoration: Boxdecoration(
// color: const color(0xFFD9D9D9),// ),// animateMenuItems: false,// duration: Duration(milliseconds: 500),// blurBackgroundcolor: colors.white,// blurSize: 2,// menuWIDth: size.wIDth * 0.5,// onpressed: () {},// menuItems: <FocusedMenuItem>[
// FocusedMenuItem(
// Title: Text(
// "Edit",// style: TextStyle(
// FontFamily: 'Montserrat',// FontWeight: FontWeight.w600,// FontSize: 14,// color: const color(0xff000000),// ),// textAlign: TextAlign.center,// ),// onpressed: () {}),// FocusedMenuItem(
// Title: Text(
// "Delete",// onpressed: () {})
// ],// );
},child: Icon(
Icons.more_horiz,size: 20,)
],);
}
Widget MedHistory() {
Size size = Mediaquery.of(context).size;
return ListVIEw(
children: [
Container(
margin: EdgeInsets.only(top: 25,height: 50,Text(
'From: 1 Jan,2021',Text(
'Ongoing',Container(
margin: EdgeInsets.only(top: 25,children: [
Text(
'Calpol',Text(
'As needed',children: [
Text(
'250 mg',Text(
'Ended: 20 Jan,);
}
Widget myPopMenu() {
return PopupMenubutton(
color: colors.white,onSelected: (value) {
Fluttertoast.showToast(
msg: "You have selected " + value.toString(),toastLength: Toast.LENGTH_SHORT,gravity: ToastGravity.BottOM,timeInSecForIosWeb: 1,backgroundcolor: colors.black,textcolor: colors.white,FontSize: 16.0);
},itemBuilder: (context) => [
PopupMenuItem(
value: 1,child: Row(
children: <Widget>[
padding(
padding: const EdgeInsets.fromLTRB(2,2,8,2),child: Icon(Icons.print),Text('Print')
],)),PopupMenuItem(
value: 2,child: Row(
children: <Widget>[
Text(
"Edit",FontSize: 14,color: const color(0xff000000),textAlign: TextAlign.center,PopupMenuItem(
value: 3,child: Row(
children: <Widget>[
Text(
"Delete",style: TextStyle(
FontFamily: 'Montserrat',]);
}
}
PS:我是 Flutter 的新手。请帮帮我
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)
以上是大佬教程为你收集整理的手势按钮内的弹出菜单按钮在 Flutter 中不起作用全部内容,希望文章能够帮你解决手势按钮内的弹出菜单按钮在 Flutter 中不起作用所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。