I have created a custom action but the it doesn't return the value after I input the parameters

Custom Code

I created a screen in which you input the weight of the patient and choose the anesthetic type from a list. After you hit the button Calcular (calculate), it should prove the result on the text widget below. However, the results are not being displayed. When I used this action as a custom function, it provided the result correctly in the test tab. I'm not sure if I selected the parameters correctly, or if the text widget is properly set to return the value.

I am a beginner, so I would need help at this level. I'll paste the page code here and the prints. Can anyone explain to me what should I do as if I were like 5yo?


import '/flutter_flow/flutter_flow_drop_down.dart';

import '/flutter_flow/flutter_flow_icon_button.dart';

import '/flutter_flow/flutter_flow_theme.dart';

import '/flutter_flow/flutter_flow_util.dart';

import '/flutter_flow/flutter_flow_widgets.dart';

import '/flutter_flow/form_field_controller.dart';

import '/custom_code/actions/index.dart' as actions;

import 'package:easy_debounce/easy_debounce.dart';

import 'package:flutter/material.dart';

import 'package:flutter/services.dart';

import 'package:google_fonts/google_fonts.dart';

import 'package:provider/provider.dart';

import 'anestesicos_model.dart';

export 'anestesicos_model.dart';

class AnestesicosWidget extends StatefulWidget {

  const AnestesicosWidget({

    super.key,

    required this.peso,

    required this.anestesico,

    required this.tubetes,

  });

  final double? peso;

  final List<String>? anestesico;

  final double? tubetes;

  @override

  State<AnestesicosWidget> createState() => _AnestesicosWidgetState();

}

class _AnestesicosWidgetState extends State<AnestesicosWidget> {

  late AnestesicosModel _model;

  final scaffoldKey = GlobalKey<ScaffoldState>();

  @override

  void initState() {

    super.initState();

    _model = createModel(context, () => AnestesicosModel());

    _model.textController ??= TextEditingController();

    _model.textFieldFocusNode ??= FocusNode();

  }

  @override

  void dispose() {

    _model.dispose();

    super.dispose();

  }

  @override

