Quantcast
Channel: Active questions tagged https - Stack Overflow
Viewing all articles
Browse latest Browse all 1822

Flutter ElevatedButton doesn't respond

$
0
0

I have an application with a form and now with a little experimental refactoring from last week 2 buttons doesn't do anything.

Logging just say "button was click " but no method is called.

The code is :

Widget build() {///...ElevatedButton (   onPress : genText1(),   child : Text("add text for image 1")),///...}

An error is detected here in a method called by genText1()

Uint8List? genText2(int index, Uint8List image) {final appState = Provider.of<AppState>(context, listen: false);log.info("GenText2 dart method. Starting process... invoke generateText (Kotlin)",);log.info("GenText2 dart method. Starting process... Inputs : checks if not null",);try {  var image2 = Image.memory(image);  var width = image2.width;  var height = image2.height;  var imageBytes = image;  var imageWidth = width;  var imageHeight = height;  if (imageWidth != null && imageHeight != null) {    try {      final Map<String, dynamic> arguments = {'image': imageBytes,'width': imageWidth, // <-- ADD THIS'height': imageHeight, // <-- ADD THIS      };      Future<dynamic> result = _FirstPanelState._channel.invokeMethod('generateText',        arguments,      );      log.info("GenText2 dart method. Starting process... generateText invoked (return to Dart)",      );      // Handle cases where imageBytes, imageWidth, or imageHeight might be null      result.then((value) {        if (value != null) {          var value2 = value as Uint8List;          log.info("GenText2 dart method. treats return value (not null...)",          );          setState(() {            switch (index) {              case 1:                log.info("GenText2 dart method. treats return value set textFileContent1 $value",                );                appState.textFileContent1 = value2;                break;              case 2:                log.info("GenText2 dart method. treats return value set textFileContent1 $value",                );                appState.textFileContent2 = value2;                break;              case 3:                log.info("GenText2 dart method. treats return value set textFileContent1 $value",                );                appState.textFileContent3 = value2;                break;              default:            }            ScaffoldMessenger.of(context).showSnackBar(              SnackBar(content: Text('Completed with 100% no error. ')),            );            //appState.selectedImage = Image.memory(value);          });        }      }).catchError((error) {        ScaffoldMessenger.of(context).showSnackBar(          SnackBar(content: Text('Error: $error')),        );      });    } on PlatformException catch (e) {      log.severe("Failed to generate text: '${e.message}'.");      ScaffoldMessenger.of(context).showSnackBar(        SnackBar(content: Text('Failed to generate text. Error: $e')),      );    }  } else {    log.info("Error: imageWidth or imageHeight is null.");    ScaffoldMessenger.of(context).showSnackBar(      SnackBar(content: Text('Error: imageWidth or imageHeight is null.')),    );  }} on PlatformException catch (e) {  ScaffoldMessenger.of(context).showSnackBar(    SnackBar(content: Text('Error: $e')),  );  log.fine("Platform Error Code: ${e.code}");  log.fine("Platform Error Message: ${e.message}");  log.fine("Platform Error Details: ${e.details}",  ); // Now will be a String or a Map  // If you sent a Map, you can process it like this:  if (e.details is Map) {    final errorDetails = e.details as Map;    log.fine("Error Size: ${errorDetails["size"]}");    log.fine("Error Message: ${errorDetails["message"]}");    ScaffoldMessenger.of(context).showSnackBar(      SnackBar(content: Text( "Error Size: ${errorDetails["size"]}\nError Message: ${errorDetails["message"]}"      ),    ));  }}return null;

}

Error: imageWidth or imageHeight is null.


Viewing all articles
Browse latest Browse all 1822

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>