我正在尝试将函数传递给静态回调,我添加了下面的代码。我正在使用一个像系统警报窗口这样的插件,它是回调,它有一个带有传递到按钮的标签。与系统警报窗口相同,要在其他应用程序上绘制,绘制在屏幕上有一个按钮(静态调用返回功能)。我正在尝试将一个函数传递给此调用回调,以便在按下按钮时它能够在应用程序内执行某些操作
这是带有按钮的警报窗口主体代码。该按钮没有 onpresse 功能,而是由字符串标签标识。
final footer = FloatyHeadFooter(
buttons: [
float.FloatyHeadButton(
text: float.FloatyHeadText(
text: "Simple button",
fontSize: 12,
textColor: Color.fromRGBO(250, 139, 97, 1),
padding: float.FloatyHeadPadding(
bottom: 4,
left: 5,
right: 5,
top: 5,
),
fontWeight: float.FontWeight.normal,
),
tag: "simple_button",
padding: float.FloatyHeadPadding(left: 10, right: 10, bottom: 10, top: 10),
width: 0,
height: float.FloatyHeadButton.WRAP_CONTENT,
decoration: float.FloatyHeadDecoration(
startColor: Colors.white,
endColor: Colors.white,
borderWidth: 0,
borderRadius: 0.0),
),
float.FloatyHeadButton(
text: float.FloatyHeadText(
fontWeight: float.FontWeight.normal,
padding: float.FloatyHeadPadding(
bottom: 4,
left: 5,
right: 5,
top: 5,
),
text: "Focus button",
fontSize: 12,
textColor: Colors.white,
),
tag: "focus_button",
width: 0,
padding: float.FloatyHeadPadding(left: 10, right: 10, bottom: 10, top: 10),
height: float.FloatyHeadButton.WRAP_CONTENT,
decoration: float.FloatyHeadDecoration(
startColor: Color.fromRGBO(250, 139, 97, 1),
endColor: Color.fromRGBO(247, 28, 88, 1),
borderWidth: 0,
borderRadius: 30.0),
)
],
padding: float.FloatyHeadPadding(left: 16, right: 16, bottom: 12),
decoration: float.FloatyHeadDecoration(startColor: Colors.white),
buttonsPosition: float.ButtonPosition.center,
); final header = float.FloatyHeadHeader(
title: float.FloatyHeadText(
text: "Ongoing Ride",
fontSize: 12,
textColor: Colors.black45,
fontWeight: float.FontWeight.normal,
padding: float.FloatyHeadPadding(
bottom: 4,
left: 5,
right: 5,
top: 5,
),
),
padding: float.FloatyHeadPadding.setSymmetricPadding(12, 12),
subTitle: float.FloatyHeadText(
text: 'Name $riderName',
fontSize: 16,
fontWeight: float.FontWeight.bold,
padding: float.FloatyHeadPadding(
bottom: 4,
left: 5,
right: 5,
top: 5,
),
textColor: Colors.black87,
),
decoration: float.FloatyHeadDecoration(startColor: Colors.grey[100]),
button: float.FloatyHeadButton(
text: float.FloatyHeadText(
fontWeight: float.FontWeight.bold,
text: "Personal",
fontSize: 10,
textColor: Colors.black45,
padding: float.FloatyHeadPadding(
bottom: 4,
left: 5,
right: 5,
top: 5,
),
),
tag: "personal_btn"),
);
final body = float.FloatyHeadBody(
rows: [
float.EachRow(
columns: [
float.EachColumn(
text: float.FloatyHeadText(
fontWeight: float.FontWeight.bold,
text: "Updated body $pickUpAdd",
fontSize: 12,
textColor: Colors.black45,
padding: float.FloatyHeadPadding(
bottom: 4,
left: 5,
right: 5,
top: 5,
),
),
),
],
gravity: float.ContentGravity.center,
),
float.EachRow(columns: [
float.EachColumn(
text: float.FloatyHeadText(
text: "Updated long data of the body",
fontSize: 12,
textColor: Colors.black87,
fontWeight: float.FontWeight.bold,
padding: float.FloatyHeadPadding(
bottom: 4,
left: 5,
right: 5,
top: 5,
),
),
padding: float.FloatyHeadPadding.setSymmetricPadding(6, 8),
decoration: float.FloatyHeadDecoration(
startColor: Colors.black12, borderRadius: 25.0),
margin: float.FloatyHeadMargin(top: 4),
),
], gravity: float.ContentGravity.center),
float.EachRow(
columns: [
float.EachColumn(
text: float.FloatyHeadText(
text: "Notes",
fontSize: 10,
textColor: Colors.black45,
fontWeight: float.FontWeight.normal,
padding: float.FloatyHeadPadding(
bottom: 4,
left: 5,
right: 5,
top: 5,
),
),
),
],
gravity: float.ContentGravity.left,
margin: float.FloatyHeadMargin(top: 8),
),
float.EachRow(
columns: [
float.EachColumn(
text: float.FloatyHeadText(
text: "Updated random notes.",
fontSize: 13,
textColor: Colors.black54,
fontWeight: float.FontWeight.bold,
padding: float.FloatyHeadPadding(
bottom: 4,
left: 5,
right: 5,
top: 5,
),
),
),
],
gravity: float.ContentGravity.left,
),
],
padding: float.FloatyHeadPadding(left: 16, right: 16, bottom: 12, top: 12),
);
final footer = FloatyHeadFooter(
buttons: [
float.FloatyHeadButton(
text: float.FloatyHeadText(
text: "Simple button",
fontSize: 12,
textColor: Color.fromRGBO(250, 139, 97, 1),
padding: float.FloatyHeadPadding(
bottom: 4,
left: 5,
right: 5,
top: 5,
),
fontWeight: float.FontWeight.normal,
),
tag: "simple_button",
padding: float.FloatyHeadPadding(left: 10, right: 10, bottom: 10, top: 10),
width: 0,
height: float.FloatyHeadButton.WRAP_CONTENT,
decoration: float.FloatyHeadDecoration(
startColor: Colors.white,
endColor: Colors.white,
borderWidth: 0,
borderRadius: 0.0),
),
float.FloatyHeadButton(
text: float.FloatyHeadText(
fontWeight: float.FontWeight.normal,
padding: float.FloatyHeadPadding(
bottom: 4,
left: 5,
right: 5,
top: 5,
),
text: "Focus button",
fontSize: 12,
textColor: Colors.white,
),
tag: "focus_button",
width: 0,
padding: float.FloatyHeadPadding(left: 10, right: 10, bottom: 10, top: 10),
height: float.FloatyHeadButton.WRAP_CONTENT,
decoration: float.FloatyHeadDecoration(
startColor: Color.fromRGBO(250, 139, 97, 1),
endColor: Color.fromRGBO(247, 28, 88, 1),
borderWidth: 0,
borderRadius: 30.0),
)
],
padding: float.FloatyHeadPadding(left: 16, right: 16, bottom: 12),
decoration: float.FloatyHeadDecoration(startColor: Colors.white),
buttonsPosition: float.ButtonPosition.center,
);
这是包含按钮的字符串标记的回调,当我单击按钮时,它会打印出结果,但我无法将 woking 函数传递给按钮。
static void floatCallBack(String tag) {
print('CALLBACK FROM FRAGMENT BUILDED: $tag');
switch (tag) {
case "simple_button":
print('CALLBACK-FROM Static void: $tag');
break;
case "updated_simple_button":
break;
case "focus_button":
print("Focus button has been called");
break;
default:
print("OnClick event of $tag");
}
}
这是我想传递给警报窗口按钮的函数示例。
void openInstalledMapToPickUp(){
double destiLat = rideDetails.pickUpLat;
double destLng = rideDetails.pickUpLng;
MapsSheet.show(
context: context,
onMapTap: (map) {
map.showDirections(
destination: mapLaunch.Coords(
destiLat,
destLng,
),
origin: mapLaunch.Coords(
currentPosition.latitude,
currentPosition.longitude,
),
);
},
);
}
这是一个完整的代码,在页面上我有一个凸起的按钮,它可以作为 expexted 工作,我也想通过让 alertwindow 按钮执行与凸起按钮相同的操作。
class NewRideScreen extends StatefulWidget
{
@override
_NewRideScreenState createState() => _NewRideScreenState();
}
class _NewRideScreenState extends State<NewRideScreen> with TickerProviderStateMixin
{
final float.FloatyHead floatyHead = float.FloatyHead();
final header = float.FloatyHeadHeader(
title: float.FloatyHeadText(
text: "Ongoing Ride",
fontSize: 12,
textColor: Colors.black45,
fontWeight: float.FontWeight.normal,
padding: float.FloatyHeadPadding(
bottom: 4,
left: 5,
right: 5,
top: 5,
),
),
padding: float.FloatyHeadPadding.setSymmetricPadding(12, 12),
subTitle: float.FloatyHeadText(
text: 'Name $riderName',
fontSize: 16,
fontWeight: float.FontWeight.bold,
padding: float.FloatyHeadPadding(
bottom: 4,
left: 5,
right: 5,
top: 5,
),
textColor: Colors.black87,
),
decoration: float.FloatyHeadDecoration(startColor: Colors.grey[100]),
button: float.FloatyHeadButton(
text: float.FloatyHeadText(
fontWeight: float.FontWeight.bold,
text: "Personal",
fontSize: 10,
textColor: Colors.black45,
padding: float.FloatyHeadPadding(
bottom: 4,
left: 5,
right: 5,
top: 5,
),
),
tag: "personal_btn"),
);
final body = float.FloatyHeadBody(
rows: [
float.EachRow(
columns: [
float.EachColumn(
text: float.FloatyHeadText(
fontWeight: float.FontWeight.bold,
text: "Updated body $pickUpAdd",
fontSize: 12,
textColor: Colors.black45,
padding: float.FloatyHeadPadding(
bottom: 4,
left: 5,
right: 5,
top: 5,
),
),
),
],
gravity: float.ContentGravity.center,
),
float.EachRow(columns: [
float.EachColumn(
text: float.FloatyHeadText(
text: "Updated long data of the body",
fontSize: 12,
textColor: Colors.black87,
fontWeight: float.FontWeight.bold,
padding: float.FloatyHeadPadding(
bottom: 4,
left: 5,
right: 5,
top: 5,
),
),
padding: float.FloatyHeadPadding.setSymmetricPadding(6, 8),
decoration: float.FloatyHeadDecoration(
startColor: Colors.black12, borderRadius: 25.0),
margin: float.FloatyHeadMargin(top: 4),
),
], gravity: float.ContentGravity.center),
float.EachRow(
columns: [
float.EachColumn(
text: float.FloatyHeadText(
text: "Notes",
fontSize: 10,
textColor: Colors.black45,
fontWeight: float.FontWeight.normal,
padding: float.FloatyHeadPadding(
bottom: 4,
left: 5,
right: 5,
top: 5,
),
),
),
],
gravity: float.ContentGravity.left,
margin: float.FloatyHeadMargin(top: 8),
),
float.EachRow(
columns: [
float.EachColumn(
text: float.FloatyHeadText(
text: "Updated random notes.",
fontSize: 13,
textColor: Colors.black54,
fontWeight: float.FontWeight.bold,
padding: float.FloatyHeadPadding(
bottom: 4,
left: 5,
right: 5,
top: 5,
),
),
),
],
gravity: float.ContentGravity.left,
),
],
padding: float.FloatyHeadPadding(left: 16, right: 16, bottom: 12, top: 12),
);
final footer = FloatyHeadFooter(
buttons: [
float.FloatyHeadButton(
text: float.FloatyHeadText(
text: "Simple button",
fontSize: 12,
textColor: Color.fromRGBO(250, 139, 97, 1),
padding: float.FloatyHeadPadding(
bottom: 4,
left: 5,
right: 5,
top: 5,
),
fontWeight: float.FontWeight.normal,
),
tag: "simple_button",
padding: float.FloatyHeadPadding(left: 10, right: 10, bottom: 10, top: 10),
width: 0,
height: float.FloatyHeadButton.WRAP_CONTENT,
decoration: float.FloatyHeadDecoration(
startColor: Colors.white,
endColor: Colors.white,
borderWidth: 0,
borderRadius: 0.0),
),
float.FloatyHeadButton(
text: float.FloatyHeadText(
fontWeight: float.FontWeight.normal,
padding: float.FloatyHeadPadding(
bottom: 4,
left: 5,
right: 5,
top: 5,
),
text: "Focus button",
fontSize: 12,
textColor: Colors.white,
),
tag: "focus_button",
width: 0,
padding: float.FloatyHeadPadding(left: 10, right: 10, bottom: 10, top: 10),
height: float.FloatyHeadButton.WRAP_CONTENT,
decoration: float.FloatyHeadDecoration(
startColor: Color.fromRGBO(250, 139, 97, 1),
endColor: Color.fromRGBO(247, 28, 88, 1),
borderWidth: 0,
borderRadius: 30.0),
)
],
padding: float.FloatyHeadPadding(left: 16, right: 16, bottom: 12),
decoration: float.FloatyHeadDecoration(startColor: Colors.white),
buttonsPosition: float.ButtonPosition.center,
);
String status = "accepted";
String arrivedStatus = 'ContinueTrip';
String onRideStatus = 'ContinueTrip';
String durationRide="";
bool isRequestingDirection = false;
String btnTitle = "Arrived";
String arrivedBtnTitle = "Continue Trip";
String onRideBtnTitle = "Continue Trip";
Color btnColor = Colors.black87;
Color arrivedBtnColor = Colors.green;
Color onRideBtnColor = Colors.green;
Timer timer;
int durationCounter = 0;
bool arrivedStat = false;
bool onRideStat = false;
bool statStat = false;
@override
void initState() {
super.initState();
Wakelock.enable();
float.FloatyHead.registerOnClickListener(floatCallBack);
}
static void floatCallBack(String tag) {
print('CALLBACK FROM FRAGMENT BUILDED: $tag');
switch (tag) {
case "simple_button":
print('CALLBACK-FROM Static void: $tag');
break;
case "updated_simple_button":
break;
case "focus_button":
print("Focus button has been called");
break;
default:
print("OnClick event of $tag");
}
}
void openInstalledMapToPickUp(){
double destiLat = widget.rideDetails.pickUpLat;
double destLng = widget.rideDetails.pickUpLng;
MapsSheet.show(
context: context,
onMapTap: (map) {
map.showDirections(
destination: mapLaunch.Coords(
destiLat,
destLng,
),
origin: mapLaunch.Coords(
currentPosition.latitude,
currentPosition.longitude,
),
originTitle: "My Current Location",
);
},
);
}
@override
Widget build(BuildContext context)
{
return new Scaffold(
body: Stack(
children: [
Positioned(
child: SlidingUpPanel(
minHeight: 110,
maxHeight: 400 ,
borderRadius: BorderRadius.only(topLeft: Radius.circular(16.0), topRight: Radius.circular(16.0)),
panel: Container(
height: 300.0,
child: Padding(
padding: EdgeInsets.symmetric(horizontal: 15.0, vertical: 18.0),
child: Column(
children: [
Container(
padding: EdgeInsets.only(top: 10, bottom: 10),
decoration: BoxDecoration(color: Colors.cyan[600],
borderRadius: BorderRadius.all(Radius.circular(40.0),),),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
"${durationRide} to Destination",
style: TextStyle(fontSize: 15.0, fontFamily: "Brand Bold", color: Colors.white),
),
],
),
),
SizedBox(height: 8.0,),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(widget.rideDetails.rider_name, style: TextStyle(fontFamily: "Brand Bold", fontSize: 20.0, fontWeight: FontWeight.w600),),
Text("R ${itemCount.toString()}"),
Column(
children: [
Text("Total Rides", style: TextStyle(fontSize: 12), ),
Text("${widget.rideDetails.totalTrip}", style: TextStyle(fontSize: 18, fontWeight: FontWeight.w600), ),
],
),
],
),
SizedBox(height: 8.0,),
Divider(height: 2.0, thickness: 2.0,),
SizedBox(height: 8.0,),
Padding(
padding: EdgeInsets.symmetric(horizontal: 10.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Padding(
padding: EdgeInsets.all(0.0),
child: MaterialButton(
onPressed: () {
launch(('tel://${widget.rideDetails.phone}'));
},
color: Colors.black,
textColor: Colors.white,
child: Icon(
Icons.call, color: Colors.white, size: 20.0,
),
padding: EdgeInsets.all(12),
shape: CircleBorder(),
),
),
],
),
),
SizedBox(height: 10.0,),
Divider(height: 2.0, thickness: 2.0,),
SizedBox(height: 10.0,),
Row(
children: [
Image.asset("images/pickicon.png", height: 16.0, width: 16.0,),
SizedBox(width: 18.0,),
Expanded(
child: Container(
child: Text(
widget.rideDetails.pickup_address,
style: TextStyle(fontSize: 14.0),
overflow: TextOverflow.visible,
),
),
),
],
),
SizedBox(height: 16.0,),
Row(
children: [
Image.asset("images/desticon.png", height: 16.0, width: 16.0,),
SizedBox(width: 10.0,),
Expanded(
child: Container(
child: Text(
widget.rideDetails.dropoff_address,
style: TextStyle(fontSize: 14.0),
overflow: TextOverflow.ellipsis,
),
),
),
],
),
SizedBox(height: 16.0,),
Visibility(
visible: statStat,
child:RaisedButton(
shape: new RoundedRectangleBorder(
borderRadius: new BorderRadius.circular(24.0),
),
onPressed: () async
{
if(status == "accepted")
{
status = "arrived";
setState(() {
btnTitle = "Start Trip";
btnColor = Colors.cyan[600];
});
}
else if(status == "arrived")
{
status = "onride";
setState(() {
btnTitle = "End Trip";
btnColor = Colors.redAccent;
});
openInstalledMapToPickUp();
}
else if(status == "onride")
{
endTheTrip();
}
},
color: btnColor,
child: Padding(
padding: EdgeInsets.all(17.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(btnTitle, style: TextStyle(fontSize: 15.0, fontWeight: FontWeight.bold, color: Colors.white),),
Icon(Icons.directions_car, color: Colors.white, size: 26.0,),
],
),
),
),
),
],
),
),
),
),
),
],
),
);
}
endTheTrip() async{}
void setCustomHeader() {
floatyHead.updateFloatyHeadContent(
header: header,
body: body,
footer: footer,
);
}
void openHead(){
if(openHeads == true){
setCustomHeader();
setCloseIcon();
setIcon();
floatyHead.openBubble();
}
}
Future<void> setNotificationTitle() async {
String result;
try {
result = await floatyHead
.setNotificationTitle("OH MY GOD! THEY KILL KENNY!!!");
} on PlatformException {
result = 'Failed to get icon.';
}
print('result: $result');
if (!mounted) return;
}
}