skip to Main Content

It works on mobile data and wifi during debug but on release mode it does not work in the app. It shows an error of Future.then must return a value of the returned future's type in release mode

2

Answers


  1. Since you said it works in debug, but not in release:

    Flutter sets the Internet Permission in the AndroidManifest automatically, but you have to set it yourself for the release version.

    https://docs.flutter.dev/data-and-backend/networking

    <manifest xmlns:android...>
     ...
     <uses-permission android:name="android.permission.INTERNET" />
     <application ...
    </manifest>
    

    Add this to your AndroidManifest.xml

    Login or Signup to reply.
  2. To fix this error, you need to make sure that the then method on the Future object is returning the correct type of value.

    Here is an example of how to fix this error:

    Future<String> yourData() async {
     // Do some asynchronous work here
     return 'My data';
    }
    
    void main() {
     // This will work in debug mode
     getMyData().then((value) {
     print(value);
     });
    
     // This will throw an error in release mode
     yourData().then((value) {
      print(value as int); // Throw an error because the value is a String.
      });
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search