I`m trying to get the device size to choose if the device orientation will be landscapeLeft and landscapeRight, or any.
The problem is, the only way i found was using context, how can i get it in main function?
the getter window
is deprecated
I tried to use getDeviceType from responsive_builder
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_dotenv/flutter_dotenv.dart';
import 'package:flutter_modular/flutter_modular.dart';
import 'app/app_module.dart';
import 'app/app_widget.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
// set orientation to landscape
await SystemChrome.setPreferredOrientations(
[DeviceOrientation.landscapeLeft, DeviceOrientation.landscapeRight],
);
// load environment variables
await dotenv.load();
runApp(
ModularApp(
module: AppModule(),
child: const AppWidget(),
),
);
}
if (getDeviceType(MediaQueryData.fromView(WidgetsBinding.instance.window).size) == DeviceScreenType.tablet) {
await SystemChrome.setPreferredOrientations(
[DeviceOrientation.landscapeLeft, DeviceOrientation.landscapeRight],
);
}
New contributor
Emerson Oliveira is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.