Search code examples
androiddartmobileflutterflow

Flutter Flow - Custom Action Not working on Android APK


I am new to flutter flow & Dart, while using custom action which I linked to my widget in action flow editor everything went smoothly until I found an abnormal behavior ( There are no visible errors in my program ):

  • On Debug mode action is working perfectly.
  • On run mode action is working on windows but in flutter flow viewer app for android that particular page is not even opening up.
  • In apk-release file page is opening but after I enter all my values and press button action is not performed, or should I say nothing happens.

This is the code/Custom Action I'm using in flutter flow :-

import 'dart:convert';

// This is only for clarification of arguments passed...
void main(){
  foreSupportCalc(
  12, //from textinput
  45, //from textinput
  "20 guage", //from dropdown
  5, //from counter
  6, //from textinput
  "14 guage", //from dropdown
  1, //from counter
  350, //from AppState
  1500, //from ApSate
  '{"14": 2, "16": 1.5, "20": 1}', //from ApSate
  '{"14": 175, "16": 150, "18": 130}'); //from AppState
}

// Main Custom Action starts here
Future<String> foreSupportCalc(
  double shelfWidth,
  double shelfLength,
  String shelfGuage,
  int shelfQuantity,
  double angleHeight,
  String angleGuage,
  int rackQuantity,
  double metalRates,
  double labourRates,
  String shelfGuageMap,
  String angleGuageMap,
) async {
  if (shelfWidth != null &&
      shelfLength != null &&
      shelfGuage != null &&
      shelfQuantity != null &&
      angleHeight != null &&
      angleGuage != null &&
      rackQuantity != null) {
    shelfWidth += 3;
    shelfLength += 3;
    Map<String, dynamic> shelfGuages = json.decode(shelfGuageMap);
    Map<String, dynamic> angleGuages = json.decode(angleGuageMap);
    double shelfGuage_mm = shelfGuages[shelfGuage.replaceAll(" guage", "")];
    double angleGuage_rate = angleGuages[angleGuage.replaceAll(" guage", "")];

    // Shelf Rates
    double perShelfRate = (((shelfWidth * shelfLength) / 144) *
            shelfGuage_mm * metalRates)
        .roundToDouble();
    double totalShelfRate = perShelfRate * shelfQuantity;
    double totalShelfRateForMultiRack = totalShelfRate * rackQuantity;
    int multiShelfQty = shelfQuantity * rackQuantity;
    // Angle Rates
    double perAngleRate = (angleGuage_rate * angleHeight).roundToDouble();
    double totalAngleRate = perAngleRate * 4;
    double totalAngleRateForMultiRack = totalAngleRate * rackQuantity;
    int multiAngleQty = 4 * rackQuantity;
    // Total Rack Cost
    double perRackCost = totalShelfRate + totalAngleRate + labourRates;
    double totalRackCost = perRackCost * rackQuantity;
    // Labour Rates
    double multiLabourRates = labourRates * rackQuantity;
    // Rates as String
    Map<String, dynamic> outputAns;
    if (rackQuantity > 1) {
      outputAns = {
        'Per Shelf Rates': perShelfRate,
        'Per Angle Rates': perAngleRate,
        '_+': '-:-',
        'Shelf Rates ($multiShelfQty)': totalShelfRateForMultiRack,
        'Angle Rates ($multiAngleQty)': totalAngleRateForMultiRack,
        'Labour, etc Cost': multiLabourRates,
        '__+': '-:-',
        'Rates Per Rack': perRackCost,
        'Rate for $rackQuantity Racks': totalRackCost
      };
    } else {
      outputAns = {
        'Per Shelf Rates': perShelfRate,
        'Per Angle Rates': perAngleRate,
        '-': '-',
        'Shelf Rates ($shelfQuantity)': totalShelfRate,
        'Angle Rates (4)': totalAngleRate,
        'Labour, etc Cost': labourRates,
        '-:': '-',
        'Rates Per Rack': perRackCost,
      };
    }

    String result = '';
    // Iterate over map entries
    outputAns.forEach((key, value) {
      // Concatenate each key-value pair into the string
      result += '$key: $value\n';
    });
    result = result.replaceAll("_+:", "");
    result = result.replaceAll("__+:", "");
    return result;
  } else {
    return "Error: Something is missing!";
  }
}

This should be the output of this action which I'm passing in an alert dialog box :-

Per Shelf Rates: Rs.1750
Per Angle Rates: Rs.1050
-:-
Shelf Rates (5): Rs.8750
Angle Rates (4): Rs.4200
Labour, etc Cost: Rs.1500
-:-
Rates Per Rack: Rs.14450

I tried to manipulate the code and also use simpler test code like just returning a sample String which in that case worked fine on all platforms, but this code isn't. i also double checked the data types of my AppState variables and those were ok.

If its working in Debug, then why not in android?

EDIT: After using web log Ctrl+Shift+j saw this on my console:

Uncaught TypeError: J.bV(...).aj is not a function
    at Object.eO (main.dart.js:29145:24)
    at Object.ayg (main.dart.js:5764:3)
    at aN2.$1 (main.dart.js:88145:19)
    at bEg (main.dart.js:4101:17)
    at main.dart.js:4109:51

Solution

  • Answer ( For future, if anyone encounters same problem )

    Thankyou everyone for not responding to my request, however I found the the problem causing this error which was in this line of code:

    String shelfGuageMap = '{"14": 2, "16": 1.5, "20": 1}';
    String angleGuageMap = '{"14": 175, "16": 150, "18": 130}';
    Map<String, dynamic> shelfGuages = json.decode(shelfGuageMap);
    Map<String, dynamic> angleGuages = json.decode(angleGuageMap);
    

    Seems like flutter flow does not support String to Map conversion on android or at least not in my case, So I changed the whole logic to:

    String shelfGuageList = '["11:3", "12:2.5", "13:2.5", "14:2"]';
    String angleGuageList = '["11:140", "12:150", "13:160", "14:175"]';
    List<String> shelfGuageToList = json.decode(shelfGuageList).cast<String>();
    List<String> angleGuageToList = json.decode(angleGuageList).cast<String>();
    

    Now, don't know why this was an issue but Code is finally working on all devices.