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