Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Unhandled Exception: type 'Future<dynamic>' is not a subtype of type 'int'

I have initializeThemeData() which returns ThemeData for the whole app.

# main.dart

Future<ThemeData> initializeThemeData() async {
  
  
  return ThemeData(
    scaffoldBackgroundColor: Color(Client().getBackgroundColor()),
    );
}

This ThemeData() uses a background color of Client().getBackgroundColor():

# get_client_settings.dart 

class Client {
  getBackgroundColor() async {
    var settings = await getSettings();
    var hexColor = settings["view_background_color"];
    return int.parse("0xFF" + hexColor.substring(1));
  }
}

Client class awaits another method called getSettings which returns a json:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

# load_settings.dart 

getSettings() async {
  String jsonData =
      await rootBundle.loadString('assets/config/client_settings.json');
  Map<String, dynamic> data = jsonDecode(jsonData);
  return data;
}

getSettings loads the json from a json file which has the backgroundcolor value i want to use:

{
   "view_background_color" : "#f5f242" 
}

But when i run the app i get the error: type 'Future<dynamic>' is not a subtype of type 'int'

EDIT:

I know it has to do with the Future and i should use FutureBuilder
There is similar question in the link How to fix type 'Future<dynamic>' is not a subtype of type 'String' Flutter

But if i have to use FutureBuilder, how can i then use it for my situation without placing everything in one file?

>Solution :

I think it should be a int instead of Future

scaffoldBackgroundColor: Color(await Client().getBackgroundColor()),
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading