我在启动屏幕上使用了自定义设备方向(已运行),并尝试使用dispose()将其恢复为正常状态。但这不起作用。
这是我的代码-
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:boimarket/widgets/exitpopup.dart';
import 'package:boimarket/homepage.dart';
class SplashScreen extends StatefulWidget {
@override
_SplashScreenState createState() => _SplashScreenState();
}
class _SplashScreenState extends State<SplashScreen> {
@override
void initState() {
super.initState();
SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitDown,
DeviceOrientation.portraitUp,
]);
Timer(
Duration(seconds: 3),
() => Navigator.push(context,
MaterialPageRoute(builder: (context) => ExitPopUp(Homepage()))));
}
@override
dispose() {
SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitDown,
DeviceOrientation.portraitUp,
DeviceOrientation.landscapeRight,
DeviceOrientation.landscapeLeft,
]);
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: SingleChildScrollView(
child: Container(
child: Text('Hello')
);
}
}
问题出在哪里?以及我该如何解决?