  Widget build(BuildContext context) {

    return GestureDetector(

      onTap: () => _model.unfocusNode.canRequestFocus

          ? FocusScope.of(context).requestFocus(_model.unfocusNode)

          : FocusScope.of(context).unfocus(),

      child: Scaffold(

        key: scaffoldKey,

        backgroundColor: FlutterFlowTheme.of(context).primaryBackground,

        appBar: AppBar(

          backgroundColor: FlutterFlowTheme.of(context).primary,

          automaticallyImplyLeading: false,

          leading: FlutterFlowIconButton(

            borderColor: Colors.transparent,

            borderRadius: 30,

            borderWidth: 1,

            buttonSize: 60,

            icon: Icon(

              Icons.arrow_back_rounded,

              color: Colors.white,

              size: 30,

            ),

            onPressed: () async {

              context.pop();

            },

          ),

          title: Text(

            'Page Title',

            style: FlutterFlowTheme.of(context).headlineMedium.override(

                  fontFamily: 'Outfit',

                  color: Colors.white,

                  fontSize: 22,

                  letterSpacing: 0,

                ),

          ),

          actions: [],

          centerTitle: true,

          elevation: 2,

        ),

        body: SafeArea(

          top: true,

          child: Column(

            mainAxisSize: MainAxisSize.max,

            children: [

              Padding(

                padding: EdgeInsetsDirectional.fromSTEB(0, 15, 0, 0),

                child: Text(

                  'Cálculo da dose máxima de anestésicos',

                  style: FlutterFlowTheme.of(context).titleLarge.override(

                        fontFamily: 'Outfit',

                        fontSize: 20,

                        letterSpacing: 0,

                        fontWeight: FontWeight.normal,

                      ),

                ),

              ),

              Padding(

                padding: EdgeInsetsDirectional.fromSTEB(46, 10, 46, 0),

                child: TextFormField(

                  controller: _model.textController,

                  focusNode: _model.textFieldFocusNode,

                  onChanged: (_) => EasyDebounce.debounce(

                    '_model.textController',

                    Duration(milliseconds: 100),

                    () => setState(() {}),

                  ),

                  autofocus: true,

                  obscureText: false,

                  decoration: InputDecoration(

                    labelText: 'Peso (kg)',

                    labelStyle:

                        FlutterFlowTheme.of(context).bodyMedium.override(

                              fontFamily: 'Readex Pro',

                              letterSpacing: 0,

                            ),

                    alignLabelWithHint: false,

                    hintText: 'Peso do paciente...',

                    hintStyle:

                        FlutterFlowTheme.of(context).labelMedium.override(

                              fontFamily: 'Readex Pro',

                              letterSpacing: 0,

                            ),

                    enabledBorder: OutlineInputBorder(

                      borderSide: BorderSide(

                        color: FlutterFlowTheme.of(context).alternate,

                        width: 2,

                      ),

                      borderRadius: BorderRadius.circular(8),

                    ),

                    focusedBorder: OutlineInputBorder(

                      borderSide: BorderSide(

                        color: FlutterFlowTheme.of(context).primary,

                        width: 2,

                      ),

                      borderRadius: BorderRadius.circular(8),

                    ),

                    errorBorder: OutlineInputBorder(

                      borderSide: BorderSide(

                        color: FlutterFlowTheme.of(context).error,

                        width: 2,

                      ),

                      borderRadius: BorderRadius.circular(8),

                    ),

                    focusedErrorBorder: OutlineInputBorder(

                      borderSide: BorderSide(

                        color: FlutterFlowTheme.of(context).error,

                        width: 2,

                      ),

                      borderRadius: BorderRadius.circular(8),

                    ),

                    filled: true,

                    fillColor: FlutterFlowTheme.of(context).secondaryBackground,

                    contentPadding:

                        EdgeInsetsDirectional.fromSTEB(16, 0, 16, 0),

                  ),

                  style: FlutterFlowTheme.of(context).bodyMedium.override(

                        fontFamily: 'Readex Pro',

                        letterSpacing: 0,

                      ),

                  keyboardType: TextInputType.number,

                  validator:

                      _model.textControllerValidator.asValidator(context),

                  inputFormatters: [

                    FilteringTextInputFormatter.allow(RegExp('[0-9]'))

                  ],

                ),

              ),

              FlutterFlowDropDown<String>(

                controller: _model.dropDownValueController ??=

                    FormFieldController<String>(null),

                options: [

                  'Articaína',

                  'Lidocaína',

                  'Prilocaína',

                  'Mepivacaína',

                  'Bupivacaína'

                ],

                onChanged: (val) => setState(() => _model.dropDownValue = val),

                width: 300,

                height: 56,

                textStyle: FlutterFlowTheme.of(context).bodyMedium.override(

                      fontFamily: 'Readex Pro',

                      letterSpacing: 0,

                    ),

                hintText: 'Selecione o anestésico...',

                icon: Icon(

                  Icons.keyboard_arrow_down_rounded,

                  color: FlutterFlowTheme.of(context).secondaryText,

                  size: 24,

                ),

                fillColor: FlutterFlowTheme.of(context).secondaryBackground,

                elevation: 2,

                borderColor: FlutterFlowTheme.of(context).alternate,

                borderWidth: 2,

                borderRadius: 8,

                margin: EdgeInsetsDirectional.fromSTEB(16, 4, 16, 4),

                hidesUnderline: true,

                isOverButton: true,

                isSearchable: false,

                isMultiSelect: false,

              ),

              Padding(

                padding: EdgeInsetsDirectional.fromSTEB(0, 5, 0, 0),

                child: FFButtonWidget(

                  onPressed: () async {

                    _model.resultAnestesico = await actions.calcAnestesico(

                      widget.peso,

                      widget.anestesico?.length?.toString(),

                    );

                    setState(() {});

                  },

                  text: 'Calcular',

                  options: FFButtonOptions(

                    height: 40,

                    padding: EdgeInsetsDirectional.fromSTEB(24, 0, 24, 0),

                    iconPadding: EdgeInsetsDirectional.fromSTEB(0, 0, 0, 0),

                    color: FlutterFlowTheme.of(context).primary,

                    textStyle: FlutterFlowTheme.of(context).titleSmall.override(

                          fontFamily: 'Readex Pro',

                          color: Colors.white,

                          letterSpacing: 0,

                        ),

                    elevation: 3,

                    borderSide: BorderSide(

                      color: Colors.transparent,

                      width: 1,

                    ),

                    borderRadius: BorderRadius.circular(8),

                  ),

                ),

              ),

              Padding(

                padding: EdgeInsetsDirectional.fromSTEB(0, 15, 0, 0),

                child: InkWell(

                  splashColor: Colors.transparent,

                  focusColor: Colors.transparent,

                  hoverColor: Colors.transparent,

                  highlightColor: Colors.transparent,

                  onTap: () async {

                    _model.resultado = await actions.resultAnestesico(

                      widget.peso!,

                      widget.anestesico!.length.toString(),

                    );

                    setState(() {});

                  },

                  child: Text(

                    'Resultado...',

                    style: FlutterFlowTheme.of(context).titleLarge.override(

                          fontFamily: 'Outfit',

                          letterSpacing: 0,

                        ),

                  ),

                ),

              ),

            ],

          ),

        ),

      ),

    );

  }

}
What have you tried so far?

