// This did not work as requirement
void main() {
SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
runApp(new MyApp());
}
你必须等到setPreferredOrientations完成,然后
启动应用
// This will works always for lock screen Orientation.
void main() {
WidgetsFlutterBinding.ensureInitialized();
SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp])
.then((_) {
runApp(new MyApp());
});
}
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
void main() {
// We need to call it manually,
// because we going to call setPreferredOrientations()
// before the runApp() call
WidgetsFlutterBinding.ensureInitialized();
// Than we setup preferred orientations,
// and only after it finished we run our app
SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp])
.then((value) => runApp(MyApp()));
}