1

I am Trying to pass a function to a static callback, i have added the code below. I am using a plugin like system alert window that is the call back, it has a tag with is pass to button. the same as system Alert window, to draw over other app, the draw over screen has a button(the static call Back function). i am trying to pass a function to this call call back so that when the button is pressed it is able to perform something inside the app

This is the Alert window body code with the button. The button doesnt have an onpresse function, instead it is identified by a string tag.

  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,
  );

Here is the call back containing the String tag for the button, when i click the button it prints out the result but i unable to pass a woking function to the button.

 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");
    }
  }

Here is an example of the function i want to pass to the alert window button.

  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,
          ),
        );
      },
    );
  }

Here is a full code, on the page i have a Raised button which works as expexted, i would also like to pass to have the alertwindow button do thesame thing the raised button does.

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;
  }

}

Page View

AlertWindow view

Chris Benson
  • 29
  • 1
  • 3

0 Answers0