1

As I am trying to work on a project I have taken the source code from github and opened it in Android Studio. After syncing there is no error in the whole code but when I run the app it shows so many errors:

enter image description here

These are the errors shown in the app. I have tried to migrate into AndroidX but that didn't work either. So basically can anyone tell me how to run a flutter app downloaded from any other sources like github?

Mobina
  • 6,369
  • 2
  • 25
  • 41

1 Answers1

0

This is an issue already brought up here. You should post the code indicated in the console. The important part seems to be line "#6" of the log, with the package flutter_sudoku lib/main.dart file at line 17.

And looking at the github repository, indeed, they are making the main function "await" fot the system orientation to be ready here

void main() =>  SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp, DeviceOrientation.portraitDown])
    .then((_) {
      runApp(
      BlocProvider(
        bloc: UserDataBloc(),
        child: MyApp(),
      )
  );
});

You must call WidgetsFlutterBinding.ensureInitialized(); before the await function

void main() {
  WidgetsFlutterBinding.ensureInitialized();
  SystemChrome.setPreferredOrientations(
      [DeviceOrientation.portraitUp, DeviceOrientation.portraitDown]).then((_) {
    runApp(BlocProvider(
      bloc: UserDataBloc(),
      child: MyApp(),
    ));
  });
}
RegularGuy
  • 3,516
  • 1
  • 12
  • 29