I tried multiple combinations of arrangements of the return function in the text widget, I've already asked help for chatgpt, but the solutions are for flutter in general, and not flutterflow


This is the custom function of the Calcular button

// Automatic FlutterFlow imports
import '/flutter_flow/flutter_flow_theme.dart';
import '/flutter_flow/flutter_flow_util.dart';
import '/custom_code/actions/index.dart'; // Imports other custom actions
import '/flutter_flow/custom_functions.dart'; // Imports custom functions
import 'package:flutter/material.dart';
// Begin custom action code
// DO NOT REMOVE OR MODIFY THE CODE ABOVE!

import 'dart:convert';
import 'dart:math' as math;

String? calcAnestesico(
  double? peso,
  String? anestesico,
) {
  /// MODIFY CODE ONLY BELOW THIS LINE

// Verifica se o peso e o anestésico são válidos
  if (peso == null || anestesico == null || anestesico.isEmpty) {
    throw Exception('Peso ou anestésico inválido');
  }

  double maxMg = 0;

  // Define a dose máxima permitida para cada anestésico
  Map<String, double> doseMaximaPermitida = {
    'Articaína': 500,
    'Bupivacaína': 90,
    'Lidoicaína': 300,
    'Mepivacaína': 400,
    'Prilocaína': 400,
  };

  // Define as concentrações percentuais para cada anestésico
  Map<String, double> concentracoesPercentuais = {
    'Articaína': 4, // 4%
    'Bupivacaína': 0.5, // 0.5%
    'Lidoicaína': 3, // 3%
    'Mepivacaína': 3, // 3%
    'Prilocaína': 3, // 3%
  };

  if (anestesico == 'Lidoicaína') {
    maxMg = 4.4 * peso;
  } else if (anestesico == 'Mepivacaína') {
    maxMg = 4.4 * peso;
  } else if (anestesico == 'Articaína') {
    maxMg = 7 * peso;
  } else if (anestesico == 'Bupivacaína') {
    maxMg = 1.3 * peso;
  } else if (anestesico == 'Prilocaína') {
    maxMg = 6 * peso;
  }

  // Aplica a restrição da dose máxima permitida
  if (doseMaximaPermitida.containsKey(anestesico)) {
    maxMg = math.min(maxMg, doseMaximaPermitida[anestesico]!);
  }

  // Calcula o volume máximo com base na concentração percentual
  double maxMl = maxMg /
      (concentracoesPercentuais[anestesico]! *
          10); // A concentração * 10 fornece mg/mL
  double maxCarpules = maxMl / 1.7;

  return 'Dose Máxima: ${maxMg.toStringAsFixed(1)} mg\nVolume Máximo: ${maxMl.toStringAsFixed(1)} mL\nCarpules Máximos: ${maxCarpules.toStringAsFixed(1)}';

// Set your action name, define your arguments and return parameter,
// and then add the boilerplate code using the green button on the right!
}

This is the custom function of the Resultado... (text widget supposed to return the value from the calculation)


// Automatic FlutterFlow imports
import '/flutter_flow/flutter_flow_theme.dart';
import '/flutter_flow/flutter_flow_util.dart';
import '/custom_code/actions/index.dart'; // Imports other custom actions
import '/flutter_flow/custom_functions.dart'; // Imports custom functions
import 'package:flutter/material.dart';
// Begin custom action code
// DO NOT REMOVE OR MODIFY THE CODE ABOVE!

Future<String?> resultAnestesico(double peso, String anestesico) async {
  // returns the result in resultAnestesico in calcAnestesico custom action parameter as text
  String? result = await calcAnestesico(peso, anestesico);
  return result;
}

calcAnestesico(double peso, String anestesico) {}
Did you check FlutterFlow's Documentation for this topic?
Yes