I am trying to load an excel file in the background and then display its content to the user. I am using the excel package to load and read it and a FutureProvider
for inserting the data into the widget tree. As the reading takes quite some time I am doing it asynchronously. However, whenever the App gets to the widget that contains the FutureBuilder, it freezes and only continues once the Future is done.
Reading the file:
Future<Excel> _readExcelFile(String path) async {
ByteData data = await rootBundle.load(path);
var bytes = data.buffer.asUint8List(data.offsetInBytes, data.lengthInBytes);
var excel = Excel.decodeBytes(bytes);
return excel;
}
The FutureBuilder
MultiProvider(
providers: [
FutureProvider(
create: (context) async => MenuProvider().loadMenu(),
lazy: false,
),
],
child: MyApp(),
)
The MenuProvider().loadMenu()
method calls the _readExcelFile(String path)
method and parses the data.
As I said, the app freezes on start and only continues rendering once the Future is complete. Is there a way to load and parse the excel file without blocking the UI thread? Or is my only option to show a splash screen until the data is ready?
Edit:
@override
Widget build(BuildContext context) {
var weekMenu = Provider.of<List<DayMenu>>(context);
if (weekMenu != null) {
print(weekMenu[0].date.toString());
return PageView(
children: [
// PageView children
],
);
} else {
return Text("Loading data...");
}
}