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:
# 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?
CodePudding user response:
I think it should be a int instead of Future
scaffoldBackgroundColor: Color(await Client().getBackgroundColor()),