main function

void main()

This is the main function executed to launch the app. First it creates a PersonalDataProvider and a DeviceProvider. The reason only these providers are instanced before the builder is called is to obtain the model of the device using obtenerModelo and load the profiles stored in SharedPreferences using PersonalDataProvider.loadProfiles before displaying the home page.

Implementation

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  final prefs = await SharedPreferences.getInstance();
  final personalDataProvider = PersonalDataProvider();
  final deviceProvider = DeviceProvider();
  bool dataExists = await prefs.getBool('dataExists') ?? false;
  if(dataExists == true) {
    await personalDataProvider.loadProfiles();
  }
  await obtenerModelo(deviceProvider);
  await SystemChrome.setPreferredOrientations([
    DeviceOrientation.portraitUp,
    DeviceOrientation.portraitDown,
  ]);

  runApp( MyApp(personalDataProvider: personalDataProvider, deviceProvider: deviceProvider,));
}