如何鎖定裝置的方向
先到main.dart檔案找到最初的進入點main()要執行runApp時,先執行
- WidgetsFlutterBinding.ensureInitialized(); 確定每次執行都要初始化
- SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp,]) 選擇我們接受的方向
所在的函示庫記得引入 import ‘package:flutter/services.dart’;
void main() {
WidgetsFlutterBinding.ensureInitialized();
SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
]).then((value) => {
runApp(MaterialApp(
home: const Expenses(),
))
});
}