orientation_helper 1.1.0 orientation_helper: ^1.1.0 copied to clipboard
A Flutter plugin to easily handle screen orientation for every route in your app.
orientation_helper #
A Flutter plugin to easily handle screen orientation for every route in your app.
Getting Started #
Create routes and set their orientation:
class AppRoutes {
// has defaultOrientation
static var home = RouteDetails(
name: 'home',
page: HomePage(),
);
static var details = RouteDetails(
name: '/details',
page: DetailsPage(),
orientation: ScreenOrientation.rotating,
);
static List<RouteDetails> get routes => [
home,
details,
];
}
Setup OrientationHelper:
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
OrientationHelper orientationHelper;
@override
void initState() {
orientationHelper = OrientationHelper(
routes: AppRoutes.routes,
defaultOrientation: ScreenOrientation.portraitOnly,
);
super.initState();
}
@override
Widget build(BuildContext context) {
return MaterialApp(
/// Setup OrientationHelper
initialRoute: AppRoutes.home.name,
navigatorObservers: [
orientationHelper.navigatorObserver,
],
onGenerateRoute: orientationHelper.onGenerateRoute,
);
}
}
Navigate with pushNamed:
Navigator.of(context).pushNamed(AppRoutes.details.name);
Pass arguments:
Navigator.of(context).pushNamed(AppRoutes.details.name, arguments: 'Argument');
Get arguments:
class DetailsPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
final dynamic arguments = (ModalRoute.of(context).settings.arguments as RouteArguments).args;
return Child();
}
}